listDevices() without declaring an ofVideograbber variable first?

I have an application where I check for all available camera devices and initialise them. Currently I do this:

    ofVideoGrabber tvid;
    allCameras = tvid.listDevices();

    cout << endl << "Listing camera devices:" << endl;
    for(int i = 0; i < allCameras.size(); i++){
        cout << allCameras[i].id << ": " << allCameras[i].deviceName;
        if( allCameras[i].bAvailable ){
            cout << endl;
        }else{
            cout << " - unavailable " << endl;
        }
    }
    cout << "Total number of detected cameras: " << allCameras.size() << endl << endl;

    vid = vector<ofVideoGrabber>(allCameras.size());
    for (unsigned int i = 0; i < allCameras.size(); ++i){
        vid[i].setVerbose(true);
        vid[i].setDeviceID(allCameras[i].id);
        vid[i].setDesiredFrameRate(30);
        vid[i].initGrabber(camWidth,camHeight);
    }

It’s the first two lines that I find a bit ugly. Isn’t there a prettier alternative? I’m just diving back into C++, so it’s a bit rusty, but wouldn’t making listDevices() a static member function work? Like so:

allCameras = ofVideoGrabber::listDevices();
1 Like