aidas-79 commited on
Commit
cde077a
·
verified ·
1 Parent(s): 086514a

Update video_detection.py

Browse files
Files changed (1) hide show
  1. video_detection.py +29 -1
video_detection.py CHANGED
@@ -1,5 +1,9 @@
1
  from ultralytics import YOLO
2
  import cv2
 
 
 
 
3
 
4
  model = YOLO("model/yolo11n_6-2-25.pt")
5
 
@@ -25,15 +29,38 @@ def draw_boxes(frame, results):
25
  cv2.putText(frame, cls, org, font, fontScale, color, thickness)
26
 
27
  return frame
 
 
 
 
 
 
 
28
 
 
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def video_detection(cap):
31
  frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
32
  frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
33
  fps = int(cap.get(cv2.CAP_PROP_FPS))
34
 
35
  out = cv2.VideoWriter('output_video.mp4', cv2.VideoWriter_fourcc(*'h264'), fps, (frame_width, frame_height))
36
-
37
  count = 0
38
  while cap.isOpened():
39
  success, frame = cap.read()
@@ -57,3 +84,4 @@ def video_detection(cap):
57
  cv2.destroyAllWindows()
58
 
59
  yield None, 'output_video.mp4'
 
 
1
  from ultralytics import YOLO
2
  import cv2
3
+ from PIL import Image
4
+ import time
5
+ import numpy as np
6
+ import uuid
7
 
8
  model = YOLO("model/yolo11n_6-2-25.pt")
9
 
 
29
  cv2.putText(frame, cls, org, font, fontScale, color, thickness)
30
 
31
  return frame
32
+
33
+ def video_detection(cap):
34
+ frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
35
+ frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
36
+ fps = int(cap.get(cv2.CAP_PROP_FPS))
37
+
38
+ cap = cv2.VideoCapture(video)
39
 
40
+ video_codec = cv2.VideoWriter_fourcc(*"mp4v") # type: ignore
41
+ fps = int(cap.get(cv2.CAP_PROP_FPS))
42
 
43
+ desired_fps = fps // SUBSAMPLE
44
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) // 2
45
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) // 2
46
+
47
+ iterating, frame = cap.read()
48
+
49
+ n_frames = 0
50
+
51
+ name = f"output_{uuid.uuid4()}.mp4"
52
+ segment_file = cv2.VideoWriter(name, video_codec, desired_fps, (width, height)) # type: ignore
53
+ batch = []
54
+
55
+ """
56
+ #@spaces.GPU
57
  def video_detection(cap):
58
  frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
59
  frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
60
  fps = int(cap.get(cv2.CAP_PROP_FPS))
61
 
62
  out = cv2.VideoWriter('output_video.mp4', cv2.VideoWriter_fourcc(*'h264'), fps, (frame_width, frame_height))
63
+
64
  count = 0
65
  while cap.isOpened():
66
  success, frame = cap.read()
 
84
  cv2.destroyAllWindows()
85
 
86
  yield None, 'output_video.mp4'
87
+ """