VideoCapture返回一个空帧,但保存到磁盘时是一个合适的帧?

时间:2018-03-07 06:17:56

标签: opencv video-capture

video=cv2.VideoCapture('video.avi')
success,frame=video.read()

# when the frame is printed it prints an array with all 0's
print(frame)

# But it is a proper image when saved to disk
cv2.imwrite("frame.jpg",frame)

代码打印出0的numpy数组,但保存到计算机时会显示正确的图像

1 个答案:

答案 0 :(得分:2)

您可以检查“框架是否为空”和“成功是否返回?”,然后您可以将其保存在安全状态。

video=cv2.VideoCapture('video.avi')
success,frame=video.read()

if(success and !(frame.empty())):      
    print(frame)
    cv2.imwrite("frame.jpg",frame)
else:
    print("empty frame")