Sign in to follow this  
Followers 0
mary

webcam motion detection

23 posts in this topic

here is a link: http://www.imagemagick.org/script/compare.php

there are also COM and dll library to compare 2 jpg.

The idea is: you take 2 jpg from your webcam and compare them with imagemagick. If the difference is more than $tolerance value ==> there is motion

sorry i have no code to help you but i'll do so if i succeed :P

Share this post


Link to post
Share on other sites



nice idea, try making some code! And when you do, I'd love to check it out...


[center][/center]

Share this post


Link to post
Share on other sites

goddamit why did you post something without code? make us some code


If you fool around with a thing for very long you will screw it up

Share this post


Link to post
Share on other sites

goddamit why did you post something without code? make us some code

Oh, now that's really going to get results - NOT.

Share this post


Link to post
Share on other sites

gotta love borat :)


----------------------------------90% of teens today would die if Myspace,Bebo + FaceBook had a system failure and was completely destroyed. If you are one of the 10% that would be laughing, copy and paste this to your signature.----------------------------------Code to win, 'till you die, 'till the compiler dies from your linesCode to win, take it all, just keep coding till you fallDay by day, codin' all the way, I'm not cavin' inLet another App begin, code to win

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

1 year old topic, ducks for cover eeek!

Edited by JellyFish666

Share this post


Link to post
Share on other sites

More like 6 months

Share this post


Link to post
Share on other sites

Yes, the only way I've come close to doing motion detection is to use third party software and just monitor the size of the images folder to see if things change. When they do, I have events trigger, but it's not the best at all. In fact, it kind of sucks. I really wish there was a DLL out there that someone could use to make a *good* motion detection program.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

prospeed.dll can.

it has a CompareBytes() function

its not in the udf, but i can put it in if you want :)

don't ask me to write a complete motion detection program.

i will only include it in the udf , with 1 example.

Edited by jpam

Share this post


Link to post
Share on other sites

#10 ·  Posted

Zerocool made a very nice one awhile back. I cannot seem to find it now, but it worked nicely. Although, I cannot remember if he actually used AutoIt to make it..


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

If ImageMagickObject.dll is registered on your machine, the code should be something along these lines:

(note that the default threshold may be an inappropriate value-I'm not currently on a computer with ImageMagickObject registered, so I'm not sure what range the MAE metric could return).

#include <ImageMagickObject.dll.au3>
Func _MotionDetected($_Pic1,$_Pic2,$_Threshold=15)
    Local $oIM=ObjCreate("ImageMagickObject.MagickImage")
    Local $_ReturnVal=$oIM.Compare("-metric","MAE",$_Pic1,$_Pic2)
    If $_ReturnVal>=$_Threshold Then
        Return 1
    Else
        Return 0
    EndIf
    $oIM=0
EndFunc

You could get my ImageMagickObject.dll.au3 include file here (thanks again GeoSoft for hosting this, originally from this thread), but if I remember right, I didn't include the .Compare functions in that dll...you'd be better off installing ImageMagick yourself, and choosing to register the dll in the installation routine. If you do try my include, note that because it registers a COM dll on your system, you'll need administrative privileges the first time you run it (#requireadmin on vista). After it's registered the first time, it will run at any privilege level.

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#12 ·  Posted

jpam, that sounds interesting. I wouldn't expect a complete motion detection program or UDF, but if there's a way to compare two images of a captured webcam image, that would be interesting. If it's comparing bytes of a file or filesize, however, I wouldn't bother. I've already tried doing that method and it's not a very useful method for motion detection.

Share this post


Link to post
Share on other sites

#13 ·  Posted

jpam, that sounds interesting. I wouldn't expect a complete motion detection program or UDF, but if there's a way to compare two images of a captured webcam image, that would be interesting. If it's comparing bytes of a file or filesize, however, I wouldn't bother. I've already tried doing that method and it's not a very useful method for motion detection.

A long time ago I used the PixelXXXX Functions to make my mouse follow a highlighter.

