changing the camera input while the app is running

Hello, i need to be able to change the camera input (select which connected camera i want to use ) while my app is working.
For this I been using videoIn.setDeviceID(0); but the problem is that this command only works in setup(), so i just select which camera i want to use just one time when i start my program.

I been trying to use videoIn.setDeviceID(0); withing the draw() function so i would be able to change it dynamically but it doesnt work, i get this message:

OF: OF_LOG_WARNING: call setDeviceID before grabber is started!

Do anybody have an idea why is this and how to make it work?

thanks

my draw function that is suppose to change between cameras look like this:

  
  
  
void testApp::draw(){  
      
   if(box1 == 0) {  
        videoIn.setDeviceID(2);  
  
          
    }  
      
    if(box1 == 1) {  
        videoIn.setDeviceID(1);  
   
          
    }  
      
    if(box1 == 2) {  
        videoIn.setDeviceID(2);  
  
          
    }  
  
}  
  
  

Yes you need to close the grabber first, set the device then do the setup.

http://www.openframeworks.cc/documentation?detail=ofVideoGrabber#ofVideoGrabber-close

Like this…

  
  
void testApp::changeCamera(int num){  
   videoIn.close();  
   videoIn.setDeviceID(num);  
   videoIn.initGrabber(320,240); // change this to your settings  
}  
  

Why are you trying to do it within the draw function? That should be for drawing only. You don’t want to be trying to open and close the camera capture in a loop like update/draw, just call changeCamera(2) either on key up or if a button is clicked etc.

Thanks Chris that works.im calling the function with keys up. Just a few questions. Each time i change the camera i get this message:


OF: OF_LOG_WARNING: No camera settings to load

why is that? should i ignore this?

and my second question is related to your question (why do it withing the draw function):

Instead of doing with keys i need to create a combobox gui element and then i need to be able to select with camera i need with that.

  
  
    string titleArray[] = {"one ", "two", "three", "four"};  
    gui.addComboBox("camera ", box1, 4,  titleArray);  
  

thats why i been trying to do it in draw:

  
  
void testApp::draw(){    
        
   if(box1 == 0) {    
    setDevice(1);  
   
    }    
        
    if(box1 == 1) {    
       setDevice(2);  
  }    
        
    if(box1 == 2) {    
        setDevice(3);  
    }    
  
  

i was wondering if there any mechanism for calling a function just one time? so it doesnt set the device all the time . how can i solve this?

thanks

I’ve never used a combobox but it should have a listener so it reacts to user actions ?

My second impulse would be to create one more variable named oldBox and store inside it the new deviceid then in your if statement use

  
 if ( oldBox!=box1 && box1 == 0) { oldBox = box1; setDevice(box1);}  

that way your code will be executed only when you change selection in combobox

Hi All !

This thread is quite ooold, but I’m facing a similar issue right now.

I’ve made some minor changes to ofVideoGrabber example, so that with a key I “close” the videograbber.

else if(key=='x')
{
    vidGrabber.close();
}

and then with 2 other keys I can init another grabber :

else if (key=='1')
{
    vidGrabber.setDeviceID(0);
    vidGrabber.initGrabber(camWidth, camHeight);
}
else if(key == '2')
{
    vidGrabber.setDeviceID(1);
    vidGrabber.initGrabber(camWidth, camHeight);
}

The results is that in OSX, the new grabber initialized after closing the first one it’s always called with deviceID = 0 . I’ve been debugging and seems like

void ofAVFoundationGrabber::setDeviceID(int deviceID)
 {
	[grabber setDevice:deviceID];
	device = deviceID;
}

Initially (the first time) it is called with the object “grabber” being an OSXVideoGrabber *. But once you hit ‘x’ and you close the initial grabber, when you try to init the grabber again and you reach this line of code grabber is “nil” !!

So the call [grabber setDevice:deviceID]; Has no effect and basically you can’t connect to another grabber that has a different deviceID …

What am I understanding or doing wrong ?
As far as OF documentation always talks about:

   vidGrabber.close();  
   vidGrabber.setDeviceID(num);  
   vidGrabber.initGrabber(w,h);

I think I’ve fixed the issue with this pull request : github.com/openframeworks/openFrameworks/pull/6082