Jump to content

webcam motion detection


mary
 Share

Recommended Posts

  • 5 months later...

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

Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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..)

Spoiler

Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder
Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...