## Recommended Posts

I could use a bit of math help.

What I'd like to do is sample a 5x5 pixel area with PixelChecksum. I would then sample again a few seconds later to check for a change as seems to be the normal usage.

Can I do any useful maths on the PixelChecksum results? For instance, if I subtracted the two sample values would it tell me anything about pixel color content? Might I know that a color shift has happened to maybe Blue or Red for instance? Or would I have to do that on a per pixel sample? And if that is the case... what math would i use to compare an RGB value against another to detect a shift in color from neutral towards Red or Blue?

From the docs:

Quote

A checksum only allows you to see if "something" has changed in a region - it does not tell you exactly what has changed.

```Func _testShift()
; with PixelChecksum
Local \$toler=5
Local \$PCS1 = PixelChecksum(\$x + \$toler, \$y + \$toler, \$x - \$toler, \$y - \$toler, 1, \$windowHandle , 0)
Sleep(200)
Local \$PCS2 = PixelChecksum(\$x + \$toler, \$y + \$toler, \$x - \$toler, \$y - \$toler, 1, \$windowHandle , 0)
If \$PCS1 <> \$PCS2 Then
; How to compare these meaningfully for colorshift?

; or with single pixel....
Local \$px1 =    PixelGetColor(\$x, \$y, \$windowHandle)
Local \$pxRGB1 = _ColorGetRGB(\$px1)
Sleep(200)
Local \$px2 =    PixelGetColor(\$x, \$y, \$windowHandle)
Local \$pxRGB2 = _ColorGetRGB(\$px2)
If \$px1 <> \$px2 Then
If \$pxRGB1 < \$pxRGB2 Then Red?
If \$pxRGB1 < \$pxRGB2 Then Blue?

EndFunc```

##### Share on other sites

In order to do that, I believe you would need to reverse the algorithm used (adler) to create the checksum, unfortunately I do not believe it can be reversed because it is essentially a hash (one way encryption).

I am not 100% on that, but fairly confident of it.

Edited by JohnOne

Monkey's are, like, natures humans.

##### Share on other sites

The only thing i can think of is something like this, it can get improved a lot, but this should give you the idea:

```#include <Array.au3>

Func RegionGetPixelSum(Const \$point_x, Const \$point_y, Const \$nSize, Const \$nPrecision = 1)
Local \$aRet = 
Local \$n = 1

For \$x = 0 To \$nSize-1 Step \$nPrecision
For \$y = 0 To \$nSize-1 Step \$nPrecision
ReDim \$aRet[\$n + 1]
\$aRet[\$n] = PixelGetColor(\$point_x + \$x, \$point_y + \$y)
\$n += 1
Next
Next

\$aRet = \$n - 1
Return \$aRet
EndFunc   ;==>CheckPixel

Local const \$start_x = 555
Local const \$start_y = 555
Local Const \$Size = 5; will be 5x5
Local Const \$Spacing = 2; How much spacing between each pixel check

; Move our mouse so we know where to start search
MouseMove(\$start_x, \$start_y)

; What region we want to keep an eye on
Local Const \$sample = RegionGetPixelSum(\$start_x, \$start_y, \$Size, \$Spacing)

; Store result here
Local \$aResult
Local \$n = 0
; If we found something
Local \$foundsomething = False

while 1
; Constantly check for changes
Local \$test = RegionGetPixelSum(\$start_x, \$start_y, \$Size, \$Spacing)

for \$i = 1 to \$sample
for \$y = 1 to \$test
; Store all id of changes
if \$sample[\$i] <> \$test[\$y] Then
\$foundsomething = True
ReDim \$aResult[\$n + 1]
\$aResult[\$n] = \$sample[\$i]
\$aResult[\$n] = \$test[\$y]
\$n+=1
EndIf
Next
Next

if \$foundsomething Then
ExitLoop
EndIf
WEnd

_ArrayDisplay(\$aResult,"Sample colours | Test colours")```

## Create an account

Register a new account

• ### Similar Content

• By dejhost
Happy New Year everyone!
I would like to extract the color values of certain pixels in an image.  This is how I picture the workflow:
User opens an image of his choice. Image is shown on the screen. User draws a line into the image. This happens by marking the startpixel and the endpixel of the line The line is drawn, so the user can check visually if he is happy with the line.  The following pixel based properties belonging to the line are stored in Excel: X-Coordinate Y-Coordinate Color Value Additional operations: Extracting for max- and min. color values; Statistical operations.   Browsing through the helpfile of AutoIt I find plenty of functions for treating images (e.g. GDIPlus), but I am completely unsure if Autoit will get me there. Should I read the entire image into an array? Should I rather attempt to script an external image software (e.g. IrfanView, Gimp)?
I would be very thankful if someone could give some recommendations and maybe list a couple of the most important commands to use.
Thank you very much.
Dejhost

