I am using EmguCV to get images from different webcams but my program fails only when I use two identical cameras. I have 4 cameras in total: a webcam built-in in the PC, an external webcam, and two USB microscopes which are identical.
In the code I create two video captures to grab images from two different sources and display them in two picture boxes. It works fine with every combination of cameras, except when I use the two microscopes, which are same brand and model.
In index0 and index1 I introduce the index value of the camera I want to connect: (0) internal webcam, (1) external webcam, (2) USB microscope and (3) USB microscope. When I use the combination of the two microscopes (2-3 or 3-2), whichever of both I assign to cap1 won't display the image. cap1.QueryFrame returns an empty frame. The error message I get when try to display the image in pbCam1 is:
Code: Select all
Dim index0 As Integer = 0 'Select camera to display in picturebox 1 Dim index1 As Integer = 1 'Select camera to display in picturebox 2 Dim cap0 As New VideoCapture(index0) Dim cap1 As New VideoCapture(index1) Private Sub btnSelect_Click(sender As Object, e As EventArgs) Handles btnSelect.Click Timer1.Start() 'Start timer End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 'For each tick of the timer display camera capture into imageBox Dim frame As Mat = cap0.QueryFrame() Dim frame1 As Mat = cap1.QueryFrame() pbCam0.Image = frame.Bitmap pbCam1.Image = frame1.Bitmap End Sub
If anyone got a similar problem or knows the reason why this happens I will appreciate any help!
Code: Select all
System.NullReferenceException: 'Object reference not set to an instance of an object.'