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是否为空”和“success是否返回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")
关于opencv - VideoCapture 返回空帧,但保存到磁盘时是正确的帧吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49145370/