Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
Private Sub Command1_Click()
Picture2.Picture = Picture1.Picture
End Sub
Private Sub Command2_Click()
STARTCAM
Picture1.Picture = LoadPicture("nosignal.bmp")
Picture2.Picture = LoadPicture("nosignal.bmp")
End Sub
Private Function Different(ByVal a As Long, ByVal b As Long) As Boolean
'Checks different of two colors
ar = a Mod 256: a = a \ 256
ag = a Mod 256: a = a \ 256
ab = a Mod 256: a = a \ 256
br = b Mod 256: b = b \ 256
bg = b Mod 256: b = b \ 256
bb = b Mod 256: b = b \ 256
sense = 255 - Slider1.Value * 5
Different = (Sqr((ar - br) * (ar - br) + (ag - bg) * (ag - bg) + (ab - bb) * (ab - bb)) > sense) 'formula for counting different
End Function
Private Sub Form_Unload(Cancel As Integer)
STOPCAM
SaveSetting "MotionDetect", "Param", "s1", Str(Slider1.Value)
SaveSetting "MotionDetect", "Param", "s2", Str(Slider2.Value)
End Sub
Private Sub Timer1_Timer()
'getting picture from camera
SendMessage mCapHwnd, GET_FRAME, 0, 0
SendMessage mCapHwnd, COPY, 0, 0
Picture1.Picture = Clipboard.GetData: Clipboard.Clear
stepp = 3 'Grid dense
Dim qan, qann As Long
qan = 0
qann = 0
For i = 1 To Picture1.Width / Screen.TwipsPerPixelX Step stepp
For j = 1 To Picture1.Height / Screen.TwipsPerPixelY Step stepp
If Different(Picture1.Point(i * stepp * Screen.TwipsPerPixelX, j * stepp * Screen.TwipsPerPixelY), Picture2.Point(Screen.TwipsPerPixelX * i * stepp, j * stepp * Screen.TwipsPerPixelY)) Then
Picture1.Circle (i * stepp * Screen.TwipsPerPixelX, Screen.TwipsPerPixelY * j * stepp), 1, RGB(255, 0, 0)
qann = qann + 1
End If
Next
Next
Label1.Caption = Int(qann * 100 / 910) & "%" 'Counting motion in pracentes
ProgressBar1.Value = Int(qann * 100 / 910)
End Sub
Sub STOPCAM()
DoEvents: SendMessage mCapHwnd, DISCONNECT, 0, 0
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Sub STARTCAM()
'Getting handle of camera window
mCapHwnd = capCreateCaptureWindow("WebcamCapture", 0, 0, 0, 320, 240, Me.hwnd, 0)
DoEvents
SendMessage mCapHwnd, CONNECT, 0, 0 'connecting to camera
SendMessage mCapHwnd, WM_CAP_DLG_VIDEOFORMAT, 0, 0 'Calling video format dialog
DoEvents
Slider1.Value = GetSetting("MotionDetect", "Param", "s1", "0")
Slider2.Value = GetSetting("MotionDetect", "Param", "s2", "0")
End Sub
Private Sub Timer2_Timer()
If ProgressBar1.Value > 100 - Slider2.Value * 2 Then
Beep
SavePicture Picture1.Picture, App.Path + "\Detected\" + Format(Date, "ddmmyyyy") + "__" + Format(Time, "hhmmss") + ".bmp"
List1.AddItem "Saved in " + Str(Time) + " " + Str(ProgressBar1.Value) + "% --> " + Format(Date, "ddmmyyyy") + "__" + Format(Time, "hhmmss") + ".bmp"
End If
End Sub