• By tiye0405
Hello,

I currently have a problem that deals with moving the mouse to a given location + or - a certain distance.
\$search1 =_WaitForImageSearch("envelope.bmp", 10, 1, \$x, \$y, 20)
\$search2 =_WaitForImageSearch("envelope2.bmp", 10, 1, \$x, \$y, 20)

If \$search1 = 1 Then
Sleep(100)
MouseMove(\$x, \$y, 10)
sleep(99)
MouseClick("left")
Sleep(99)
ElseIf \$search2 = 1 Then
Sleep(100)
MouseMove(\$x, \$y2, 10)
sleep(99)
MouseClick("left")
Sleep(100)
Else
Sleep(150)
MouseMove(\$x2, \$y, 10)
Sleep(150)
MouseClick("left")
Sleep(150)
EndIf
The problem about this is that i defined \$x2 = \$x - 175  and \$y2 = \$y + 35
I got these numbers ( 175 and 35) with the autoit helper and just subtracted point where it is to the point its supposed to move but it doesnt work.

is there any proper way to find the distance between 2 points in pixels?

Imgsearch doesnt always work for this picture so i want it to have a backup

edit: could it be that the definition of \$x and \$y  from the previous image search arent there anymore and thats why it moves my mouse to strange places?
is there a way to preserve the \$x \$y from the previous img search untill the next succesful one?

• Hey there!

Is there a way to detect movement only for 1 specific window?

HWnd is not really working, it still detects movement in all the windows within the region

This is my script:

;Checksum actual HotKeySet("{f2}", 'exit_') MsgBox(0, '', '0') Beep(500, 2000) \$Hwnd = WinActive('') while 1 \$Checksum = PixelChecksum(211, 650, 1094, 914, 1, \$Hwnd) If PixelChecksum(211, 650, 1094, 914, 1, \$Hwnd) <> \$Checksum Then For \$i = 1 To 100 Beep(1000, 50) Next MsgBox(0, '', 'New message!', 1) EndIf WEnd Func exit_() Beep(500, 1000) Exit 0 EndFunc I just want to check whenever a message comes because the app i use doesn't give notifications properly.

Any help is really appreciated!

• Hi!

I'm trying to script an ellipse drawing algorithm in AutoIT for learning purposes.
I use an edit control to "draw" the ellipse with characters.
The code i have works kinda good but i would like to see if others around here know a better algorithm to do it..
I would like to be able to give the x, y and width, height arguments to the function and not have to start at the middle point and draw the ellipse around it.

side note, the ellipse glitches when it has to be 2 pixels high too..

func ellipsePlotPoints (\$xc,\$yc, \$x,\$y) pixel (\$xc + \$x, \$yc + \$y) pixel (\$xc - \$x, \$yc + \$y) pixel (\$xc + \$x, \$yc - \$y) pixel (\$xc - \$x, \$yc - \$y) endfunc func ellipse(\$xc,\$yc, \$a,\$b) local \$a2 = \$a * \$a local \$b2 = \$b * \$b local \$twoa2 = 2 * \$a2 local \$twob2 = 2 * \$b2 local \$p local \$x = 0 local \$y = \$b local \$px = 0 local \$py = \$twoa2 * \$y ; Plot the initial point in each quadrant. ellipsePlotPoints (\$xc,\$yc, \$x,\$y) ; Region 1 \$p = int(\$b2 - (\$a2 * \$b) + (0.25 * \$a2)) while (\$px < \$py) \$x+=1 \$px += \$twob2 if (\$p < 0) then \$p += \$b2 + \$px else \$y-=1 \$py -= \$twoa2 \$p += \$b2 + \$px - \$py endif ellipsePlotPoints (\$xc,\$yc, \$x,\$y) wend ; Region 2 \$p = int (\$b2 * (\$x+0.5) * (\$x+0.5) + \$a2 * (\$y-1) * (\$y-1) - \$a2 * \$b2) while (\$y > 0) \$y-=1 \$py -= \$twoa2 if (\$p > 0) then \$p += \$a2 - \$py else \$x+=1 \$px += \$twob2 \$p += \$a2 - \$py + \$px endif ellipsePlotPoints (\$xc,\$yc, \$x,\$y) wend endfunc
• By lacamel
Hi there,
I did a short script to simulate mouse click when pixel change is detected on a small section of the screen. I recorded the screen many times to see the accuracy of the script and it seems though response time varies widely.
Here's the script
\$checksum = pixelchecksum (400,250, 402,252)
While \$checksum = pixelchecksum (400,250, 402,252)
Sleep (50)
Wend
Sleep (300)
Mouseclick("left", 450,300, 1, 0)
Counting from the pixel change to the mouse click, i get response times anywhere between 370ms and 550ms. I've tried running au3 and exe, changed sleep times but never gotten an accurate response time based on the script. Any ideas why?
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...