Sub GetMotion()
Dim ColorSumStr As String 'sum of pixel color
Dim ColorRedStr As String 'red
Dim ColorGreenStr As String 'green
Dim ColorBlueStr As String 'blue
Dim ColorRedDec As Single 'red
Dim ColorGreenDec As Single 'green
Dim ColorBlueDec As Single 'blue
Dim PixX As Single 'curent pixel X
Dim PixY As Single 'curent pixel Y
Dim AveragePixel(5) As Single 'Average color from 6 pixels
Static Counter As Single 'counter
Dim AverageSum As Single 'Average sum of all colors
Dim BoxesX As Single 'how many 'detection boxes - x axis
Dim BoxesY As Single 'how many 'detection boxes - y axis
Dim AveragePixelLoop As Single 'defines how many frames does this sub compare
BoxesX = 16 'from 1 to 50
BoxesY = 16 'from 1 to 50
AveragePixelLoop = 30 'from 1 to 250
Dim Repeat As Single
Dim Px As Single, Py As Single
For Px = 0 To (MotionPic.Width) Step Int(MotionPic.Width / BoxesX)
For Py = 0 To (MotionPic.Height) Step Int(MotionPic.Height / BoxesY)
PixX = Fix(Px / (MotionPic.Width / BoxesX))
PixY = Fix(Py / (MotionPic.Height / BoxesY))
For Repeat = 0 To 5
ColorSumStr = Right$("000000" + Hex(GetPixel(MotionPic.hdc, Px + Repeat, Py + Repeat)), 6)
ColorRedStr = Mid$(ColorSumStr, 5, 2)
ColorGreenStr = Mid$(ColorSumStr, 3, 2)
ColorBlueStr = Mid$(ColorSumStr, 1, 2)
ColorRedDec = Val("&H" + ColorRedStr)
ColorGreenDec = Val("&H" + ColorGreenStr)
ColorBlueDec = Val("&H" + ColorBlueStr)
AveragePixel(Repeat) = ColorRedDec + ColorGreenDec + ColorBlueDec
Next
Counter = Counter + 1
If Counter = AveragePixelLoop Then Counter = 1
mdSample(PixX, PixY, 0) = 0
mdSample(PixX, PixY, Counter) = 0
For Repeat = 0 To 5
mdSample(PixX, PixY, 0) = mdSample(PixX, PixY, 0) + AveragePixel(Repeat)
mdSample(PixX, PixY, Counter) = mdSample(PixX, PixY, 0) + AveragePixel(Repeat)
Next
AverageSum = 0
For Repeat = 1 To AveragePixelLoop
AverageSum = AverageSum + mdSample(PixX, PixY, Repeat)
Next
AverageSum = AverageSum / AveragePixelLoop
'preveri proženje motion-a
If Abs(mdSample(PixX, PixY, 0) - AverageSum) > mdTriger Then
MotionPic.Line (Px - 4, Py - 4)-Step((MotionPic.Width / BoxesX) - 4, (MotionPic.Height / BoxesY) - 4), , B
End If
Next
Next
End Sub