Opening multiple cameras using ofVideoGrabber

Hi,

I am trying to open multiple cameras, more than 3 cameras (hopefully up to 5 or 6) in one openframework app on Mac. I opened one camera which is a Face Time built-in camera on Mac and one more camera connecting a web cam to usb and connected one more camera by connecting a usb 3.0 hub to the usb port. So I connected 3 cameras in total so far. I would like to connect one more camera(or more than 2 cameras) through usb hub but it failed. How do I open more than two cameras from usb hub?

Thanks,

Can you tell us a little bit more about how it failed? Did it give you an error? What platform are you on? Are you opening specific cameras by querying listing your devices and passing a ofVideoDevice?

I have a problem aswell with using multiple webcams with an USB-hub.
communicating with the webcams does work if each is connected to a different USB-connection on the computer.

However, if I connect a (powered) USB-Hub with my computer and connect the two webcams to that USB-Hub I can see the two webcams with listDevices(), but one of the webcams (the second one I initialize) doesn’t get new frames when I call update(): .isFrameNew() only returns false for the second cam.

I tried it with two different hubs, both with the same result. I am on OS X 10.9.2 with an 2,4 ghz core2duo MacBook Pro (late 2008) and oF 0.8.1 with XCode 4.6.3.

any ideas on how to fix the problem and get multiple cams working with USB-Hubs.

for reference, my ofApp.c

    void ofApp::setup(){
    //we can now get back a list of devices.
    ofSetFrameRate(1);
    

    vector<ofVideoDevice> devices = grabber0.listDevices();
    
    for(int i = 0; i < devices.size(); i++){
        cout << devices[i].id << ": " << devices[i].deviceName;
        if( devices[i].bAvailable ){
            cout << endl;
        }else{
            cout << " - unavailable " << endl;
        }
    }
    imageCount = 0;
    // manually initialize all the cameras we have, so we can controll the position
    
    ofSoundStream  soundStream;
    
    grabber0.setDeviceID(0);
    grabber1.setDeviceID(1);

    grabber0.initGrabber(160,120, false);
    grabber1.initGrabber(160,120, false);
    cameras.push_back(grabber0);
    cameras.push_back(grabber1); 
}

//--------------------------------------------------------------
void ofApp::update(){
   
}
//--------------------------------------------------------------
void ofApp::draw(){
    index = -1;
    for(ofVideoGrabber g : cameras){
        index++;
        if(g.isFrameNew() == false){
            g.update();
            //if frame still is not new
            if(g.isFrameNew() == false){
                printf("cam %d has new frame: false\n", index);
            }
            return;
        } else {
            printf("cam %d has new frame: true\n", index);   
        }
    }
    
    // all cameras updated and have a new frame
    // grab the frames and save them to the filesystem
    
    index = -1;
    
    for(ofVideoGrabber g : cameras){
        index++;
        printf("current cam: %d\n", index);
        
        ofImage camImage;
        camImage.setUseTexture(false);
        camImage.setFromPixels(g.getPixels(), g.width, g.height, OF_IMAGE_COLOR);
        string path = "/Users/tom/Desktop/camtest/";
        path += ofToString(index) + "_" + ofToString(++imageCount) + ".jpg";
        camImage.saveImage(path);
        camImage.clear(); 
    }
}

This is very likely a hardware limitation. It may be a few things, sometimes when you initialise the cameras they draw more power than your hub can provide, make sure you are using a large power supply. It could well also be that the USB controller on your laptop is just not fast enough to run both the cameras, I am pretty sure the USB ports on each side of your laptop use a different bus.

Also some hubs are just not good quality. I was using a multi-camera USB based motion capture system. they recommended a specific model of dlink USB hub, with this hub and a 3A power supply I could run 6 of these special mocap cameras per hub, any other hub would fail -this is the hub we had to use.

The thing I did notice was that when I initialised these cameras on our motion capture system it would not init all the cameras at once, it would identify each one rapidly and then initialise them one at a time (maybe waiting for each one to be ready before moving on to the next).

1 Like