Jump to content
Quarrel

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

Recommended Posts

Quarrel

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
JohnOne

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
  • Like 1

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
tarretarretarre

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

    • tiye0405
      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?
       
       
    • DynamicRookie
      By DynamicRookie
      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!
    • TheAutomator
      By TheAutomator
      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  
    • 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  
×