【发布时间】:2022-10-20 07:29:30
【问题描述】:
我正在尝试对视频进行一些图像处理,然后在 colab 上使用 opencv 保存生成的视频。但是,我无法访问我正在写入的生成的视频文件。
import cv2
from google.colab.patches import cv2_imshow
import numpy as np
fourcc = cv2.VideoWriter_fourcc(*'H264')
cap = cv2.VideoCapture(vid_file)
out = cv2.VideoWriter('output.mp4',fourcc,30.0,(1124,1080))
cnt = 0
ret = True
while(ret):
ret,frame = cap.read()
print(cnt,end=' ')
# check if prey was tracked on this frame
match = np.where(prey_frames==cnt)[0]
if match:
prey_frame = match[0]
# print(prey_frame)
image = cv2.circle(frame,(int(prey_px[prey_frame].x),95+int(prey_px[prey_frame].y)),
radius=5,color=(255,0,255),thickness=2)
else:
image = frame
out.write(image)
cnt += 1
out.release()
cap.release()
cv2.destroyAllWindows()
据我了解,这应该写入一个名为“output.mp4”的文件。此代码运行没有错误,但当前目录中没有文件,并且没有该名称的文件可供下载(使用 files.download('output.mp4') 返回“找不到文件”错误)。
任何帮助,将不胜感激!
【问题讨论】:
标签: opencv google-colaboratory