Problem using multiple identical cameras

General Discussion
Post Reply
DanielMelia
Posts: 1
Joined: Thu Dec 05, 2019 9:29 am

Problem using multiple identical cameras

Post by DanielMelia » Thu Dec 05, 2019 9:33 am

Hello,

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.

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
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

System.NullReferenceException: 'Object reference not set to an instance of an object.'
If anyone got a similar problem or knows the reason why this happens I will appreciate any help!

Many thanks

Post Reply