Jump to content

count how many pixels has changed in area


Recommended Posts

Depending on how big of an area you are looking at, any script may be too CPU intensive for you to be happy. It sounds like you are new to AutoIt, so I would suggest looking at the help file and trying some scripts. Here is a "brute force" approach:

1) define the area you want to look at in pixels: left, right, top and bottom. I would recommend a small area: 4 by 4 to get started

2) Loop through your area and GetPixelColor storing the value in an array. The help files and forum can help with how to work with arrays

3) This same loop will be used to get the data after the change but it will be stored in a different array. Each element in the array can be compared to the baseline. If A = B then ...

There may be more efficient ways, but I would suggest getting your feet wet with this excersise to learn some of the things you are confused about. Then tackle the bigger problem.

Welcome to AutoIt.

Bob

You can't see a rainbow without first experiencing the rain.

Link to comment
Share on other sites

OK, I'm newbie, but not such a big newbie. I just couldn't make it because there are many loops and i need something like "extended array". You'll see what i mean in the code bellow. When i wrote first post, i couldn't write this code, but i got angry of YellowLab (sorry, but you told me things which i knew and thank you, without you i couldn't write it :P ) and i wrote it. So, here is my new don't working code and i bet you'll find mistake and what i meant with "extended array" almost immediately (hint: lines 21,23,28 :P)

$a=0
$dif=0

$ltopmsgbox = MsgBox (0, "left top", "Select left top of rectangle with mouse cursor and push ENTER")
If $ltopmsgbox = 1 Then
    $ltop = MouseGetPos()
Else    
    Exit
EndIf

$rbottommsgbox = MsgBox (0, "left top", "Select right bottom corner of rectangle with mouse cursor and push ENTER")
If $rbottommsgbox = 1 Then
    $rbottom = MouseGetPos()
Else 
    Exit
EndIf

While $dif < 4 ;determine how many pixels can be different before you'll get result
    For $godown = $ltop[1] to $rbottom[0]-$ltop[0] ;loop for jump to new row after all vertical pixels in row has been checked
        For $goright = $ltop[0] to $rbottom[1]-$ltop[1] ;loop for jump to new pixel in horizontal direction
            $var[[$goright,$godown]$a] = PixelGetColor($goright, $godown) ;getting colour of pixel to $var
            If $a = 0 Then
                If Not $var[[$r,$d]$a]=$var[[$r,$d]1] Then ;if pixel colour isn't same as before, increase $dif
                    $dif=$dif+1
                    $a = 1
                EndIf
            Else
                If Not $var[[$r,$d]$a]=$var[[$r,$d]0] Then
                    $dif=$dif+1
                    $a=0
                EndIf
            EndIf
        Next
    Next
WEnd
MsgBox(0, "Result", "In the selected area has changed " &$dif &" pixels")

btw, i know it'll be cpu intensive, but the script will be running when computer is in inactivity. I want at least try that.

Link to comment
Share on other sites

maybe that can help...

$Dif=0

$ltopmsgbox = MsgBox (0, "left top", "Select left top of rectangle with mouse cursor and push ENTER")
If $ltopmsgbox = 1 Then
    $ltop = MouseGetPos()
Else   
    Exit
EndIf

$rbottommsgbox = MsgBox (0, "left top", "Select right bottom corner of rectangle with mouse cursor and push ENTER")
If $rbottommsgbox = 1 Then
    $rbottom = MouseGetPos()
Else
    Exit
EndIf

$Width = $rbottom[0] - $ltop[0]
$Heigh = $rbottom[1] - $ltop[1]
Dim $_aPixels[$Width][$Heigh][2]

$Counter = 0
While $Dif < 4 ;determine how many pixels can be different before you'll get result
    For $GoTop = $ltop[1] To $rbottom[1]-1 ;loop for jump to new row after all vertical pixels in row has been checked
        For $GoRight = $ltop[0] to $rbottom[0]-1 ;loop for jump to new pixel in horizontal direction
            $abs = $GoRight-$ltop[0]
            $Ord = $GoTop-$ltop[1]
            $_aPixels[$abs][$Ord][0] = PixelGetColor($GoRight, $GoTop)
            If $Counter==0 Then
                $_aPixels[$abs][$Ord][1] = PixelGetColor($GoRight, $GoTop)
            Else
                If $_aPixels[$abs][$Ord][0]<>$_aPixels[$abs][$Ord][1] Then $Dif = $Dif + 1
            EndIf
        Next
    Next
    $Counter = $Counter + 1
WEnd
MsgBox(0, "Result", "In the selected area has changed " & $Dif &" pixels")
Link to comment
Share on other sites

thank you! i don't know how it works, but it works, great! And it isn't as slow as i though. It took cca 12 sec. to react on youtube video and cca 1m,8sec. to react on change on my desktop 1280x800px

Edited by gadelat
Link to comment
Share on other sites

thank you! i don't know how it works, but it works, great! And it isn't as slow as i though. It took cca 12 sec. to react on youtube video and cca 1m,8sec. to react on change on my desktop 1280x800px

you're welcome,

you gt a pb with you're array declaration

$var[[$r,$d]$a]

maybe it's not the best way to do this but if it's works with a minimum f work....

here is the thing : double loop to scan width and height then put it in a 3 dimensional array

$_aPixels[$abs][$Ord][0]

for your screen 1280*800 this array will have 1280 entry on first dimension 800 on second and 2 (1 for the first pixel color and another if the color change) for the third.

during the first pass we put all the color for each pixel in the array (for exemple, pixel at top left will be placed on $_aPixels[0][0][0]

We do the same for the last dimension : $_aPixels[0][0][1], but only the first time to keep the first pass color

during the rest of the loop, we compare pixel color with the one store in the array : If $_aPixels[$abs][$Ord][0]<>$_aPixels[$abs][$Ord][1] Then $Dif = $Dif + 1

til $dif <4

for a big resolution, memory will be solicited because our array will be huge 1280*800*2 entries...

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