Spaces:
Sleeping
Sleeping
File size: 907 Bytes
23d3c5a 9a1a12e a0d3b60 d018658 bd0d2bb 23d3c5a 9a1a12e 23d3c5a 9a1a12e bd0d2bb 9a1a12e |
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 |
import gradio as gr
import cv2
from Yolov5_Deepsort.demo import app_main
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def process_video(video):
# 打开视频文件
cap = cv2.VideoCapture(video)
# 创建一个 VideoWriter 对象以保存处理后的视频
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (int(cap.get(3)), int(cap.get(4))))
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# 处理帧,例如将其转换为灰度
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# 将处理后的帧写入输出视频
out.write(cv2.cvtColor(gray_frame, cv2.COLOR_GRAY2BGR))
cap.release()
out.release()
return 'output.mp4'
demo = gr.Interface(fn=app_main, inputs="video", outputs="video")
demo.launch()
|