Alexxander Posted February 9, 2014 Share Posted February 9, 2014 (edited) hi all i want to make a camera motion detection system and know the place of the motion. i'm thinking of making a script that take a picture from the usb camera every 1 second then detect if their is changes in the picture my idea is to make it take a picture in second 1 and store that pic in a temp folder in second 2 it takes another pic and save it then it detect the visual pixel changes between the 2 images . if their is difference then their is a motion in the environment my question is how can i do the image dividing and how to compare the visual Columns ? is my idea good or their is a better methods to do this ? any help/ideas is much appreciated Edited February 9, 2014 by Alexxander Link to comment Share on other sites More sharing options...
JohnOne Posted February 9, 2014 Share Posted February 9, 2014 (edited) There have been a few discussed on the forum, none very good or reliable. I'd say out loud that AutoIt is not the language to develop such an application. But, of course, best of luck. EDIT: For example a cloud moves, the sun casts a new shadow, the lighting changes in any way, a bug crawls past etcetera. EDIT2: I believe OpenCV is what you could use. EDIT3: >Link to some AutoIt code using OpenCV Edited February 9, 2014 by JohnOne Alexxander 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
junkew Posted February 9, 2014 Share Posted February 9, 2014 (edited) http://sourceforge.net/projects/opencvlibrary/not sure if anyone has tried to call those functions from AutoITthis is not fast enough'?do=embed' frameborder='0' data-embedContent>>and maybe search the form for bitblt or GDIBTW: more, less light will give every second a different bitmap due to light effects Edited February 9, 2014 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
nullschritt Posted February 9, 2014 Share Posted February 9, 2014 If you want to do this in pure autoit my recommendation is to get the pixel data for each image and then split the data into arrays, comparing each element. This would return a % of the image that had changed. Then you would simply need to only save the file if more n% has changed. Link to comment Share on other sites More sharing options...
nullschritt Posted February 9, 2014 Share Posted February 9, 2014 You could go even further to compensate for lighting changes by comparing the percentage of change between each hexidecimal value of each pixel, and then averaging the total difference(this way if the light increases/decreases by a small amount, the returned % will be the amount of change that occured in the lighting, where-as the original situation I presented would return the percentage of the whole image that changed as a result of the lighting effect).. Link to comment Share on other sites More sharing options...
JohnOne Posted February 9, 2014 Share Posted February 9, 2014 I reckon large video images would have quite a lot of pixels, and would take quite some time, to collect the data. $Timer = TimerInit() For $y = 0 To @DesktopHeight For $x = 0 To @DesktopWidth PixelGetColor($x, $y) Next Next MsgBox(0,0,Round(TimerDiff($Timer),2)) While being just as unreliable on a video stream as the faster PixelChecksum. $Timer = TimerInit() PixelChecksum(0, 0, @DesktopWidth, @DesktopHeight) MsgBox(0, 0, Round(TimerDiff($Timer), 2)) Exit However here is an example using PixelChecksum. Move mouse over button, (cursor is not detected). #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> $hGUI = GUICreate("", 100, 100, 200, 200) $hButton = GUICtrlCreateButton("x", 0, 0, 100, 100) GUISetState() $winpos = WinGetPos($hGUI) Sleep(250) $psum = PixelChecksum($winpos[0], $winpos[1], $winpos[0] + $winpos[2], $winpos[1] + $winpos[3]) Do _Detect() Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _Detect() If PixelChecksum($winpos[0], $winpos[1], $winpos[0] + $winpos[2], $winpos[1] + $winpos[3]) <> $psum Then Exit MsgBox(0, 0, 'Change') EndIf EndFunc ;==>_Detect AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
nullschritt Posted February 9, 2014 Share Posted February 9, 2014 @JohnOne The idea was for a slightly improved accuracy by getting the actual percent of pixels changed. And getting pixels could be faster with gdi. (: Link to comment Share on other sites More sharing options...
JohnOne Posted February 9, 2014 Share Posted February 9, 2014 Suppose. There's that fast pixel dll in example forums too, that could be worth a look, seems to have all kinds of features. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
nullschritt Posted February 10, 2014 Share Posted February 10, 2014 (edited) Here's a function I wrote to compare two colors in hexadecimal format. To make use of this make an array/string of all the pixels in each image. You can pass values of any length to the _colorcompare() function, so it's possible to pass all the pixels for both images to the function as a string, or you can process it in chunks of 6/12/24 or however you want to do it, though the less times you call the function, the faster the end result will be.ConsoleWrite(_colorcompare('ffffff', 'eeeeee')&@CRLF) func _colorcompare($color1, $color2) Local $difference $color1 = StringSplit($color1, "") $color2 = StringSplit($color2, "") $difference = 0 for $i=1 to $color1[0] if $color1[$i] <> $color2[$i] Then $difference += Abs(_hextonum($color1[$i]) - _hextonum($color2[$i])) EndIf Next $difference = (($difference/$color1[0])/15)*100 Return $difference EndFuncEdit: Fixed a bug in the percentage calculation, had two numbers backwards.Seems decently fast Takes about 100ms on a 1000 pixel image (500x500) Edited February 10, 2014 by nullschritt Link to comment Share on other sites More sharing options...
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