读取网络摄像头时的Ubuntu OpenCV错误



i可以在Windows中运行相同的程序。我可以在Ubuntu 16.04,64位使用LSUSB看到我的相机。相机是OSVR红外摄像头。

我的程序是

import numpy as np
import cv2
camera = cv2.VideoCapture(0)
while(True):
    # Capture frame-by-frame
    ret, frame = camera.read()
    cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('camera', frame)
    #    k = cv2.waitKey(30)
# When everything done, release the capture
camera.release()
cv2.destroyAllWindows()

结果是:

cwu@ubuntu:~/project/osvrCamera$ python test.py 
select timeout
select timeout
OpenCV Error: Assertion failed (!buf.empty() && buf.isContinuous()) in imdecode_, file /tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/imgcodecs/src/loadsave.cpp, line 490
Traceback (most recent call last):
File "test.py", line 8, in <module>
ret, frame = camera.read() 
cv2.error: /tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/imgcodecs/src/loadsave.cpp:490: error: (-215) !buf.empty() && buf.isContinuous() in function imdecode_

检查框架是否不是empty()(可能是在尝试转换/显示时凸轮/帧未完全初始化的:

import numpy as np
import cv2
camera = cv2.VideoCapture(0)
while(True):
    # Capture frame-by-frame
    ret, frame = camera.read()
    if not frame.empty():
       cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
       cv2.imshow('camera', frame)
    #    k = cv2.waitKey(30)
# When everything done, release the capture
camera.release()
cv2.destroyAllWindows()

最新更新