Python OpenCV stereo cam blind one?
Question: My system is Linux HPDebian 3.2.0-2-amd64 #1 SMP x86_64 GNU/Linux Python 2.7,
OpenCV2 I can use only 1 cam. My question is How to get a video feed from 2
cams ? I had read c++ version but I prefer python. It is easier for non-
programmer.

I don't understand why my webcam works only Wleft, but WRight is blank-gray
windows And at the command line

VIDIOC_QBUF: Invalid argument

continue to flood my command line.

OpenCV-Python has a ready-made package of stereo program, but I need to access
the elements of each cam because I want to test my algorithm.

URLs, Book. Any help would be appreciated. Student

My attempt:

    
    
    '''
    Simple Stereo feed
    '''
    import cv
    cv.NamedWindow("wLeft", cv.CV_WINDOW_AUTOSIZE)
    cv.NamedWindow("wRight", cv.CV_WINDOW_AUTOSIZE)
    captureL = cv.CaptureFromCAM(0)
    captureR = cv.CaptureFromCAM(1)
    
    def repeat():
        frameL = cv.QueryFrame(captureL)
        cv.ShowImage("wLeft", frameL)
        frameR = cv.QueryFrame(captureR)
        cv.ShowImage("wRight", frameR)
    
    while True:
        repeat()
        if cv.WaitKey(33)==27:
           break
    
    cv.DestroyAllWindows()
    

===============================================  
**Update 1**  
Answer to your questions

  1. In current OpenCV-Python. I can not find any command, but I when I comment out the Leftcam, Rightcam works. And vice versa.
  2. Yes, I just found it!. I redirected command and carefully searched.   
**libv4l2: error turning on stream: No space left on device**  

  3. They are identical. OKER193.
  4. I can use it just only 1 cam Left or Right only. Can not get a video feed from two of them simulataneously.
  5. I have no hubs. I don't know it is a real port or not, but I connect it left and right of my notebook.   
http://opencv-users.1802565.n2.nabble.com/Multiple-Camera-Read-Error-
td7001563.html  

I tried cv.ReleaseCapture()

    
    
    def repeat():
            frameL = cv.QueryFrame(captureL)
            cv.ShowImage("wLeft", frameL)
            cv.ReleaseCapture(captureL)
            frameR = cv.QueryFrame(captureR)
            cv.ShowImage("wRight", frameR)
            cv.ReleaseCapture(captureR)
    

I got the errors:

    
    
    ...
    VIDIOC_QUERYMENU: Invalid argument //Many lines
    ...
    Traceback (most recent call last):
      File "55.py", line 19, in <module>
        repeat()
      File "55.py", line 13, in repeat
        cv.ReleaseCapture(captureL)
    AttributeError: 'module' object has no attribute 'ReleaseCapture'
    

I really wonder  
<http://opencv.willowgarage.com/documentation/python/highgui_reading_and_writing_images_and_video.html?highlight=releasecapture>  
CaptureFromCAM last line say To release the structure, use ReleaseCapture.
This function may be dropped out.

Wandering around and found this  
<http://superuser.com/questions/431759/using-multiple-usb-webcams-in-linux>  

Then I check my resolution per cam is 640x480 as a normal. And my webcam is
1.1/2.0 USB interface.

    
    
    root@HPDebian:~# v4l2-ctl -d /dev/video0 --list-formats
    ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'YUYV'
        Name        : YUV 4:2:2 (YUYV)
    

Then check another cam

    
    
    root@HPDebian:~# v4l2-ctl -d /dev/video1 --list-formats
    ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'YUYV'
        Name        : YUV 4:2:2 (YUYV)
    

At this point I am not sure about my USB notebook. It may be a hub inside. I
will try reduce the resolution and post my result again.

========================================================================  
**Update 2**  
Try time.sleep(1) from Martin.  

    
    
    VIDIOC_QUERYMENU: Invalid argument //Many lines
    libv4l2: error setting pixformat: Device or resource busy
    HIGHGUI ERROR: libv4l unable to ioctl S_FMT
    libv4l2: error setting pixformat: Device or resource busy
    libv4l1: error setting pixformat: Device or resource busy
    HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT
    
    libv4l2: error turning on stream: No space left on device
    VIDIOC_STREAMON: No space left on device
    VIDIOC_QBUF: Invalid argument  //Many lines until Ctrl C
    

I will try this again in M$ xp.

===============================================  

**Update 3**

Still using Linux. M$ xp is busy. This time I del the c1 and c2. Since I don't
know how to release camera. I believe that API of driver I use is allow only 1
device access kernel per time. So I try this one.

    
    
    def repeat1():
        c1 = cv.CreateCameraCapture(0)
        i1 = cv.QueryFrame(c1)
        cv.ShowImage("WebCAM1", i1)
        del(c1)
    def repeat2():
        c2 = cv.CreateCameraCapture(1)
        i2 = cv.QueryFrame(c2)
        cv.ShowImage("WebCAM2", i2)    
        del(c2)
    

  
Program run very sluggish and WebCAM1 is distorted, WebCAM2 is not.


Answer: Some things to check:

  1. Is OpenCV picking up all your cameras? Try [checking how many cameras are attached](http://stackoverflow.com/questions/7322939/how-to-count-cameras-in-opencv-2-3).
  2. Do you get any error other error messages? i.e. is there a stack track with the one you've mentioned?
  3. Are there any hardware differences between the two cameras?
  4. What happens if you comment out all the stuff about lcam? i.e. is it just something to do with the second camera or is it something to do with running two cameras at once.
  5. Try plugging them into seperate hubs as per [this suggestion](http://forum.openframeworks.cc/index.php?PHPSESSID=m5l5gsjssc5pv0jimj4nbsvst2&/topic,8179.0.html)

