Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python OpenCV cv2.VideoWriter错误_Python_Opencv_Camera_Thermal Printer - Fatal编程技术网

Python OpenCV cv2.VideoWriter错误

Python OpenCV cv2.VideoWriter错误,python,opencv,camera,thermal-printer,Python,Opencv,Camera,Thermal Printer,我正试图导出来自热像仪的数据,但我收到一条错误消息,上面说 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

我正试图导出来自热像仪的数据,但我收到一条错误消息,上面说

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\u buf)
更改为
out.write(np.uint8(lepton\u 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()

这消除了错误,但输出的文件总是损坏的。知道为什么吗?你说的损坏是什么意思吗?你还缺少了一个
out.release()
语句,因此缓冲区永远不会被清空。你也这样做了,但程序继续吐出一个8K文件,里面什么都没有。试着将它移到
a[:lepton\u buf.shape[0],:lepton\u buf.shape[1],:]=lepton_buf
行并调整大小。谢谢。我尝试了第一个建议,但它给了我一个模块错误,所以我想我会继续使用现在的编解码器。你知道有没有办法确定视频的高度和宽度?数据表告诉我分辨率是80x60,但由于我使用了其他代码来运行相机,我想确保我的数字是正确的。你使用的是什么系统?我很惊讶xvid在您的opencv/ffmpeg中不可用。您是否曾经通过opencv在您的计算机上成功保存过任何视频?您的代码指定
out=cv2.VideoWriter(文件名,fourcc,fps,(宽度,高度))
。在何处指定宽度和高度?请在语句
out.write(lepton\u buf)
之前使用
print lepton\u buf.shape()
检查视频数据的格式。这将为每一帧打印,也将是一个检查帧是否来自您的相机的健全检查。请尝试
out=cv2。VideoWriter(文件名,fourcc,8.0,(60,80))