Spaces:
No application file
No application file
File size: 1,076 Bytes
ba2e328 |
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 |
import cv2
import tempfile
from utils.fault_detection import detect_faults
from utils.image_processing import preprocess_image
import os
def process_video(video_path, frame_interval=30):
cap = cv2.VideoCapture(video_path)
fps = cap.get(cv2.CAP_PROP_FPS)
frame_count = 0
fault_report = []
annotated_frames = []
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
temp_out = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
out = cv2.VideoWriter(temp_out.name, fourcc, fps, (int(cap.get(3)), int(cap.get(4))))
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
if frame_count % frame_interval == 0:
processed = preprocess_image(frame)
faults, annotated = detect_faults(processed)
for f in faults:
f["frame"] = frame_count
fault_report.append(f)
out.write(annotated)
else:
out.write(frame)
frame_count += 1
cap.release()
out.release()
return temp_out.name, fault_report
|