Sign in to follow this  
Followers 0
quixote79

_PixelsSearch

11 posts in this topic

#1 ·  Posted (edited)

This is demo.

It can be replacement of pixelsearch().

_PixelsSearch() can find pixel by not just 1 pixel info.

_PixelsSearch() use Areavalue which includes plural pixel info(color and distance between pixels) to find point.

Please see and advice to me.

#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.5 Prototype

opt("MouseCoordMode", 1);1=absolute, 0=relative, 2=client
opt("PixelCoordMode", 1);1=absolute, 0=relative, 2=client

#include <GuiConstants.au3>

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GUICreate("Demo", 290, 420, (@DesktopWidth - 392) / 2, (@DesktopHeight - 316) / 2)

GUICtrlCreateTab(10, 10, 270, 400)
GUICtrlCreateTabItem("Create Areavalue")
GUICtrlCreateGroup("Info", 20, 40, 250, 80)
GUICtrlCreateLabel("MouseX :", 30, 65)
GUICtrlCreateLabel("MouseY :", 30, 90)
$label_mousex1 = GUICtrlCreateLabel("1024", 105, 65)
$label_mousey1 = GUICtrlCreateLabel("1024", 105, 90)
$color1 = GUICtrlCreateLabel("", 150, 60, 100, 50)
GUICtrlCreateGroup("AreaValue", 20, 130, 250, 145)
$edit_areavalue1 = GUICtrlCreateEdit("", 30, 150, 230, 50, $es_autovscroll)
$button_clear = GUICtrlCreateButton("Clear", 100, 220, 90, 40)
GUICtrlCreateGroup("Usage", 20, 285, 250, 105)
GUICtrlCreateLabel("This is demo of searching a rectangle", 30, 305)
GUICtrlCreateLabel("of pixels for pixel areavalue provided.", 30, 325)
GUICtrlCreateLabel("To make AreaValue, press F5.", 30, 345)
GUICtrlCreateLabel("Areavalue can be made by plural point.", 30, 365)
GUICtrlCreateTabItem("Find point with Areavalue")
GUICtrlCreateGroup("Info", 20, 40, 250, 80)
GUICtrlCreateLabel("MouseX :", 30, 65)
GUICtrlCreateLabel("MouseY :", 30, 90)
$label_mousex2 = GUICtrlCreateLabel("1024", 105, 65)
$label_mousey2 = GUICtrlCreateLabel("1024", 105, 90)
$color2 = GUICtrlCreateLabel("", 150, 60, 100, 50)
GUICtrlCreateGroup("_PixelsSearch() Variable", 20, 130, 250, 205)
GUICtrlCreateLabel("* Left", 30, 150)
GUICtrlCreateLabel("* Top", 90, 150)
GUICtrlCreateLabel("* Right", 150, 150)
GUICtrlCreateLabel("* Bottom", 210, 150)
$input_left = GUICtrlCreateInput("0", 40, 170, 40, 20)
$input_top = GUICtrlCreateInput("0", 100, 170, 40, 20)
$input_right = GUICtrlCreateInput(@DesktopWidth - 1, 160, 170, 40, 20)
$input_bottom = GUICtrlCreateInput(@DesktopHeight - 1, 220, 170, 40, 20)
GUICtrlCreateLabel("* AreaValue", 30, 210)
$edit_areavalue2 = GUICtrlCreateEdit("Paste a areavalue here...", 30, 230, 230, 50, $es_autovscroll)
GUICtrlCreateLabel("Shade-Variation", 30, 300)
GUICtrlCreateLabel("Step", 190, 300)
$input_sv = GUICtrlCreateInput("0", 130, 300, 40, 20)
$input_step = GUICtrlCreateInput("1", 220, 300, 40, 20)
$button_find = GUICtrlCreateButton("Find", 100, 350, 90, 40)

GUISetState()

HotKeySet("{F5}", "_AreaValue")


