Hi all,

I am new to C# and currently writing a program which attempts to capture video from two webcams at exactly the same time. I am using the EmguCv framework which is a wrapper class of the OpenCv framework used in C++. I have the program completed, with the stream from the left and right webcams displayed in their respective image box within the Windows form. Each frame is extracted and stored in a folder corresponding to the webcam which captured it. The capture is set to begin once the start button, added to the window, is pressed with the same button allowing the user to pause and resume the capture.

I am having a problem with the final, and most crucial, element of the program which is that when the program starts the cameras do capture images at the same time. I would welcome any advice available to aid me in this final step.

Below is the code behind my "Start" button which begins the capture.

Thanks in advance

LJ

private void btnStart_Click(object sender, EventArgs e)
        {
            #region if webcam1 is not created, create it now
            if (webcam1 == null && webcam2 == null)
            {
                try
                {
                    webcam1 = new Capture(0);
                    webcam2 = new Capture(1);
                }
                catch (NullReferenceException excep)
                {
                    MessageBox.Show(excep.Message);
                    FrameNo = 0;
                }
            }
            #endregion

            if (webcam1 != null & webcam2 != null)
            {
                if (captureInProgress)
                {
                    btnStart.Text = "Start";
                    Application.Idle -= ProcessFrame;
                }
                else 
                {
                    btnStart.Text = "Stop";
                    Application.Idle += ProcessFrame;
                }
                 captureInProgress = !captureInProgress;
            }
        }

You'll never get them at exactly the same time unless each frame from the camera comes with a timestamp, and even then it will depend on clock resolution.

How long does it take to capture a frame? Are you multi-threading the capture process? Is the system doing anything other than image capture? Are you sure?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.