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

问题描述 投票:1回答:1
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数组,但保存到计算机时会显示正确的图像

opencv video-capture
1个回答
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")
© www.soinside.com 2019 - 2024. All rights reserved.