繁体   English   中英

Python OpenCV cv2.VideoWriter 错误

[英]Python OpenCV cv2.VideoWriter Error

我正在尝试导出来自热像仪的数据,但收到一条错误消息,指出

error: /build/opencv-ISmtkH/opencv-2.4.9.1+dfsg/modules/highgui/src/cap_ffmpeg.cpp:238: error: (-215) image->depth == 8 in function writeFrame

有人可以看看我在做什么并告诉我我做错了什么吗? 我非常密切地遵循和示例,所以我不明白这个错误意味着什么或为什么会发生。

o = camera.add_overlay(np.getbuffer(a), size=(320,240), layer=3, alpha=int(alpha), crop=(0,0,80,60), vflip=flip_v)

filename = time.strftime("%Y.%m.%d  %H.%M.%S", time.localtime()) + ".avi"
fourcc =  cv2.cv.CV_FOURCC('I','4','2','0')
out = cv2.VideoWriter(filename, fourcc, fps, (width, height))

try:
  time.sleep(0.2) # give the overlay buffers a chance to initialize
  with Lepton(device) as l:
    last_nr = 0
    while True:
      _,nr = l.capture(lepton_buf)

      out.write(lepton_buf)

      if nr == last_nr:
        # no need to redo this frame
        continue
      last_nr = nr
      cv2.normalize(lepton_buf, lepton_buf, 0, 65535, cv2.NORM_MINMAX)
      np.right_shift(lepton_buf, 8, lepton_buf)
      a[:lepton_buf.shape[0], :lepton_buf.shape[1], :] = lepton_buf
      o.update(np.getbuffer(a))
except Exception:
  traceback.print_exc()
finally:
  camera.remove_overlay(o)

您需要将out.write(lepton_buf)更改为out.write(np.uint8(lepton_buf))

你试图写的不是一个数字,这就是混淆它的原因。

几个尝试的建议

尝试更常见的编解码器:

fourcc=cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')

确保您的视频尺寸适合图像尺寸。 尝试交换宽度和高度,它们的顺序可能会令人困惑。

height,width,channels=lepton_buf.shape

或直接为您的视频指定宽度和高度:

out = cv2.VideoWriter(filename, fourcc, 8.0, (60, 80))

正如@Crystal 之前所述,请确保将图像数据转换为数据类型“uint8”

尝试保存为“新”文件名。 有时,opencv videowriter 会默默地无法保存到未从先前访问中正确释放的文件中。

最后,完成写帧后释放您的文件!

out.release()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM