Create services/video_service.py
Browse files- services/video_service.py +21 -0
services/video_service.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
|
| 3 |
+
def process_video(uploaded_file):
|
| 4 |
+
video_path = "/tmp/" + uploaded_file.name
|
| 5 |
+
with open(video_path, "wb") as f:
|
| 6 |
+
f.write(uploaded_file.read())
|
| 7 |
+
|
| 8 |
+
cap = cv2.VideoCapture(video_path)
|
| 9 |
+
results = []
|
| 10 |
+
|
| 11 |
+
while cap.isOpened():
|
| 12 |
+
ret, frame = cap.read()
|
| 13 |
+
if not ret:
|
| 14 |
+
break
|
| 15 |
+
|
| 16 |
+
# Process each frame for detection
|
| 17 |
+
fault_results = detect_faults(frame) # Assuming a function to process the frame
|
| 18 |
+
results.append(fault_results)
|
| 19 |
+
|
| 20 |
+
cap.release()
|
| 21 |
+
return results
|