While 1
   _Info()
   
   $msg = GUIGetMsg()
   Select
      Case $msg = $gui_event_close
         ExitLoop
      Case $msg = $button_clear
         GUICtrlSetData($edit_areavalue1, "")
      Case $msg = $button_find
         $left = GUICtrlRead($input_left)
         $top = GUICtrlRead($input_top)
         $right = GUICtrlRead($input_right)
         $bottom = GUICtrlRead($input_bottom)
         $areavalue = GUICtrlRead($edit_areavalue2)
         $shadevariation = GUICtrlRead($input_sv)
         $step = GUICtrlRead($input_step)
         GUICtrlSetState($button_find, $gui_disable)
         $pos = _PixelsSearch($left, $top, $right, $bottom, $areavalue, $shadevariation, $step)
         Select
            Case Not @Error
               MouseMove($pos[0], $pos[1])
            Case @Error = 1
               MsgBox(0, "", "Region is not found.")
            Case @Error = 2
               MsgBox(0, "", "Areavalue is invalid.")
         EndSelect
         GUICtrlSetState($button_find, $gui_enable)
   EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

Func _Info()
   $mousepos = MouseGetPos()
   $mousecolor = PixelGetColor($mousepos[0], $mousepos[1])
   GUICtrlSetData($label_mousex1, $mousepos[0])
   GUICtrlSetData($label_mousey1, $mousepos[1])
   GUICtrlSetBkColor($color1, $mousecolor)
   GUICtrlSetData($label_mousex2, $mousepos[0])
   GUICtrlSetData($label_mousey2, $mousepos[1])
   GUICtrlSetBkColor($color2, $mousecolor)
EndFunc  ;==>_Info

Func _AreaValue()
   $mousepos = MouseGetPos()
   $mousecolor = PixelGetColor($mousepos[0], $mousepos[1])
   $areavalue = Hex($mousepos[0], 3) & Hex($mousepos[1], 3) & Hex($mousecolor, 6)
   $oldareavalue = GUICtrlRead($edit_areavalue1)
   GUICtrlSetData($edit_areavalue1, "")
   GUICtrlSetData($edit_areavalue1, $oldareavalue & $areavalue)
EndFunc  ;==>_AreaValue

Func _PixelsSearch($left, $top, $right, $bottom, $areavalue, $shadevariation = 0, $step = 1)
  ;===============================================================================
  ;
  ; Description: Searches a rectangle of pixels for the pixel areavalue provided.
  ; Areavalue is combination of one or more pixel point.
  ; Syntax: _PixelsSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )
  ; Parameter(s): left - left coordinate of rectangle.
  ; top - top coordinate of rectangle.
  ; right - right coordinate of rectangle.
  ; bottom - coordinate of rectangle.
  ; checksum - checksum value of the region.
  ; shadevariation - A number between 0 and 255 to indicate the allowed number of shades of
  ; variation of the red, green, and blue components of the colour. Default is 0 (exact match).
  ; step - Instead of searching each pixel use a value larger than 1 to skip pixels (for speed).
  ; E.g. A value of 2 will only check every other pixel. Default is 1.
  ; Return Value(s): On Success - Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y)
  ; On Failure - Sets @error to 1 if region is not found.
  ; - Sets @error to 2 if areavalue is invalid
  ; Author(s): quixote79
  ; Note(s): Similar to PixelSearch()
  ; It works only under Opt("MouseCoordMode", 1) and Opt("PixelCoordMode", 1)
  ;
  ;===============================================================================
   
   $areavaluelength = StringLen($areavalue) / 12
   If IsInt($areavaluelength) = 1 Then
      Local $x[$areavaluelength]
      Local $y[$areavaluelength]
      Local $color[$areavaluelength]
      If $areavaluelength <> 1 Then
         Local $xg[$areavaluelength - 1]
         Local $yg[$areavaluelength - 1]
      EndIf
      For $a = 0 To $areavaluelength - 1
         $x[$a] = Dec(StringMid($areavalue, 12 * $a + 1, 3))
         $y[$a] = Dec(StringMid($areavalue, 12 * $a + 4, 3))
         $color[$a] = Dec(StringMid($areavalue, 12 * $a + 7, 6))
      Next
      For $b = $areavaluelength - 2 To 0 Step - 1
         $xg[$b] = $x[$b + 1] - $x[0]
         $yg[$b] = $y[$b + 1] - $y[0]
      Next
      
      For $c = $top To $bottom
         $mleft = $left
         Do
            $fpos = PixelSearch($mleft, $c, $right, $c, $color[0], $shadevariation, $step)
            If Not @error Then
               $state = 0
               For $d = 0 To $areavaluelength - 2
                  If PixelGetColor($fpos[0] + $xg[$d], $fpos[1] + $yg[$d]) <> $color[$d + 1] Then
                     $state = 1
                     ExitLoop
                  EndIf
               Next
               If $state = 0 Then
                  Return $fpos
                  ExitLoop
               Else
                  $mleft = $fpos[0] + $step
               EndIf
            Else
               ExitLoop
            EndIf
         Until $mleft >= $right
      Next
      SetError(1)
   Else
      SetError(2)
   EndIf
