Search code examples
winformsc#-4.0emgucv

Switching between multiple Cameras using Emgu CV


I have a quick question: I need to switch between the two camera on a tablet. Front and Back. By default, the Front camera is always used by Emgu CV.

Thanks.


Solution

  • Ok. There is a different constructor. I was building upon the 7 line demo for Emgu CV.

    Using the correct overloaded constructor, this is what did the trick for me:

        private Capture _capture;
    
        private void InitCapture(Int32 _camIndex) {         
            try {
                if (_capture != null) {
                    Application.Idle -= ProcessFrame;               
                }
    
                _capture = new Capture(_camIndex);
                Application.Idle += ProcessFrame;
            }
            catch (NullReferenceException excpt) {
                XtraMessageBox.Show(excpt.Message);
            }
        }
    
        private void ProcessFrame(object sender, EventArgs arg) {
            Image<Bgr, Byte> frame = _capture.QueryFrame();
            ImageBoxCapture.Image = frame;
        }
    
        private void CharmsBarBase_ButtonTop01Click(object sender, EventArgs e) {
            InitCapture(0);
        }
    
        private void CharmsBarBase_ButtonTop02Click(object sender, EventArgs e) {
            InitCapture(1);
        }
    

    Regards.