If you have a good enough quality camera and a viewer, you could use the pixel functions to monitor non-discreet changes (As in all likely hood, the image will change every second, but subtlety)

Share this post


Link to post
Share on other sites

#14 ·  Posted

it compares 2 bitmap array data's with a user definded tolerance

the tolerance is the amount off bytes that may diiffer from the 2 pictures

something like this ; $result = CompareBytes($array1, $array2, $bytesSize, 50)

$array1 = bitmap array data

$array2 = bitmap array data

$bytesSize = byteSize of the bitmap

50 = tolerance , how many bytes may different from the 2 bitmaps

$return value = 0 if the bitmaps are the same ,else the total bytes that are different

Share this post


Link to post
Share on other sites

#15 ·  Posted

I did some testing with CompareBytes()

it works

between 1 and 1.5 ms for a 400x400 pixel bitmap

Share this post


Link to post
Share on other sites

#16 ·  Posted

Easy method:

Have it take a base screenshot and MD5 it

Every 5 seconds, take a screenshot and MD5 it then compare the two.

If they aren't the same MD5 then something changed.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Easy method:

Have it take a base screenshot and MD5 it

Every 5 seconds, take a screenshot and MD5 it then compare the two.

If they aren't the same MD5 then something changed.

The problem is that you'll never get two pictures of something that are exactly the same. Note that the OP was looking for a tolerance of some kind, which is why the ImageMagick method is a good fit- it gives you the AMOUNT of change from one picture to another. Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#18 ·  Posted

The compare would work great for simple motion/action, but I was wondering does Imagemagick support some sort of co-ord info for where in the motion is detected? (top right of picture, bottom left, etc..)

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

If you have access to the pixels then you could code up a simple mean-square error function (though it wouldn't really be an error, just a difference), and then threshold based on that error. I'm pretty sure it's one of the most common error measures there is. The only difficulty would probably be in determining an appropriate size for the threshold... but that is just a matter of experiment.

http://en.wikipedia.org/wiki/Mean_square_error

Edit:

And if you want information on where the motion occurred I would probably

(1) create an error map

(2) apply some smoothing (probably a blur or unsharp mask)

(3) normalize it

(4) fit a rectangle around the top x% of the error (this rect would tell you where the motion occurred)

Edited by Wus

Share this post


Link to post
Share on other sites

#20 ·  Posted

here's the script i did some testing with

you need prospeed3.0.dll and the prospeed3.0 udf for it

download @ http://prospeed-jan.xprofan.com/

i cannot anwser any questions for 10 days, holiday in spain :)

#include <prospeed3.0.au3>

GUICreate("Compare 2 images", 800, 400)
GUISetState()

$hdc = GetHDC()

$clock1  = LoadFileImage("clock.png")
$size = GetInfosImage($clock1,7)

$clock2 = CreateImage(400,400)
PaintImage($clock2,0,0,400,400,$clock1,0,0,0)
ColorFillImage($clock2,398,398,400,400,0xFFFFFF)

PaintImage($hdc,0,0,400,400,$clock1,0,0,0)
PaintImage($hdc,400,0,400,400,$clock2,0,0,0)

CreateBuffer(800,400)
SetBuffer($hdc)

$array1 = InitFX($clock1)
$array2 = InitFX($clock2)

$Struct1 = DllStructCreate("byte["&$size&"]")
$Struct2 = DllStructCreate("byte["&$size&"]")

$mem1 = SaveToMemoryFX($array1, DllStructGetPtr($Struct1))
$mem2 = SaveToMemoryFX($array2, DllStructGetPtr($Struct2))

$time = TimerInit()

$chk2 = CompareBytes(DllStructGetPtr($Struct1), DllStructGetPtr($Struct2), $size, 0)

$stop = TimerDiff($time)
MsgBox(0,$stop,$chk2)

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then 
        $Struct1 = ""
        $Struct2 = ""
        FreeAllImages()
        FreeFX($array1)
        FreeFX($array2)
        DestroyBuffer()
        Exit        
    EndIf
WEnd

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0