VideoCapture returns 一个空帧,但保存到磁盘时是一个正确的帧吗?

VideoCapture returns an empty frame, but is a proper frame when saved to disk?

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 数组,但在保存到计算机时显示正确的图像

您可以查看"frame is empty or not"和"does success return true?",然后您可以将其保存在保险箱中。

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")