2017-11-28 43 views
0

Ubuntu 16.04のOpenCVの統合Webカメラが以下のエラーを投げ捨てています。私は別のプログラムでチーズをチェックしましたが、まだ画像とビデオが表示されていますので、ここでカメラ自体は問題ではないようです。Ubuntu 16.04(ホスト)のOpenCVで統合Webカメラを使用できません

私はこれをテストするために使用されるコード:

import cv2 
    import numpy as np 
    import time 
    cam = cv2.VideoCapture(2) 
    if not cam.isOpened(): 
    print('Cannot open camera') 

    while True: 
    ret,frame = cam.read() 
    cv2.imshow('webcam', frame) 
    if cv2.waitKey(1)&0xFF == ord('q'): 
     break 

    cam.release() 
    cv2.destroyAllWindows() 

エラー:

Cannot open camera (feedback from script at if not cam.isOpened():).

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /io/opencv/modules/highgui/src/window.cpp, line 325

Traceback (most recent call last): File "Video_test.py", line 13, in cv2.imshow('webcam', frame) cv2.error: /io/opencv/modules/highgui/src/window.cpp:325: error: (-215) size.width>0 && size.height>0 in function imshow

任意の助けいただければ幸いです。ありがとう!

+1

@ Yashaswini Bhat。下の私の答えを参照してください。あなたの最初のバッチを獲得するためにSOツアーを完了してください;-) – ZF007

+0

あなたは 'VideoCapture(0)'または 'VideoCapture(1)' – user1767754

+0

@Mikeを試しましたか? YashaswiniはTracebackエラーを投げた。 ... *リンクの恒久的修正**には記載されていません。あなたはリンクを提供しました:-) – ZF007

答えて

0

cam.open()を使用して次のことを試してみてください。

import cv2 
import numpy as np 
import time 

cam = cv2.VideoCapture(2) # camera index (default = 0) (added based on Randyr's comment). 

print 'cam has image : %s' % cam.read()[0] # True = got image captured. 
              # False = no pics for you to shoot at. 

# Lets check start/open your cam! 
if cam.read() == False: 
    cam.open() 

if not cam.isOpened(): 
    print('Cannot open camera') 

while True: 
    ret,frame = cam.read() 
    cv2.imshow('webcam', frame) 
    if cv2.waitKey(1)&0xFF == ord('q'): 
     break 

cam.release() 
cv2.destroyAllWindows() 

あなたは今も2に設定されているcam = cv2.VideoCapture(value)値..と遊ぶことができます。範囲を試してください。 1-10。

+1

私はVideoCapture(0) 'をデフォルトのwebcamとしてみます。これは、利用可能な唯一のカメラ([docs](https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video)です。 html#videocapture-videocapture) "1台のカメラが接続されている場合は、単に0を渡します。") – Randyr

関連する問題