Reputation: 39
I would like to simultaneously record the video from two webcams. I am using the Aforge.Video.DirectShow package to capture each frame from the webcames. I started with the example shown on their website and just added a second camera.
But the problem I have is that only one of the event handler for handling new frames is fired. In the example code below it is _NewFrameHandler2.
I have the feeling that I am missing something obvious here...
public class Camera
{
private VideoCaptureDevice objCamera1;
private VideoCaptureDevice objCamera2;
public void Start()
{
FilterInfoCollection objVideoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
objCamera1 = new VideoCaptureDevice(objVideoDevices[0].MonikerString);
objCamera2 = new VideoCaptureDevice(objVideoDevices[1].MonikerString);
objCamera1.VideoResolution = objCamera1.VideoCapabilities[objCamera1.VideoCapabilities.Count() - 1];
objCamera2.VideoResolution = objCamera2.VideoCapabilities[objCamera2.VideoCapabilities.Count() - 1];
objCamera1.NewFrame += new NewFrameEventHandler(_NewFrameHandler1);
objCamera2.NewFrame += new NewFrameEventHandler(_NewFrameHandler2);
objCamera1.Start();
objCamera2.Start();
}
public void Stop()
{
objCamera1.Stop();
objCamera2.Stop();
}
private void _NewFrameHandler1(object sender, NewFrameEventArgs eventArgs)
{
Bitmap objFrame = (Bitmap)eventArgs.Frame;
Console.WriteLine("1");
}
private void _NewFrameHandler2(object sender, NewFrameEventArgs eventArgs)
{
Bitmap objFrame = (Bitmap)eventArgs.Frame;
Console.WriteLine("2");
}
}
Upvotes: 1
Views: 216
Reputation: 39
I think I have figured it out. I added a 500 ms delay in between calling the .Start() function on the camera objects.
System.Threading.Thread.Sleep(500);
Now it works.
Upvotes: 1