Sign in to follow this  
Followers 0
Smorg

Help with pixelsearching algorhythms.

2 posts in this topic

Can i change pixelsearch to reverse its scan direction? In fact, i want to use pixelsearch's optomized scan algorhythm to search a lot of differant patterns besides linear left, right, top, bottom scan.

For this application, i need 4 searches. one to scan a vertical line of pixels down, and another to look up. Also 2 more for left and right. Unfortunatly it seems pixelgetcolor called in a loop is at least 20x slower than pixelsearch. however for small searches of a single row of pixels, is it still faster to use pixelsearch? or is there ever a situation where pixelgetcolor is faster?

This application is very time critical because i will be doing continuous polling of a meter at a very high refresh rate. This will be accomplished by finding the edge of a bar of pixels, and waiting for a change in direction. After this happens it will search either up or down depending on the detected change and derrive a percentage based on the found edge. (there are 3 progressbar-like meters total, 2 vertical and 1 horizontal)

Since changes can be gradual, or quick (unpredictable), but doing a complete rescan from top to bottom of the entire bar would take a lot more scans.

There are other applications i'd like this for such as finding the nearest pixel of x color to a point using a circular scanning engine, and doing either entire screen dumps to an array, or dumps of single color presences at any resolution to an array. Pixelgetcolor is so damned slow...

i'd love to just take your sourcecode and modify it, but i dont know any other languages.

How do the screenshots work? It seems windows can instantly dump the entire screen to a bitmap. If we could do this then you could instantly get a searchable array of data and even pixelsearch minimized windows. That would be insanely fast.

For the circle search, i cannot find an appropreate algorhythm. I would need to look in concentric circles from a starting point, without skipping or rescans. I have tried a trigonomic stepping algorhythm to look at vectors. The rounding caused by radian stepping is terrible because i get rescans and skips. I cannot think of a way to compensate for this. The second method i tried the bresenham circle alg I rewrote for autoit. This is slightly better but still causes massive skipping. I almost need some sort of rasterization mechanism to correct the problem. You can see from mapping these plots that there is a definate pattern to skips so there must be a way to solve the problem.

The following are scripts I designed to test each situation. Both give similar but not identical results.

Vector based:

;-------------------Paramaters-------------------
#include <math.au3>
#Include <Array.au3>
#include <GuiConstants.au3>
Opt("guioneventmode", 1)
;------------------User Variables----------------
Global $Data[1001][1001]
$Resolution = 1
Const $Pi = 3.14159265358979323846264338327950288
;-----------------------GUI----------------------
GuiCreate("Circle Array Tester", 499, 165,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Progressbar = GuiCtrlCreateProgress(100, 130, 390, 20)
GuiCtrlCreateLabel("Progress", 10, 130, 90, 20)    ;Status
$diminput = GuiCtrlCreateInput("", 70, 10, 70, 20)
GuiCtrlCreateLabel("Dimensions:", 10, 10, 50, 20)
GuiCtrlCreateGroup("Statistics:", 320, 10, 170, 110)
$Input_X = GuiCtrlCreateInput("", 400, 30, 80, 20)
$Input_Y = GuiCtrlCreateInput("", 400, 60, 80, 20)
$Input_Radius = GuiCtrlCreateInput("", 400, 90, 80, 20)
GuiCtrlCreateLabel("X", 330, 30, 60, 20)
GuiCtrlCreateLabel("Y", 330, 60, 60, 20)
GuiCtrlCreateLabel("Radius", 330, 90, 60, 20)
$go = GuiCtrlCreateButton("Go", 10, 80, 70, 30)
$Exit = GuiCtrlCreateButton("Exit", 100, 80, 70, 30)
;GuiCtrlCreateLabel("", 210, 105, 150, 20)

GUICtrlSetOnEvent ($go, "StartScript")
GUICtrlSetOnEvent ($Exit, "Terminate")
GuiSetState()
While 1
    Sleep(50)
Wend
;------------------------------------------------
Func StartScript()
$Radius = 0
$xcoord = 400
$ycoord = 300
$dimension = GuiCtrlRead(5)
$time = TimerInit()
ControlSetText("", "", 4, "Building Array...")
For $b = 1 To $dimension
    ControlSetText("", "", 9, $B)
    For $a = 1 To $dimension
        $Data[$a][$b] = 0
        ;ControlSetText("", "", 8, $a)
        ;ControlSetText("", "", 16, ($b*$dimension)+$a & " / " & $dimension^2)
    Next
    GuiCtrlSetData(3, 100*((($b*$dimension)+$a)/($dimension^2)))
Next

ControlSetText("", "", 4, "Drawing Circles...")
$total = 0
Do
    For $PiCount = 0 to ($pi * 2) Step $Resolution* (($pi * 2) / (($Radius * 2) * $pi))
        $xcoord = Round(($Dimension/2) + ($Radius * (Cos($PiCount))))
        $ycoord = Round(($Dimension/2) + ($Radius * (Sin($PiCount))))
        If $xcoord > 0 And $xcoord < $dimension And $ycoord > 0 And $ycoord < $dimension Then
            $Data[$xcoord][$ycoord] = $Data[$xcoord][$ycoord] + 1
            $total = $total + 1
            ;ControlSetText("", "", 8, $xcoord)
            ;ControlSetText("", "", 9, $ycoord)
            ;ControlSetText("", "", 16, $total & " / " & $dimension^2)
        EndIf
    Next
    $Radius = $Radius + $Resolution
    ControlSetText("", "", 10, $Radius & " / " & _Floor(Sqrt((($dimension/2)^2) + (($dimension/2)^2))))
    GuiCtrlSetData(3, (100*($Radius/(_Floor(Sqrt((($dimension/2)^2) + (($dimension/2)^2)))))))
Until $Radius >= _Floor(Sqrt((($dimension/2)^2) + (($dimension/2)^2)))

ControlSetText("", "", 4, "Writing File...")
FileDelete("C:\testfile.txt")
$blub = FileOpen("C:\testfile.txt", 2)
For $b = 1 To $dimension
    ControlSetText("", "", 9, $B)
    For $a = 1 To $dimension
        FileWrite($blub, $Data[$a][$b] & " ")
        ;ControlSetText("", "", 8, $a)
        ;ControlSetText("", "", 16, ($b*$dimension)+$a & " / " & $dimension^2)
    Next
    GuiCtrlSetData(3, 100*((($b*$dimension)+$a)/($dimension^2)))
    FileWrite($blub, @CRLF)
Next
FileWrite($blub, @CRLF & "Total Count: " & $Total & @CRLF & "Dimensions: " & $Dimension & " x " & $Dimension & @CRLF & "Elements Area: " & $Dimension^2)
ControlSetText("", "", 4, "Finished.")
MsgBox(1, "Finished", "Finished, Calculation took: " & Round(TimerDiff($time) / 1000) & " Seconds. " & $dimension^2 & " elements were calculated." _
& " Max radius is: " & _Floor(Sqrt((($dimension/2)^2) + (($dimension/2)^2))) & " Total count is: " & $Total)
ToolTip("")
FileClose($blub)
EndFunc

Func Terminate()
    Exit
EndFuncoÝ÷ Ú«¶&¥n·¬zxZh¶z-¢h,Þu©©Â+a¢ëk¢Ö­ÚºÚ"µÍÌÍÜÚ^HHLÛØ[   ÌÍØ^VÉÌÍÜÚ^H
ÈWVÉÌÍÜÚ^H
ÈWBÌÍØHHLÌÍØHÜ  ÌÍÞHHHÈ ÌÍÜÚ^BQÜ   ÌÍÞHHÈ  ÌÍÜÚ^BBIÌÍØ^VÉÌÍÞVÉÌÍÞWHHS^]ÛÛ
    ÌÍÞJB^Ü ÌÍÔY]ÈHHÈ  ÌÍÜÚ^KÌIÌÍÞH    ÌÍÜÚ^KÌIÌÍÞHH
    ÌÍÜÚ^KÌHH  ÌÍÔY]ÂQÂBIÌÍØ^VÉÌÍÞVÉÌÍÞWH
