2016-12-14 32 views
0

Windowsで同じプログラムを実行できます。 Ubuntu 16.04、64ビットでlsusbを使って自分のカメラを見ることができます。カメラはOSVR赤外線カメラです。Ubuntu WebCameraを読んでいるときに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() 
関連する問題