This project has moved. For the latest updates, please go here.

Using Aforge Sample

Nov 29, 2014 at 3:06 AM
Hello Everybody,

i tried to use the example code from the AForge sample to read QR Codes over my webcam. Generally it works fine, it reads QR codes when i place them in front of the cameras. The Problem i have is the preview picturbox. It is getting very big (bigger as my form), i can only see the top left edge of the video stream. When i run the compiled AForge sample i dont have this problem. I used the same code as on the home page, i just converted it from C# into vb.net. I could insert the converted code into my existing project without serious problems. the only problem was the type var which is not available in vb.net.

Has anybody an idea what i could do to solve this problem?
Coordinator
Dec 20, 2014 at 7:11 PM
Can you provide your sample code so that I can take a look at it?
Dec 22, 2014 at 1:58 AM
following code i use for controlling the camera, i think i need to set the resolution of the cameras somewhere, i run the program on two different devices and get different results in size of the picture box. on my surface 3 the picture box gets very big and on a low cost windows 8 tablet the picture size is ok.
Private Sub LoadDevicesToCombobox()
        cmbDevice.Items.Clear()
        For index = 0 To camDevices.Devices.Count - 1
            cmbDevice.Items.Add(New Device() With {.Index = index, .Name = camDevices.Devices(index).Name})
        Next
    End Sub
Private Sub Current_NewFrame(sender As Object, eventArgs As NewFrameEventArgs)
        If IsDisposed Then
            Return
        End If

        Try
            If currentBitmapForDecoding Is Nothing Then
                currentBitmapForDecoding = DirectCast(eventArgs.Frame.Clone(), Bitmap)
            End If
            Invoke(New Action(Of Bitmap)(AddressOf ShowFrame), eventArgs.Frame.Clone())
            ' not sure, why....
        Catch generatedExceptionName As ObjectDisposedException
        End Try
    End Sub

 Private Sub ShowFrame(frame As Bitmap)
        If PictureBox1.Width < frame.Width Then
            PictureBox1.Width = frame.Width
        End If
        If PictureBox1.Height < frame.Height Then
            PictureBox1.Height = frame.Height
        End If
        PictureBox1.Image = frame
    End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs)
        If currentResult Is Nothing Then
            Return
        End If

        If currentResult.ResultPoints IsNot Nothing AndAlso currentResult.ResultPoints.Length > 0 Then
            Dim resultPoints = currentResult.ResultPoints
            Dim rect = New Rectangle(CInt(resultPoints(0).X), CInt(resultPoints(0).Y), 1, 1)
            For Each point In resultPoints
                If point.X < rect.Left Then
                    rect = New Rectangle(CInt(point.X), rect.Y, rect.Width + rect.X - CInt(point.X), rect.Height)
                End If
                If point.X > rect.Right Then
                    rect = New Rectangle(rect.X, rect.Y, rect.Width + CInt(point.X) - rect.X, rect.Height)
                End If
                If point.Y < rect.Top Then
                    rect = New Rectangle(rect.X, CInt(point.Y), rect.Width, rect.Height + rect.Y - CInt(point.Y))
                End If
                If point.Y > rect.Bottom Then
                    rect = New Rectangle(rect.X, rect.Y, rect.Width, rect.Height + CInt(point.Y) - rect.Y)
                End If
            Next
            Using g = PictureBox1.CreateGraphics()
                g.DrawRectangle(resultRectPen, rect)
            End Using
        End If
    End Sub
Private Sub cmbDevice_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles cmbDevice.SelectedIndexChanged
        If camDevices.Current IsNot Nothing Then
            RemoveHandler camDevices.Current.NewFrame, AddressOf Current_NewFrame
            If camDevices.Current.IsRunning Then
                camDevices.Current.SignalToStop()
            End If
        End If

        camDevices.SelectCamera(CType(cmbDevice.SelectedItem, Device).Index)
        AddHandler camDevices.Current.NewFrame, AddressOf Current_NewFrame
        camDevices.Current.Start()
    End Sub
Coordinator
Jan 14, 2015 at 8:00 PM
I don't see any error in your code.
But generally the code doesn't do any scaling of the video frames. So I think different behavior is caused by the resolutions of the different cameras.