ÏHBBIÌÍÜHXÊ    ÌÍÔY]ÈHÜ



    ÌÍÞ
ÈJHH   ÌÍØJWH
È

    ÌÍØH ÌÍÞJWJJBBIÌÍÜHXÊ ÌÍÔY]ÈHÜ



    ÌÍÞ
ÈJHH   ÌÍØJWH
È

    ÌÍØH
    ÌÍÞH
ÈJJWJJBBIÌÍÙHXÊ    ÌÍÔY]ÈHÜ


    ÌÍÞH ÌÍØJWH
È

    ÌÍØH
    ÌÍÞH
ÈJJWJJBBRY ÌÍÜ  È  ÌÍÜS ÌÍÜ  È  ÌÍÙ[BBIÌÍÞ
ÏHBBQ[ÙRY ÌÍÜ  È  ÌÍÜS ÌÍÜ  È  ÌÍÙ[BBIÌÍÞ
ÏHBBBIÌÍÞH
ÏHBBQ[ÙBBBIÌÍÞH
ÏLBBQ[YU[[ ÌÍÞH ÝÈ    ÌÍØHÊ   ÌÍØH
È
    ÌÍÜY]ËÌJB^ÌÍÙ[HH[SÜ[   ][ÝØÎÌLÝÝ ][ÝËBÜ   ÌÍÞHHHÈ ÌÍÜÚ^BQÜ   ÌÍÞHHÈ  ÌÍÜÚ^BBQ[UÜ]J  ÌÍÙ[K    ÌÍØ^VÉÌÍÞVÉÌÍÞWJBS^Q[UÜ]J   ÌÍÙ[KÔB]ÛÛ
    ÌÍÞJB^[PÛÜÙJ  ÌÍÙ[JB^]

This is the resulting readout from the vector plot @ 50 resolution:

2 1 2 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 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 1 1 1 0 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 0 1 1 1 1 1 2 1 0 1 0 
1 1 1 1 1 1 1 1 1 1 1 1 0 2 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 2 1 1 0 1 1 1 2 1 1 0 
0 1 2 1 0 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 0 1 1 2 1 1 1 0 1 1 2 0 
1 2 1 1 1 2 1 1 1 1 0 2 0 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 0 1 2 1 1 1 0 1 0 
2 1 0 1 2 0 1 1 2 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 2 0 1 1 1 0 
1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 0 1 2 1 1 1 1 1 1 1 2 1 1 0 0 
1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 2 1 0 1 1 1 1 1 2 0 1 1 2 1 0 
1 1 1 1 1 0 2 0 2 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 2 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

Total Count: 2406
Dimensions: 50 x 50
Elements Area: 2500

The pattern becomes much clearer at higher resolutions.

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