File size: 1,510 Bytes
41f903d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import cv2
import os
import sys
import numpy as np

# Add backend to path
sys.path.append(os.path.join(r"c:\Users\Rajesh s\Downloads\KARPAGAM HACKATHON", "backend"))
from detector import engine, model

video_path = r"c:\Users\Rajesh s\Downloads\KARPAGAM HACKATHON\test_traffic_video.mp4"
if not os.path.exists(video_path):
    print("Video not found!")
    sys.exit(1)

cap = cv2.VideoCapture(video_path)
success, frame = cap.read()
if not success:
    print("Could not read frame!")
    sys.exit(1)

frame = cv2.resize(frame, (800, 600))
results = model.track(frame, persist=True, verbose=False, classes=[2, 3, 5, 7])[0]

# Draw ALL detected cars in BLUE
if results.boxes:
    for box in results.boxes:
        x1, y1, x2, y2 = map(int, box.xyxy[0])
        cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 255, 0), 2)
        cv2.putText(frame, "CAR", (x1, y1-5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 0), 1)

# Draw ALL calibrated slots in GREEN
for i, slot in enumerate(engine.cached_slots or []):
    y1, x1, y2, x2 = slot
    cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 1)
    cv2.putText(frame, f"Slot {i+1}", (x1, y1+15), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 255, 0), 1)

output_path = r"c:\Users\Rajesh s\Downloads\KARPAGAM HACKATHON\debug_alignment.jpg"
cv2.imwrite(output_path, frame)
print(f"Debug image saved at: {output_path}")
print("Please check this image to see if the Green boxes (slots) align with the Blue boxes (cars).")

cap.release()