opencv - VideoCapture 返回空帧,但保存到磁盘时是正确的帧吗?

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

最佳答案

你可以检查“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/

相关文章:

python - OPENCV:以可变帧速率提取视频中帧的生命周期

java - 为什么Eclipse无法检测到以cv开头的javacv函数

c++ - 在 Ubuntu 上使用 GUI 安装 OpenCV

python - 属性错误 : module 'cv2.cv2' has no attribute 'bgsegm

iphone - 同时 AVCaptureVideoDataOutput 和 AVCaptureMovieFileOutput

c++ - 在 C++ 中使用具有可变帧速率的 FFmpeg 库(不是 libav 分支)以编程方式捕获视频

c++ - 当我尝试在启用推理引擎的情况下编译OpenCv时,出现错误

matlab - 使用matlab提取人脸特征

c++ - 如何同时使用两个CameraCaptureUI(UWP/C++)

python - 无法使用 python 通过 v4l2loopback 设备生成稳定的视频流