# Pixel Check Sum: can I use it for math calculations?

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

• #### Monitoring colours - PixelSearch and PixelCheckSum - (Moved)

By Dave1,

• 19 replies
• 1,678 views
• #### Detect pixel changes on specific screen area?

By kellariluukku,

• 13 replies
• 3,457 views
• #### Extracting color-values of image along a user specified line

By dejhost,

• 19 replies
• 3,357 views
• #### Getting distance in pixels?

By tiye0405,

• 5 replies
• 1,580 views
• #### Detect movement in a certain window

By DynamicRookie,

• 6 replies
• 1,991 views
×

• Wiki
• #### AutoIt Resources

• FAQ
×
• Create New...