2016-12-14 290 views
0

我可以在Windows中運行相同的程序。我可以在Ubuntu 16.04,64位下使用lsusb查看我的相機。該相機是OSVR紅外相機。在閱讀webCamera時出現Ubuntu OpenCV錯誤

我的計劃是

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() 

的結果是:

[email protected]:~/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_ 

回答

0

檢查幀不是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()