Metricam SDK: подключение двух веб-камер

Это мой первый пост в stackoverflow. Кто-нибудь когда-нибудь пробовал использовать DLL-библиотеки Metricam с www.metrilus.de?? Я хочу связать две веб-камеры в одной "Форме" как Metricam.Webcam() и использовать их только по одной за раз. Когда я пытаюсь в соответствии с их примером «MultiCam» как для камеры (0), так и для камеры (1), работает только моя первая камера. Вот код, который я прилагаю. Пожалуйста, дайте мне знать, если я делаю ошибку...

'#########################################################
'References added:  Metricam.dll    &   Webcam.dll
'#########################################################

Imports MetriCam

Public Class Form1

    Dim x As Integer = Nothing
    Dim cam As String() = WebCam.ScanForCameras
    Private camera As WebCam() = New WebCam(2) {}

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub BtnPhotoCapture_Click(sender As Object, e As EventArgs) Handles BtnPhotoCapture.Click

        Try
            If BtnPhotoCapture.Text = "Start Capture" Then
                ' Select camera.
                x = ComboBox1.SelectedIndex()
                If cam.Count > 0 Then
                    Try
                        camera(x) = New WebCam()                ' Instead of 'x', I have tried simply putting 0 and 1.
                        camera(x).Connect()
                        BtnPhotoCapture.Text = "Grab"
                        BackgroundWorker.RunWorkerAsync()

                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                Else
                    BackgroundWorker.CancelAsync()
                    MessageBox.Show("No camera detected.")
                End If
                Exit Sub

            Else
                Try
                    'Stop camera updating.
                    BackgroundWorker.CancelAsync()

                    ' Get the source bitmap.
                    Dim bm_source As New Bitmap(camera(x).GetBitmap())

                    ' Calculate scale factor to make source bitmap height 200 pixel.
                    Dim BitmapHeight As Integer = bm_source.Height
                    Dim scale_factor As Integer = 1

                    ' Make a bitmap for the result.
                    Dim bm_dest As New Bitmap(CInt(bm_source.Width * scale_factor), CInt(bm_source.Height * scale_factor))

                    ' Make a Graphics object for the result Bitmap.
                    Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)

                    ' Copy the source image into the destination bitmap.
                    gr_dest.DrawImage(bm_source, 0, 0, bm_dest.Width + 1, bm_dest.Height + 1)

                    ' Display the result.
                    PictureBox1.Image = bm_dest
                    BtnPhotoCapture.Text = "Start Capture"

                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub BackgroundWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker.DoWork

        Try
            While Not BackgroundWorker.CancellationPending
                ' Camera updates for streaming.
                camera(x).Update()

                ' Get the source bitmap.
                Dim bm_source As New Bitmap(camera(x).GetBitmap())

                ' Calculate scale factor to make source bitmap height 200 pixel.
                Dim BitmapHeight As Integer = bm_source.Height
                Dim scale_factor As Integer = 1

                ' Make a bitmap for the result.
                Dim bm_dest As New Bitmap(CInt(bm_source.Width * scale_factor), CInt(bm_source.Height * scale_factor))

                ' Make a Graphics object for the result Bitmap.
                Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)

                ' Copy the source image into the destination bitmap.
                gr_dest.DrawImage(bm_source, 0, 0, bm_dest.Width + 1, bm_dest.Height + 1)

                ' Display the result.
                PictureBox1.Image = bm_dest
            End While

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub BackgroundWorker_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker.RunWorkerCompleted

        Try
            'Disconnecting camera.
            camera(x).Disconnect()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub BtnScanCameras_Click(sender As Object, e As EventArgs) Handles BtnScanCameras.Click
        'Add detected cameras to combo box.
        For i = 0 To cam.Count - 1
            ComboBox1.Items.Add("Camera " & i & " : [" & cam(i) & "]")
        Next
        ComboBox1.SelectedIndex = 0
        BtnScanCameras.Enabled = False
    End Sub

End Class

person Debarjun Roy    schedule 11.08.2015    source источник


Ответы (1)


Попробуйте использовать этот код (в этой демонстрации я предполагаю, что хочу использовать «последнюю» камеру в списке доступных камер...):

camera = new WebCam();
string[] mycams = WebCam.ScanForCameras();            
int indice = mycams.Length - 1;
((WebCam)camera).SetSerialNumberToConnect(mycams[indice]);
camera.Connect();
person carlornd    schedule 04.04.2016