A Beginner needs help

Aug 8, 2009 at 11:39 AM

Hello @all,

at first excuse my bad english :-)

I tried the touchless SDK and have some problems.

I got the picture from my webcam and want to set a marker and that the touchless recognizes the "marker". So I used the addmarker function. But everything I tried, it doen´t work well. My marked area in the picture will not be recognized. Sometimes it recognizes the whole picture (not my marker) and I see the rectangle. What I´m doing wrong?

 

Below is my code:


Public Class Form1
    Dim Touchless1 As New TouchlessLib.TouchlessMgr
    Dim player As String = "Player1"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetStyle(ControlStyles.UserPaint, True)
        SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        SetStyle(ControlStyles.DoubleBuffer, True)
        Me.UpdateStyles()
        If Touchless1.Cameras.Count = 0 Then MessageBox.Show("This application needs a webcam") : Return
        Touchless1.CurrentCamera = Touchless1.Cameras.First
        AddHandler Touchless1.CurrentCamera.OnImageCaptured, AddressOf Form1_Capture
        Touchless1.CurrentCamera.ShowPropertiesDialog(Me.Handle)
    End Sub

    Private Sub Form1_Capture()
        'Me.BeginInvoke(New EventHandler(AddressOf Me.Invalidate))
        Invalidate()
    End Sub

    Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        Dim g As Graphics = CreateGraphics()
        Dim p As New Pen(Color.Red)
        Dim Mouseposition As New Point
        Mouseposition.X = e.X - 20
        Mouseposition.Y = e.Y - 20
        g.DrawEllipse(p, Mouseposition.X, Mouseposition.Y, 40, 40)

        Touchless1.AddMarker(player, Touchless1.CurrentCamera.GetCurrentImage, Mouseposition, 40)
        MessageBox.Show(Touchless1.Markers.ToString)
        Touchless1.Markers(0).Highlight = True
        Touchless1.Markers(0).Threshold = 4
    End Sub

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim b = Touchless1.CurrentCamera.GetCurrentImage
        If b IsNot Nothing Then e.Graphics.DrawImage(b, 0, 0, Width, Height)
    End Sub


End Class