Jump to content

compare bitmaps from webcam


Recommended Posts

I am using the new webcam script and I wanted to do motion sensing but it would alway sense motion if I did a checksum compare.

My question is, is there a way to compare or do a checksum to a percentage, like 30% difference?

Thanks a lot

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

I don't think so... You would need to write your own checksum function. Maybe If you took pixel colors from every 10th pixel or so and checked them against the previous color with some determined toloerance. If the tolerance is surpased, raise the red flag... regardless, record the pixel colors into an array... This one interests me... perhaps I will write this function... It will monitor an area on screen for changes...

LAr.

thanks, I just thought maybe there would be an easier way, I will get started on that.

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

I wrote this as proof of concept... maybe it gives you ideas...

HotKeySet("{ESC}","Bye")

MotionDetect(0,0,99,49,20)

While 1
    Sleep(50)
    If $MD_Motion = 1 Then
        ToolTip("Moved")
        Sleep(1500)
        ToolTip("")
        $MD_Motion = 0
    EndIf
WEnd
Func MotionDetect($l,$t,$r,$b,$tolerance)
    Global $MD_l = $l
    Global $MD_t = $t
    Global $MD_r = $r
    Global $MD_b = $b
    Global $MD_tolerance = $tolerance

    Global $MD_elements = Int(((($MD_r - $MD_l) + 10) / 10)) * _
            Int(((($MD_b - $MD_t) + 10) / 10))
    
    Global $MD_cur[$MD_elements]
    Global $MD_next[$MD_elements]
    
    MD_LoadArray(1)
    If Not IsDeclared("MD_Motion") Then AdlibEnable("MD_Check")
    Global $MD_Motion = 0
EndFunc

Func MD_LoadArray($MD_initial)
    Local $y,$x,$n = 0
    For $y = $MD_t to $MD_b Step 10
        For $x = $MD_l to $MD_r Step 10
            $MD_next[$n] = Hex(PixelGetColor($x,$y),6)
            $MD_next[$n] = Dec(StringLeft($MD_next[$n],2)) + _
                    Dec(StringMid($MD_next[$n],3,2)) + _
                    Dec(StringRight($MD_next[$n],2))
            $n += 1
        Next
    Next
    If $MD_initial Then $MD_cur = $MD_next
EndFunc

Func MD_Check()
    Local $i,$colornext,$colorcur
    MD_LoadArray(0)
    For $i = 0 to ($MD_elements - 1)
        If (Abs($MD_cur[$i] - $MD_next[$i]) / 3) > $MD_tolerance Then $MD_Motion = 1
    Next
    $MD_cur = $MD_next  
EndFunc

Func bye()
    Exit
EndFunc

Thanks a lot, this will really help.

it works great but when I exit I get errors like:

C:\Documents and Settings\-\Desktop\larrys proof.au3(7,19) : WARNING: $MD_Motion: possibly used before declaration.

If $MD_Motion =

Thanks again

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Just a warning... and a decent warning... The code is not writtent to work as a UDF or anything... Just to exhibit the possibilities. I am sure there are gobs of different ways of implementing the same pixel comparison logic...

Lar.

ok, but just what you had, when I exit it, it gives me the undefined errors?

I did try this with the web cam too and it is awsome. I can watch to see if my boss is coming.

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Warning comes running from Scite?... or running otherwise?

Lar.

just from Scite, it doesnt error out

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Dear Larry,

I have a question, what is the reason using length = 6 in this func. Hex(PixelGetColor($x,$y),6) not less or more and why you divid the $MD_next[$n] result to three Dec values instead of using $MD_next[$n] = Dec($MD_next[$n]).

Other question, why you divide Abs($MD_cur[$i] - $MD_next[$i]) by 3 and what is $MD_tolerance.

Thanks in advance.

Best regards

H.J.

Link to comment
Share on other sites

Hex(PixelGetColor($x,$y),6) because a Color is like this: ff00ff.

It has always 6 (if you would use 8 it would just add 00 at the left side)

[sry...don't know how to explain that in english :> ]

Why is he deviding $MD_next[$n] in 3 parts is, because a color (for example ff00ff) contains 3 colors [Red, Green, Blue (that's why it's called RGB)]. He wants to get the Colorcode (in my example 255,0,255)...i think that's why he's doing this.

Well..just a guess :D

Link to comment
Share on other sites

Thanks to all your helps, but what about (Abs($MD_cur[$i] - $MD_next[$i]) / 3) > $MD_tolerance, why he divid by three, is it the average for the total three colors Red, Green and Blue?

Thanks in advance

Edited by H.J.
Link to comment
Share on other sites

Post the Script please ^^ (the WebCam + MotionDetection)

Detector

#Include <Misc.au3>
Sleep(3000)
$pos = WinGetPos ( "Camera" )
MotionDetect($pos[0],$pos[1],$pos[2]+$pos[0],$pos[1]+$pos[3],40)

While 1
    Sleep(50)
    If $MD_Motion = 1 Then
SoundPlay( "C:\Documents and Settings\-\Desktop\buzzer.wav", 1 )
        $MD_Motion = 0
    EndIf
    If _IsPressed( "1B" ) Then Exit
WEnd


Func MotionDetect($l,$t,$r,$b,$tolerance)
    Global $MD_l = $l
    Global $MD_t = $t
    Global $MD_r = $r
    Global $MD_b = $b
    Global $MD_tolerance = $tolerance

    Global $MD_elements = Int(((($MD_r - $MD_l) + 10) / 10)) * _
            Int(((($MD_b - $MD_t) + 10) / 10))
   
    Global $MD_cur[$MD_elements]
    Global $MD_next[$MD_elements]
   
    MD_LoadArray(1)
    If Not IsDeclared("MD_Motion") Then AdlibEnable("MD_Check")
    Global $MD_Motion = 0
EndFunc

Func MD_LoadArray($MD_initial)
    Local $y,$x,$n = 0
    For $y = $MD_t to $MD_b Step 10
        For $x = $MD_l to $MD_r Step 10
            $MD_next[$n] = Hex(PixelGetColor($x,$y),6)
            $MD_next[$n] = Dec(StringLeft($MD_next[$n],2)) + _
                    Dec(StringMid($MD_next[$n],3,2)) + _
                    Dec(StringRight($MD_next[$n],2))
            $n += 1
        Next
    Next
    If $MD_initial Then $MD_cur = $MD_next
EndFunc

Func MD_Check()
    Local $i,$colornext,$colorcur
    MD_LoadArray(0)
    For $i = 0 to ($MD_elements - 1)
        If (Abs($MD_cur[$i] - $MD_next[$i]) / 3) > $MD_tolerance Then $MD_Motion = 1
    Next
    $MD_cur = $MD_next 
EndFunc

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

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