Quarrel

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

4 posts in this topic

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[0] < $pxRGB2[0] Then Red?
        If $pxRGB1[2] < $pxRGB2[2] Then Blue?
        
EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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
1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
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[1] = [0]
    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[0] = $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[1][2]
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[0]
        for $y = 1 to $test[0]
            ; Store all id of changes
            if $sample[$i] <> $test[$y] Then
                $foundsomething = True
                ReDim $aResult[$n + 1][2]
                $aResult[$n][0] = $sample[$i]
                $aResult[$n][1] = $test[$y]
                $n+=1
            EndIf
        Next
    Next

    if $foundsomething Then
        ExitLoop
    EndIf
WEnd

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

 

Share this post


Link to post
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

  • Similar Content

    • lacamel
      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?
    • Nitrolord
      By Nitrolord
      I had this problem with PixelGetColor not giving me the same HEX Color as the AU3Info Tool and searched every were with no luck then had a OH DA moment LoL.
      The problem is that the
      "PixelGetColor ($mouseX[0], $mouseY[1])"
      is looking rite at the very tip of the mouse pointer not under it.  So you have to set a -3 after the [0] and [1].  
      "PixelGetColor ($mouseX[0] -3, $mouseY[1] -3)"
      to make it search next to the pointer not on the pointer.  You may have to adjust this a bit for your display but you should not have  to go more then -5.  -3 seems to work best for me.
      Example.au3
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 141, 127, 276, 231) $Input1 = GUICtrlCreateInput("", 8, 8, 121, 21) $Label1 = GUICtrlCreateLabel("Press or Hold F1 to get Hex color at Mouse X -3, Y-3 Pos,", 8, 40, 124, 73) GUISetState(@SW_SHOW) HotKeySet("{f1}","MousePos") Func MousePos() $aPos = MouseGetPos() $PGC = PixelGetColor($aPos[0] -3, $aPos[1] -3) GUICtrlSetData($Input1, "0x" & Hex($PGC, 6)) EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • Miliardsto
      By Miliardsto
      Hello i have problem with function PixelGetColor. On my computer it working fine but in some cases it not working.
      And Im clicking on the active window on red color and it give me the same color still. But in other computers when clicking on the same color red it gives other values and returned color in MsgBox is not red.
      Dont know is it a real main thing what causing problem but,
      I noticed that problem was on one windows 10.
      I have windows 8 and working well. On other windows 10 works well to
      Maybe it is caused by windows aero or something like that
      How to deal with it?
      There is a code
      HotKeySet("{PAUSE}", "MouseCord") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func MouseCord() Global $MousePos = MouseGetPos() $clickedColor = PixelGetColor($MousePos[0], $MousePos[1]) MsgBox(0, "Done", $clickedColor) EndFunc  
       
    • Reizvoller
      By Reizvoller
      Hello,
      I am using the addon-library of FastFind.au3  found here :
       
      The script I've put together is rather simple but it's returning a value that I don't understand.
      #include "FastFind.au3" #Include <WinAPI.au3> #RequireAdmin WinActivate ("ABC Window") Local $xyzWindow = WinGetHandle ("ABC Window") Local $triangleSpot = FFSnapShot (212, 216, 214, 218, 1, $xyzWindow) ConsoleWrite ($triangleSpot&@CR) Local $triangleData = FFGetRawData (1) Local $splitTriangleData = StringSplit ($triangleData, "00") Local $iMax If isArray ($splitTriangleData) Then $iMax = Ubound ($splitTriangleData) ConsoleWrite ($iMax) EndIf So here's the question...
      If the area I have selected is a total of 4 pixels , why is the UBound return value 26?
      I thought that maybe it was getting values for the 4 along with the surrounding pixels bordering the selected area, even still , it should provide only 16 values(or so I thought). 
      I feel that there is a bit of pixel data or something that I am not fully understanding. If anyone could please provide materials on what is happening I'd really appreciate it. 
      Thank you for your time!
      -Reiz
      PS : I used terms like "triangleSpot" and such because in the actual window there is a small triangle icon that I am trying to gain the pixel data of to then search for others like it on the page. I understand the area that I am selecting is a square/rectangle and not a triangle. 
    • WoodGrain
      By WoodGrain
      Hi All,
      I'm trying to run a script to fire when a pixel at a certain location on the screen changes to a particular colour, however auinfo is unable to measure the colour where my cursor is due to my high resolution - 2560x1440 on a 13.3" laptop. Does anyone have a workaround or a fix for this?
      If I move my mouse to the bottom-right corner of the screen auinfo reports the mouse position as about 1280x720, 1/2 my actual resolution.
      Thanks!