rajesh9698 commited on
Commit
e8a819e
·
verified ·
1 Parent(s): 8742183

Deploy: test_video_engine.py

Browse files
Files changed (1) hide show
  1. test_video_engine.py +54 -0
test_video_engine.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import os
3
+ import sys
4
+
5
+ # Add the current directory to path so we can import detector
6
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'backend')))
7
+ from detector import engine
8
+
9
+ # Define sources
10
+ video_source = 'test_traffic_video.mp4'
11
+ output_file = 'backend/output_analysis.mp4'
12
+
13
+ if not os.path.exists(video_source):
14
+ print(f"Error: {video_source} not found!")
15
+ sys.exit(1)
16
+
17
+ cap = cv2.VideoCapture(video_source)
18
+
19
+ # Get video properties
20
+ frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
21
+ frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
22
+ fps = int(cap.get(cv2.CAP_PROP_FPS)) or 20
23
+
24
+ # Define the codec and create VideoWriter object
25
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
26
+ out = cv2.VideoWriter(output_file, fourcc, fps, (800, 600)) # Engine resizes to 800x600
27
+
28
+ print(f"Starting analysis on {video_source}...")
29
+ print("Saving output to", output_file)
30
+
31
+ frame_count = 0
32
+ max_frames = 100 # Let's just process 100 frames for a quick test
33
+
34
+ try:
35
+ while cap.isOpened() and frame_count < max_frames:
36
+ ret, frame = cap.read()
37
+ if not ret:
38
+ break
39
+
40
+ # Process the frame through our Smart Parking Engine
41
+ annotated_frame, total, occupied, free, _ = engine.process_frame(frame)
42
+
43
+ # Write the frame
44
+ out.write(annotated_frame)
45
+
46
+ frame_count += 1
47
+ if frame_count % 10 == 0:
48
+ print(f"Processed {frame_count} frames...")
49
+
50
+ finally:
51
+ cap.release()
52
+ out.release()
53
+ print(f"\nSuccess! Processed {frame_count} frames.")
54
+ print(f"Annotated video saved at: {os.path.abspath(output_file)}")