ConsultingJoe Posted June 26, 2006 Posted June 26, 2006 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 Check out ConsultingJoe.com
ConsultingJoe Posted June 26, 2006 Author Posted June 26, 2006 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. Check out ConsultingJoe.com
ConsultingJoe Posted June 27, 2006 Author Posted June 27, 2006 I wrote this as proof of concept... maybe it gives you ideas... expandcollapse popupHotKeySet("{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 Check out ConsultingJoe.com
ConsultingJoe Posted June 27, 2006 Author Posted June 27, 2006 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. Check out ConsultingJoe.com
ConsultingJoe Posted June 27, 2006 Author Posted June 27, 2006 Warning comes running from Scite?... or running otherwise?Lar.just from Scite, it doesnt error out Check out ConsultingJoe.com
H.J. Posted June 29, 2006 Posted June 29, 2006 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.
XxXFaNtA Posted June 29, 2006 Posted June 29, 2006 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 /[center][/center]
nfwu Posted June 29, 2006 Posted June 29, 2006 $MD_tolerance is the maximum difference the color can have from the provided color. #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
H.J. Posted June 29, 2006 Posted June 29, 2006 (edited) 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 June 29, 2006 by H.J.
XxXFaNtA Posted June 29, 2006 Posted June 29, 2006 Post the Script please ^^ (the WebCam + MotionDetection) /[center][/center]
ConsultingJoe Posted June 29, 2006 Author Posted June 29, 2006 Post the Script please ^^ (the WebCam + MotionDetection)Detector expandcollapse popup#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 Check out ConsultingJoe.com
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now