加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

opencv python VideoWriter的问题

发布时间:2020-12-20 11:38:17 所属栏目:Python 来源:网络整理
导读:我一直试图让openCV python VideoWriter对象无法正常工作.我要做的是读取视频,抓取帧,进行一些处理并将其写回视频文件.我得到的错误是: Traceback (most recent call last):File "detect.py",line 35,in module out_video.write(processed)cv2.error: /tmp/
我一直试图让openCV python VideoWriter对象无法正常工作.我要做的是读取视频,抓取帧,进行一些处理并将其写回视频文件.我得到的错误是:

Traceback (most recent call last):
File "detect.py",line 35,in <module>
    out_video.write(processed)
cv2.error: /tmp/opencv-z9Pa/opencv-2.4.9/modules/imgproc/src/color.cpp:4419: 
error: (-215) src.depth() == dst.depth() in function cvCvtColor

我写的代码如下:

video = VideoCapture(args["video"])
num_frames = video.get(CV_CAP_PROP_FRAME_COUNT)
width = video.get(CV_CAP_PROP_FRAME_WIDTH)
height = video.get(CV_CAP_PROP_FRAME_HEIGHT)

fps = video.get(CV_CAP_PROP_FPS)

out_video = VideoWriter()
fourcc = CV_FOURCC('m','p','4','v')
out_video.open(args["out"],fourcc,int(fps),(int(width),int(height)),True)

while (video.isOpened()):
    ret,frame = video.read()
    #?This simply takes the frame and does some image processing on it
    segments = compute_superpixels(frame,num_pixels=100)
    processed = mark_boundaries(frame,segments)
    out_video.write(processed)

有谁知道我在这里做错了什么?

[编辑]

我尝试了一些可能会带来一些亮点(或不亮)的东西.所以,如果我想写原始帧,即替换

out_video.write(processed)

out_video.write(frame)

我收回了原始视频.但是,框架和处理对象具有相同的大小和类型!所以,现在我完全不知道发生了什么.处理和框架形状和类型的输出是:

frame: (576,720,3)
processed: (576,3)
frame: <type 'numpy.ndarray'>
processed: <type 'numpy.ndarray'>

解决方法

我弄清楚出了什么问题.这条线

processed = mark_boundaries(frame,segments)

实际上是将图像归一化在0和1之间,所以它不是8位深度,这是一个问题.该修复程序正在执行以下操作:

processed = (processed * 255.0).astype('u1')

然后将其传递给VideoWriter.write_frame().

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读