![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/5adc2a74-c164-48c7-8c9c-51bcbdaf1b0d?x-oss-process=image/resize,p_100/auto-orient,1/quality,q_90/format,jpg/watermark,image_eXVuY2VzaGk=,t_100,g_se,x_0,y_0)
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/7f470bdb-7e50-4bca-b8fc-b0aae2c6c3df?x-oss-process=image/resize,p_100/auto-orient,1/quality,q_90/format,jpg/watermark,image_eXVuY2VzaGk=,t_100,g_se,x_0,y_0)
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/eb0235c6-fc6f-41c1-b5b1-47ac4b0d316a?x-oss-process=image/resize,p_100/auto-orient,1/quality,q_90/format,jpg/watermark,image_eXVuY2VzaGk=,t_100,g_se,x_0,y_0)
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/e01b36a6-9724-4afa-82b5-624ac0b94f0e?x-oss-process=image/resize,p_100/auto-orient,1/quality,q_90/format,jpg/watermark,image_eXVuY2VzaGk=,t_100,g_se,x_0,y_0)
Private CAM As New DSAPI. Camera_avicap32
Private Clr As Color = Color.FromArgb (230, 50, 50)
Private _Location As Point
Private Sub Form1_FormClosing (sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
End
End Sub
Private Sub Form1_Load (sender As Object, e As EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False
CAM. Start video preview on the specified control (Label1)
MSK.Show ()
MSK.Owner = Me
Dim T As New Threading.Thread (AddressOf DoThd)
T.Start ()
End Sub
Private Sub DoThd ()
While True
Using B As New DSAPI. Graphic image. Image recognition (CAM. Capture image)
Dim Rct As Rectangle = B. Get the maximum contained area of the specified color (Clr, 0.2)
Rct = Label1.RectangleToScreen (Rct)
_Location = Rct.Location + New Point (Rct.Width / 2, Rct.Height / 2)
Me.Invoke (New CrossAppDomainDelegate (AddressOf SetMove))
'MSK.Location = New Point (Rct.X + Rct.Width / 2, Rct.Y + Rct.Height / 2)
'Me.Text = Rct.Location.ToString
End Using
Threading.Thread.SpinWait (100)
Application.DoEvents ()
End While
End Sub
Private Sub SetMove ()
MSK.Location = _Location-New Point (MSK.Width / 2, MSK.Height / 2)
End Sub