Added json field and implement lat & lng
This commit is contained in:
@@ -28,6 +28,8 @@ export type DetectionData = {
|
|||||||
first_detected_frame: number
|
first_detected_frame: number
|
||||||
first_detected_time: number
|
first_detected_time: number
|
||||||
confidence: number
|
confidence: number
|
||||||
|
lat?: number
|
||||||
|
lng?: number
|
||||||
}>
|
}>
|
||||||
signboard_list?: Array<{
|
signboard_list?: Array<{
|
||||||
signboard_id: number
|
signboard_id: number
|
||||||
@@ -35,6 +37,8 @@ export type DetectionData = {
|
|||||||
first_detected_frame: number
|
first_detected_frame: number
|
||||||
first_detected_time: number
|
first_detected_time: number
|
||||||
confidence: number
|
confidence: number
|
||||||
|
lat?: number
|
||||||
|
lng?: number
|
||||||
}>
|
}>
|
||||||
frames: Array<{
|
frames: Array<{
|
||||||
frame_id: number
|
frame_id: number
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ type UploadSectionProps = {
|
|||||||
|
|
||||||
export function UploadSection({ onDetectionComplete, onDetectionTypeChange }: UploadSectionProps) {
|
export function UploadSection({ onDetectionComplete, onDetectionTypeChange }: UploadSectionProps) {
|
||||||
const [file, setFile] = useState<File | null>(null)
|
const [file, setFile] = useState<File | null>(null)
|
||||||
|
const [jsonFile, setJsonFile] = useState<File | null>(null)
|
||||||
const [speed, setSpeed] = useState(30)
|
const [speed, setSpeed] = useState(30)
|
||||||
const [detectionType, setDetectionType] = useState<DetectionType>("pothole-detection")
|
const [detectionType, setDetectionType] = useState<DetectionType>("pothole-detection")
|
||||||
const [uploading, setUploading] = useState(false)
|
const [uploading, setUploading] = useState(false)
|
||||||
@@ -28,6 +29,7 @@ export function UploadSection({ onDetectionComplete, onDetectionTypeChange }: Up
|
|||||||
const [statusMessage, setStatusMessage] = useState("")
|
const [statusMessage, setStatusMessage] = useState("")
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||||
|
const jsonFileInputRef = useRef<HTMLInputElement>(null)
|
||||||
const wsRef = useRef<WebSocket | null>(null)
|
const wsRef = useRef<WebSocket | null>(null)
|
||||||
|
|
||||||
const handleDetectionTypeChange = (value: DetectionType) => {
|
const handleDetectionTypeChange = (value: DetectionType) => {
|
||||||
@@ -134,6 +136,11 @@ export function UploadSection({ onDetectionComplete, onDetectionTypeChange }: Up
|
|||||||
formData.append("detection_type", detectionType)
|
formData.append("detection_type", detectionType)
|
||||||
formData.append("speed_kmh", speed.toString())
|
formData.append("speed_kmh", speed.toString())
|
||||||
|
|
||||||
|
// Add JSON file if provided
|
||||||
|
if (jsonFile) {
|
||||||
|
formData.append("json_file", jsonFile)
|
||||||
|
}
|
||||||
|
|
||||||
setUploading(true)
|
setUploading(true)
|
||||||
setProgress(0)
|
setProgress(0)
|
||||||
setStatusMessage("Uploading...")
|
setStatusMessage("Uploading...")
|
||||||
@@ -199,7 +206,7 @@ export function UploadSection({ onDetectionComplete, onDetectionTypeChange }: Up
|
|||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-4">
|
<CardContent className="space-y-4">
|
||||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
{/* File Input */}
|
{/* File Input */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="video-file">Video File</Label>
|
<Label htmlFor="video-file">Video File</Label>
|
||||||
@@ -224,6 +231,30 @@ export function UploadSection({ onDetectionComplete, onDetectionTypeChange }: Up
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* JSON File Input */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="json-file">GPS JSON File</Label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Input
|
||||||
|
ref={jsonFileInputRef}
|
||||||
|
id="json-file"
|
||||||
|
type="file"
|
||||||
|
accept=".json,application/json"
|
||||||
|
onChange={(e) => {
|
||||||
|
setJsonFile(e.target.files?.[0] || null)
|
||||||
|
setError(null)
|
||||||
|
}}
|
||||||
|
disabled={uploading}
|
||||||
|
className="flex-1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{jsonFile && (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Selected: {jsonFile.name} ({(jsonFile.size / 1024).toFixed(2)} KB)
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Detection Type Selector */}
|
{/* Detection Type Selector */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="detection-type">Detection Type</Label>
|
<Label htmlFor="detection-type">Detection Type</Label>
|
||||||
@@ -238,13 +269,11 @@ export function UploadSection({ onDetectionComplete, onDetectionTypeChange }: Up
|
|||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="pothole-detection">
|
<SelectItem value="pothole-detection">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<span>🕳️</span>
|
|
||||||
<span>Pothole Detection</span>
|
<span>Pothole Detection</span>
|
||||||
</div>
|
</div>
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
<SelectItem value="sign-board-detection">
|
<SelectItem value="sign-board-detection">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<span>🚦</span>
|
|
||||||
<span>Signboard Detection</span>
|
<span>Signboard Detection</span>
|
||||||
</div>
|
</div>
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ type DetectionLog = {
|
|||||||
type?: string // For signboards
|
type?: string // For signboards
|
||||||
bbox: { x1: number; y1: number; x2: number; y2: number }
|
bbox: { x1: number; y1: number; x2: number; y2: number }
|
||||||
confidence: number
|
confidence: number
|
||||||
|
latitude?: number
|
||||||
|
longitude?: number
|
||||||
}>
|
}>
|
||||||
timestamp: string
|
videoTime: string // Video timestamp (MM:SS)
|
||||||
}
|
}
|
||||||
|
|
||||||
function SummarySection({ data, show, detectionType }: { data: DetectionData; show: boolean; detectionType: DetectionType }) {
|
function SummarySection({ data, show, detectionType }: { data: DetectionData; show: boolean; detectionType: DetectionType }) {
|
||||||
@@ -120,6 +122,8 @@ export default function VideoPlayerSection({ data, videoId, videoFile, detection
|
|||||||
const [showSummary, setShowSummary] = useState(false)
|
const [showSummary, setShowSummary] = useState(false)
|
||||||
const [hasPlayedOnce, setHasPlayedOnce] = useState(false)
|
const [hasPlayedOnce, setHasPlayedOnce] = useState(false)
|
||||||
const [videoError, setVideoError] = useState<string | null>(null)
|
const [videoError, setVideoError] = useState<string | null>(null)
|
||||||
|
const [lastDetectedLat, setLastDetectedLat] = useState<number | null>(null)
|
||||||
|
const [lastDetectedLng, setLastDetectedLng] = useState<number | null>(null)
|
||||||
const frameDetectionMap = useRef<Map<number, any[]>>(new Map())
|
const frameDetectionMap = useRef<Map<number, any[]>>(new Map())
|
||||||
const lastProcessedFrame = useRef(-1)
|
const lastProcessedFrame = useRef(-1)
|
||||||
const loggedFrames = useRef<Set<number>>(new Set())
|
const loggedFrames = useRef<Set<number>>(new Set())
|
||||||
@@ -128,6 +132,45 @@ export default function VideoPlayerSection({ data, videoId, videoFile, detection
|
|||||||
const isPothole = detectionType === "pothole-detection"
|
const isPothole = detectionType === "pothole-detection"
|
||||||
const isSignboard = detectionType === "sign-board-detection"
|
const isSignboard = detectionType === "sign-board-detection"
|
||||||
|
|
||||||
|
// Create GPS coordinate map from signboard_list or pothole_list
|
||||||
|
const gpsMap = useRef<Map<number, { lat: number; lng: number }>>(new Map())
|
||||||
|
|
||||||
|
// Build GPS map from signboard_list or pothole_list
|
||||||
|
useEffect(() => {
|
||||||
|
const map = new Map()
|
||||||
|
|
||||||
|
if (isPothole && data.pothole_list) {
|
||||||
|
data.pothole_list.forEach(item => {
|
||||||
|
if (item.lat !== undefined && item.lng !== undefined) {
|
||||||
|
map.set(item.pothole_id, { lat: item.lat, lng: item.lng })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (isSignboard && data.signboard_list) {
|
||||||
|
data.signboard_list.forEach(item => {
|
||||||
|
if (item.lat !== undefined && item.lng !== undefined) {
|
||||||
|
map.set(item.signboard_id, { lat: item.lat, lng: item.lng })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
gpsMap.current = map
|
||||||
|
console.log(`[VideoPlayer] GPS map built with ${map.size} entries`)
|
||||||
|
}, [data, isPothole, isSignboard])
|
||||||
|
|
||||||
|
// Helper function to format video time from frame number
|
||||||
|
const formatVideoTime = useCallback((frame: number, fps: number): string => {
|
||||||
|
const seconds = frame / fps
|
||||||
|
const hours = Math.floor(seconds / 3600)
|
||||||
|
const minutes = Math.floor((seconds % 3600) / 60)
|
||||||
|
const secs = Math.floor(seconds % 60)
|
||||||
|
|
||||||
|
if (hours > 0) {
|
||||||
|
return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
|
||||||
|
}
|
||||||
|
return `${minutes}:${secs.toString().padStart(2, '0')}`
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
// Build optimized frame detection map
|
// Build optimized frame detection map
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const map = new Map()
|
const map = new Map()
|
||||||
@@ -297,22 +340,40 @@ export default function VideoPlayerSection({ data, videoId, videoFile, detection
|
|||||||
|
|
||||||
loggedFrames.current.add(frame)
|
loggedFrames.current.add(frame)
|
||||||
|
|
||||||
|
// Update last detected GPS coordinates if available
|
||||||
|
if (detections.length > 0) {
|
||||||
|
const detectionId = isPothole ? detections[0].pothole_id : detections[0].signboard_id
|
||||||
|
const gpsCoords = gpsMap.current.get(detectionId)
|
||||||
|
|
||||||
|
if (gpsCoords) {
|
||||||
|
setLastDetectedLat(gpsCoords.lat)
|
||||||
|
setLastDetectedLng(gpsCoords.lng)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setLogs((prev) => {
|
setLogs((prev) => {
|
||||||
const newLog: DetectionLog = {
|
const newLog: DetectionLog = {
|
||||||
frame,
|
frame,
|
||||||
detections: detections.map((det) => ({
|
detections: detections.map((det) => {
|
||||||
id: isPothole ? det.pothole_id : det.signboard_id,
|
const detectionId = isPothole ? det.pothole_id : det.signboard_id
|
||||||
|
const gpsCoords = gpsMap.current.get(detectionId)
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: detectionId,
|
||||||
type: isSignboard ? det.type : undefined,
|
type: isSignboard ? det.type : undefined,
|
||||||
bbox: det.bbox,
|
bbox: det.bbox,
|
||||||
confidence: det.confidence,
|
confidence: det.confidence,
|
||||||
})),
|
latitude: gpsCoords?.lat,
|
||||||
timestamp: new Date().toLocaleTimeString(),
|
longitude: gpsCoords?.lng,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
videoTime: formatVideoTime(frame, data.video_info.fps),
|
||||||
}
|
}
|
||||||
|
|
||||||
const updated = [newLog, ...prev].slice(0, MAX_LOGS)
|
const updated = [newLog, ...prev].slice(0, MAX_LOGS)
|
||||||
return updated
|
return updated
|
||||||
})
|
})
|
||||||
}, [isPothole, isSignboard])
|
}, [isPothole, isSignboard, formatVideoTime, data.video_info.fps])
|
||||||
|
|
||||||
// Track current frame and log detections
|
// Track current frame and log detections
|
||||||
const updateFrameInfo = useCallback(() => {
|
const updateFrameInfo = useCallback(() => {
|
||||||
@@ -479,6 +540,22 @@ export default function VideoPlayerSection({ data, videoId, videoFile, detection
|
|||||||
<span className="text-muted-foreground">FPS:</span>
|
<span className="text-muted-foreground">FPS:</span>
|
||||||
<Badge variant="outline">{data.video_info.fps.toFixed(1)}</Badge>
|
<Badge variant="outline">{data.video_info.fps.toFixed(1)}</Badge>
|
||||||
</div>
|
</div>
|
||||||
|
{lastDetectedLat !== null && lastDetectedLng !== null && (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<span className="text-muted-foreground text-xs">Lat:</span>
|
||||||
|
<Badge variant="outline" className="font-mono text-xs px-1.5 py-0">
|
||||||
|
{lastDetectedLat.toFixed(6)}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<span className="text-muted-foreground text-xs">Lng:</span>
|
||||||
|
<Badge variant="outline" className="font-mono text-xs px-1.5 py-0">
|
||||||
|
{lastDetectedLng.toFixed(6)}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -506,7 +583,7 @@ export default function VideoPlayerSection({ data, videoId, videoFile, detection
|
|||||||
>
|
>
|
||||||
<div className="flex items-center justify-between mb-2">
|
<div className="flex items-center justify-between mb-2">
|
||||||
<span className="font-semibold text-foreground">Frame: {log.frame}</span>
|
<span className="font-semibold text-foreground">Frame: {log.frame}</span>
|
||||||
<span className="text-muted-foreground text-[10px]">{log.timestamp}</span>
|
<span className="text-muted-foreground text-[10px]">{log.videoTime}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{log.detections.length === 0 ? (
|
{log.detections.length === 0 ? (
|
||||||
@@ -526,6 +603,11 @@ export default function VideoPlayerSection({ data, videoId, videoFile, detection
|
|||||||
<div className="text-muted-foreground font-mono text-[10px]">
|
<div className="text-muted-foreground font-mono text-[10px]">
|
||||||
Coordinates: ({Math.round(det.bbox.x1)}, {Math.round(det.bbox.y1)}) → ({Math.round(det.bbox.x2)}, {Math.round(det.bbox.y2)})
|
Coordinates: ({Math.round(det.bbox.x1)}, {Math.round(det.bbox.y1)}) → ({Math.round(det.bbox.x2)}, {Math.round(det.bbox.y2)})
|
||||||
</div>
|
</div>
|
||||||
|
{det.latitude !== undefined && det.longitude !== undefined && (
|
||||||
|
<div className="text-muted-foreground font-mono text-[10px]">
|
||||||
|
GPS: {det.latitude.toFixed(6)}, {det.longitude.toFixed(6)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user