EndFunc  ;==>_PixelsSearch
Edited by quixote79

Share this post


Link to post
Share on other sites



Really hard for me to read, I suggest you run Tidy on this beast.

Also, you should document the function BEFORE you being it ;)

;====================================6===========================================
;
; Description: Searches a rectangle of pixels for the areavalue provided.
; Areavalue is combination of one or more pixel point.
; Syntax: _PixelsSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )
; Parameter(s): left - left coordinate of rectangle.
; top - top coordinate of rectangle.
; right - right coordinate of rectangle.
; bottom - coordinate of rectangle.
; checksum - checksum value of the region.
; shadevariation - A number between 0 and 255 to indicate the allowed number of shades of
; variation of the red, green, and blue components of the colour. Default is 0 (exact match).
; step - Instead of searching each pixel use a value larger than 1 to skip pixels (for speed).
; E.g. A value of 2 will only check every other pixel. Default is 1.
; Return Value(s): On Success - Returns a two-element array of pixel's coordinates(center of rectangle). (Array[0] = x, Array[1] = y)
; On Failure - Sets @error to 1 if region is not found.
; - Sets @error to 2 if areavalue is invalid
; Author(s): quixote79
; Note(s): similar to PixelSearch()
;
;===============================================================================

Func _PixelsSearch($left, $top, $right, $bottom, $areavalue, $shadevariation = 0, $step = 1)

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

I can't find out how to give indent..

Original Source is properly arranged.

Share this post


Link to post
Share on other sites

I am interested in this function, I ran the program but wasn't quite sure what to do with it. I can be slow though ;) Can you explain the usage a bit more please?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

There are some modifications on source.. plz check.

1. You can make a 'Areavalue' in 'Create Areavalue' tab.

And by pressing F5 one or more times at different place, you can add plural pixel info to Areavalue.

2. Next, it's time to confirm the function.

3. Once making areavalue, copy it and paste it to '* Areavalue' editbox in 'Find point with Areavalue' tab.

4. Click 'Find' button.

5. If mouse cursor moves to destination, it is a success.

Edited by quixote79

Share this post


Link to post
Share on other sites

OOh I like, works nicely, now I need to think of how I would use this ;)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thank you. You are only one who is interested in this function. ;)

Areavalue has 12 char length per 1 point. I think it is too long.

And this function works only under Opt("MouseCoordMode", 1) and Opt("PixelCoordMode", 1).

I want someone's suggestion that makes this function more regular and compatible. Thanks.

Edited by quixote79

Share this post


Link to post
Share on other sites

Thank you. You are only one who is interested in this function. :mad2:

Areavalue has 12 char length per 1 point. I think it is too long.

And this function works only under Opt("MouseCoordMode", 1) and Opt("PixelCoordMode", 1).

I want someone's suggestion that makes this function more regular and compatible. Thanks.

Please don't think that there is only one person intrested in this function. Your function is amazing and I'm very happy that you decided to share it with us. Thank you. ;)

I really sympathise with programmers who are generally ignored by the nescient community here. :P

Share this post


Link to post
Share on other sites

Sorry for my short thinking.

Maybe I want to see many many many replies.^^;

Share this post


Link to post
Share on other sites

ACTools has something similar in that instead of checking a single pixel it will compare blocks of pixels. It makes trying OCR easy, I need something like that for OCR in autoIt.

This function seems close....

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
Sign in to follow this  
Followers 0