|
-
Jun 26th, 2004, 06:01 PM
#1
Thread Starter
Hyperactive Member
Detect Movement, Cam [RESOLVED]
Hello,
I want to create a program that "looks" through my web cam and determines if there is any movement. If there is, I want it to do something.
I have the following code from PSCode.com:
http://www.pscode.com/vb/scripts/Sho...20041848591370
I don't know like anything that has to do with graphics : / so any help is greatly appreciated!
Thanks,
alacritous
Last edited by alacritous; Sep 22nd, 2004 at 08:56 PM.
-
Jun 26th, 2004, 08:02 PM
#2
The picture isn't missing
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 27th, 2004, 11:49 AM
#3
Thread Starter
Hyperactive Member
How would I make it so if there are any red boxes (motion) it does a sub or something?
-
Jun 27th, 2004, 12:31 PM
#4
The picture isn't missing
I have no idea. I didn't even download the code.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 27th, 2004, 01:44 PM
#5
Thread Starter
Hyperactive Member
Well, you just did.
(I think this is the right part)
BTW, preveri proženje motion-a is "preveri pro?enje motion it".
I couldn't translate it all because the translater is dumb...hehe
VB Code:
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
I tried to look and put little counter things but it won't work out!
Thanks,
alacritous
-
Jun 27th, 2004, 06:43 PM
#6
The picture isn't missing
Well it looks like that it draws the boxes here (I think you know this):
VB Code:
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
Therefore:
VB Code:
If Abs(mdSample(PixX, PixY, 0) - AverageSum) > mdTriger Then
'There is movement. Do something about it
'And since you just need to KNOW there is movement, you can do an exit sub:
Exit Sub
End If
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 28th, 2004, 09:08 AM
#7
Thread Starter
Hyperactive Member
Hello,
I can't believe I missed that. I've just been fooling around with it, finally got it to how I like it.
Thanks,
alacritous
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|