openframeworks / openframeworks/openFrameworks

listDevices() without declaring an ofVideograbber variable?

Open
#3,048 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

core development-strategy feature section-video
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

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? Why not make listDevices() a static member function?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the ofVideoGrabber::listDevices() declaration and its current usage in the example shown. Check how device enumeration is exposed across the project before deciding whether the API can be called without an instance. Done means providing a consistent, documented way to list devices or documenting why the current pattern is required.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.