问题
I can get AForge to work with an USB web cam, but I have a video card that can connect to multiple cameras. How do I get AForge to work with the video card?
My issue is I could not get the VideoInputDevice
to set to a working video input.
The code is like this:
void init(){
FilterInfoCollection videoCaptureDevice =
new FilterInfoCollection(FilterCategory.VideoInputDevice);
VideoCaptureDevice finalVideo =
new VideoCaptureDevice(videoCaptureDevice[0].MonikerString);
finalVideo.NewFrame += new NewFrameEventHandler(finalVideo_NewFrame);
finalVideo.Start();
}
public void finalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap temp = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = temp;
}
I also tried:
finalVideo = new VideoCaptureDevice();
finalVideo.CrossbarVideoInput = VideoInput.Default;
and it did not work either.
Any help is highly appreciated.
回答1:
in your code
VideoCaptureDevice finalVideo = new VideoCaptureDevice(videoCaptureDevice[0].MonikerString);
registers the first device [0]
i asume if you would put in [1] there you get the second device.
also note this line
finalVideo.NewFrame += new NewFrameEventHandler(finalVideo_NewFrame);
there you define what event name (finalvide_Newframe) should trigger when there is a new image frame received for that specific camera. Most simple would be to register two different events. So each camera [0] and [1] receives its own event to display it.
here some additional code hints that might be helpfull for you its what i use to select a camera, its just an idea for if you have multiple external camera's (make 2 combo boxes) but dont want to use for example a laptops internal cam.
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
{
comboBox1.Items.Add(VideoCaptureDevice.Name);
} // to get all your devices inside a combo box;
with that you could do
FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
回答2:
look in the aforge examples when you download the whole package, there is a demo snapshotmaker, that works with multiple camera's.
来源:https://stackoverflow.com/questions/13297577/aforge-working-with-video-card-with-multiple-cameras