Spaces:
Runtime error
Runtime error
Update video_detection.py
Browse files- video_detection.py +7 -5
video_detection.py
CHANGED
@@ -32,10 +32,11 @@ def draw_boxes(frame, results):
|
|
32 |
return frame
|
33 |
|
34 |
def video_detection(cap):
|
35 |
-
video_codec = cv2.VideoWriter_fourcc(*"mp4v") # type: ignore
|
|
|
36 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
37 |
|
38 |
-
desired_fps = fps // SUBSAMPLE
|
39 |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) // 2
|
40 |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) // 2
|
41 |
|
@@ -44,14 +45,15 @@ def video_detection(cap):
|
|
44 |
n_frames = 0
|
45 |
|
46 |
name = f"output_{uuid.uuid4()}.mp4"
|
47 |
-
segment_file = cv2.VideoWriter(name, video_codec,
|
48 |
batch = []
|
49 |
while iterating:
|
50 |
frame = cv2.resize( frame, (0,0), fx=0.5, fy=0.5)
|
51 |
#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
52 |
if n_frames % SUBSAMPLE == 0:
|
53 |
batch.append(frame)
|
54 |
-
if len(batch) == 2 * desired_fps:
|
|
|
55 |
#inputs = image_processor(images=batch, return_tensors="pt").to("cuda")
|
56 |
|
57 |
print(f"starting batch of size {len(batch)}")
|
@@ -90,7 +92,7 @@ def video_detection(cap):
|
|
90 |
end = time.time()
|
91 |
print("time taken for processing boxes", end - start)
|
92 |
name = f"output_{uuid.uuid4()}.mp4"
|
93 |
-
segment_file = cv2.VideoWriter(name, video_codec,
|
94 |
|
95 |
iterating, frame = cap.read()
|
96 |
n_frames += 1
|
|
|
32 |
return frame
|
33 |
|
34 |
def video_detection(cap):
|
35 |
+
#video_codec = cv2.VideoWriter_fourcc(*"mp4v") # type: ignore
|
36 |
+
video_codec = cv2.VideoWriter_fourcc(*'h264')
|
37 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
38 |
|
39 |
+
#desired_fps = fps // SUBSAMPLE
|
40 |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) // 2
|
41 |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) // 2
|
42 |
|
|
|
45 |
n_frames = 0
|
46 |
|
47 |
name = f"output_{uuid.uuid4()}.mp4"
|
48 |
+
segment_file = cv2.VideoWriter(name, video_codec, fps, (width, height)) # type: ignore
|
49 |
batch = []
|
50 |
while iterating:
|
51 |
frame = cv2.resize( frame, (0,0), fx=0.5, fy=0.5)
|
52 |
#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
53 |
if n_frames % SUBSAMPLE == 0:
|
54 |
batch.append(frame)
|
55 |
+
#if len(batch) == 2 * desired_fps:
|
56 |
+
if len(batch) == 8:
|
57 |
#inputs = image_processor(images=batch, return_tensors="pt").to("cuda")
|
58 |
|
59 |
print(f"starting batch of size {len(batch)}")
|
|
|
92 |
end = time.time()
|
93 |
print("time taken for processing boxes", end - start)
|
94 |
name = f"output_{uuid.uuid4()}.mp4"
|
95 |
+
segment_file = cv2.VideoWriter(name, video_codec, fps, (width, height)) # type: ignore
|
96 |
|
97 |
iterating, frame = cap.read()
|
98 |
n_frames += 1
|