d代码如下:
import cv2
def detect(frame):#对视频进行处理
img=cv2.rectangle(frame,(1,10),(100,300),color=(255,255,1),thickness=3)#里面画一个框
return img
mp4_path = r'..\data\fish.mp4'
print(mp4_path)
cap = cv2.VideoCapture(mp4_path)
# # 设置视频的编码格式
fourcc = cv2.VideoWriter.fourcc(*'avci')
# # 定义视频保存的输出属性
out = cv2.VideoWriter(r'outpt_test.mp4', fourcc, 15, (1280, 720))#图片的宽高一定要对应
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
img = detect(frame)
out.write(img)
out.release()
cap.release()
def detect(frame):#对视频进行处理
img=cv2.rectangle(frame,(1,10),(100,300),color=(255,255,1),thickness=3)#里面画一个框
return img
ps:如果显示出来的的保存的视频是1Kb,就说明输出图想你设置的宽高和原来的宽高不匹配