I've coded a project to use a webcam for motion tracking (like many others). I use avicap32.dll and receive images happily at 640x480 i then grab a frame for reference then grab another frame and difference them to produce a black and white picturebox (picture4) I then use this picture to create the image for another picturebox (picture5) but this one draws rectangles over any 5x5 white areas. Or at least that is what is supposed to happen. I just cannot draw the rectangles for some reason even though I'm doing as thousand of pages say. Below is the routine in question all others work happily but for some reason this one does not.
Any ideas?
Any ideas?
VB.NET:
Private Sub Detection(ByVal old As PictureBox, ByVal knew As PictureBox)
Dim pic As New Bitmap(old.Image)
Dim i As Integer
Dim bgr As Color
Dim p As New Pen(Color.Red, 1)
Dim d As Graphics
d = knew.CreateGraphics
'knew.Refresh()
d.DrawImage(pic, 0, 0, knew.Width, knew.Height)
' Detect blob size
For xcnt = 0 To old.Image.Width - 1
For ycnt = 0 To old.Image.Height - 1
bgr = pic.GetPixel(xcnt, ycnt)
i = 0
If bgr = Color.White Then
For a = -2 To 2
For b = -2 To 2
If pic.GetPixel(xcnt + a, ycnt + b) = Color.White Then
area(i) = "true"
i += 1
End If
Next
Next
If area(0) = area(1) = area(2) = area(3) = area(4) = area(5) _
= area(6) = area(7) = area(8) = area(9) = area(10) _
= area(11) = area(12) = area(13) = area(14) = area(15) _
= area(16) = area(17) = area(18) = area(19) = area(20) _
= area(21) = area(22) = area(23) = area(24) = area(25) Then
d.DrawRectangle(p, xcnt - 2, ycnt - 2, 5, ycnt + 2)
End If
ReDim area(25)
End If
Next
Next
End Sub