Mac iSight cam and initGrabber()'s arbitrary behaviour with multiple cameras

Hi

I’m trying to setup a multi-cam app on a Mac. For now, I have two cameras: the built-in iSight; and a Logitech HD C525 USB cam. I’ve been struggling for both cameras to draw simultaneously. I just couldn’t get both to draw at the same time. Until I realized that it depended on the parameters passed on to ofVideoGrabber’s initGrabber(...).

I’ve tried different settings with these results:

cam->initGrabber(320, 240); // both cameras draw OK      
cam->initGrabber(321, 241); // just one camera will draw        
cam->initGrabber(319, 239); // both cameras draw OK  
cam->initGrabber(320, 480); // both cameras draw [obviously] distorted   
cam->initGrabber(640, 240); // both cameras draw [obviously] distorted
cam->initGrabber(640, 480); // just one camera will draw
cam->initGrabber(1024, 480); // just one camera will draw
cam->initGrabber(ofGetWidth(), ofGetHeight()); // just one camera will draw

Here’s the [simplified] code.

ofApp.h

class ofApp : public ofBaseApp{
   // ...
    vector<shared_ptr<ofVideoGrabber> > cams;
}

ofApp.cpp

void ofApp::setup() {

    ofVideoGrabber vidGrabber;
    vector<ofVideoDevice> devices = vidGrabber.listDevices();
    
    for(int i = 0; i < devices.size(); i++) {
        shared_ptr<ofVideoGrabber> cam(new ofVideoGrabber());
        cam->setDeviceID(i);
        cam->initGrabber(ofGetWidth(), ofGetHeight()); // or whatever
        cams.push_back(cam);
    }
}

//--------------------------------------------------------------
void ofApp::update(){
    for (int i=0; i < cams.size(); i++) {
        cams[i]->update();
    }
}

//--------------------------------------------------------------
void ofApp::draw(){
    for (int i=0; i < cams.size(); i++) {
        cams[i]->draw(320*i, 0);
    }
}

Any ideas on what is going on? I don’t like the idea of hard-coding camera sizes, and even if there wasn’t any other solution, 320x240 is way too small for what I’m willing to accomplish.

EDIT:
I made some more experiments.

If I set one cam to 320x240 and the other one to something else, they both work.

If I add a third camera (another Logitech HD C525), I can see two of them, even if they are the same size (other than 320x240). The camera not showing is always the last one to be initialized with initGrabber().

If I ignore the Bult-in iSight, by skipping it’s initialization, then the other two cameras work.

Is this an issue with Mac’s hardware?

I would check the native resolution of all the cameras involved, they will all be different, and hence need to be initialised with different resolutions. If you had cameras that are the same, then I think you can avoid hardcoding resolutions, or at least use an XML to load a single prefered resoltuions. Using ofGetWidth() to initialise cameras seems a bit off, as it is going to based on your window/screen size wich can change and has no relationship to the cameras capabilities. I check each camera and find the resolution and frame rates that work for you and the camera and initialise them with that. I am not sure what computer you are using, but for me the built in mac webcam can do 1280720 as native at 30fps. The logitech camera is a little different, the specs page is here, http://support.logitech.com/en_us/product/hd-webcam-c525/specs but there is a telling note on this line:
Frame Rate (max) 30fps@640x480
I would try the two logitechs at 640
480 and the isight at 1280*720.

Thanks @fresla.

I tried doing what you suggested, but still get the same results. Setting iSight to 320x240 seems to be the only way to make them all work. I can set both Logitech’s cams up to 1280x720 and iSight to 320x240 and it works. Anything greater than that for iSight, and I loose the last cam to be initialized.

What is the actual resolution of your iSight camera? You may have reached the limit of your USB bandwidth.

What do you mean by “actual resolution”?

If I had reached the limit of USB bandwidth, why can I see 2 HD cams at 720p + the iSight at 320x240, and not both iSight + one USB at 640x480 ?

How can I check the USB bandwidth usage in OSX? Have googled a bit and found nothing. I can see the specs but not the actual usage

I just meant what resolution is the insights native res? What is the actual sensor running at natively in video mode, on my 2014 MacBook Pro it is 1280*720

I can’t seem to find this information, but recording at highest resolution with QT I get 640x480. My guess is that’s the native resolution. This is on a 2010 Macbook Pro