Jump to content

Pixelsearch making GUI VERY slow, please help!


Mich9874
 Share

Recommended Posts

Hi guys!

I have a loop that calls this function:

Func TestColors($checkbox,$DColor)
Local $foundcount[4]

$foundcount[0] = 0
$foundcount[1] = 0
$foundcount[2] = 0
$foundcount[3] = 0

$size = WinGetPos($checkbox)
$areatopleft = PixelSearch($size[0],$size[1],$size[0]+($size[2]/2),$size[1]+($size[3]/2),$DColor,$ColorAccuracy,$SkipPixels)
If not @error Then
  $foundcount[0] = 1
EndIf
$areatopright = PixelSearch($size[0]+($size[2]/2),$size[1],$size[0]+$size[2],$size[1]+($size[3]/2),$DColor,$ColorAccuracy,$SkipPixels)
If not @error Then
  $foundcount[1] = 1
EndIf
$areabottomleft = PixelSearch($size[0],$size[1]+($size[3]/2),$size[0]+($size[2]/2),$size[1]+$size[3],$DColor,$ColorAccuracy,$SkipPixels)
If not @error Then
  $foundcount[2] = 1
EndIf
$areabottomright = PixelSearch($size[0]+($size[2]/2),$size[1]+($size[3]/2),$size[0]+$size[2],$size[1]+$size[3],$DColor,$ColorAccuracy,$SkipPixels)
If not @error Then
  $foundcount[3] = 1
EndIf
Return $foundcount
EndFunc

I pass it a GUI window and a color to search for, it divides the GUI window into 4 segments and returns an array of which segments my color was found in. $ColorAccuracy and $SkipPixels are defined as globals.

When I call the function in a loop such as:

Local $Quadrants[4]
Do
$msg = GUIGetMsg()
Select
Case $msg =  $GUI_EVENT_CLOSE
  $Quit = 1
EndSelect
$Quadrants = TestColors("MyGUI",$SearchColor)

Until $Quit = 1
Exit

The GUI slows down to the point that clicking the close button takes multiple seconds (4 to 10) to exit the program. While the GUI is "locked out" the logic continues to run, adding a loop counter shows that it's running multiple loops per second so it's not just waiting for a pixelsearch to complete . I've tried putting sleep()'s in there but it seems to make no difference. I want the pixelsearch to run as often as possible but I don't want it locking up the application like this obviously. The CPU load sits at 3 or 4% while the program is running.

Can someone please enlighten me as to what I'm doing wrong?

Thanks!

Mich

Edited by Mich9874
Link to comment
Share on other sites

Hi guys!

I have a loop that calls this function:

Func TestColors($checkbox,$DColor)
Local $foundcount[4]

$foundcount[0] = 0
$foundcount[1] = 0
$foundcount[2] = 0
$foundcount[3] = 0

$size = WinGetPos($checkbox)
$areatopleft = PixelSearch($size[0],$size[1],$size[0]+($size[2]/2),$size[1]+($size[3]/2),$DColor,$ColorAccuracy,$SkipPixels)
If not @error Then
  $foundcount[0] = 1
EndIf
$areatopright = PixelSearch($size[0]+($size[2]/2),$size[1],$size[0]+$size[2],$size[1]+($size[3]/2),$DColor,$ColorAccuracy,$SkipPixels)
If not @error Then
  $foundcount[1] = 1
EndIf
$areabottomleft = PixelSearch($size[0],$size[1]+($size[3]/2),$size[0]+($size[2]/2),$size[1]+$size[3],$DColor,$ColorAccuracy,$SkipPixels)
If not @error Then
  $foundcount[2] = 1
EndIf
$areabottomright = PixelSearch($size[0]+($size[2]/2),$size[1]+($size[3]/2),$size[0]+$size[2],$size[1]+$size[3],$DColor,$ColorAccuracy,$SkipPixels)
If not @error Then
  $foundcount[3] = 1
EndIf
Return $foundcount
EndFunc

I pass it a GUI window and a color to search for, it divides the GUI window into 4 segments and returns an array of which segments my color was found in. $ColorAccuracy and $SkipPixels are defined as globals.

When I call the function in a loop such as:

Local $Quadrants[4]
Do
$msg = GUIGetMsg()
Select
Case $msg =  $GUI_EVENT_CLOSE
  $Quit = 1
EndSelect
$Quadrants = TestColors("MyGUI",$SearchColor)

Until $Quit = 1
Exit

The GUI slows down to the point that clicking the close button takes multiple seconds (4 to 10) to exit the program. While the GUI is "locked out" the logic continues to run, adding a loop counter shows that it's running multiple loops per second so it's not just waiting for a pixelsearch to complete . I've tried putting sleep()'s in there but it seems to make no difference. I want the pixelsearch to run as often as possible but I don't want it locking up the application like this obviously. The CPU load sits at 3 or 4% while the program is running.

Can someone please enlighten me as to what I'm doing wrong?

Thanks!

Mich

Since autoit isn't multi-thread capable, you get this shit, I would suggest either checking the gui message via adlibregister or create another process for the gui that controls functions in the main process through some nifty form of interprocess communication.

But then I didn't look at your code because I'm a noob and don't really know anything about anything related to searching pixel values since I've never needed it and the problem might be there.

Link to comment
Share on other sites

Since autoit isn't multi-thread capable, you get this shit, I would suggest either checking the gui message via adlibregister or create another process for the gui that controls functions in the main process through some nifty form of interprocess communication.

I just tried using adlibregister to make the call to GUIGetMessage() and it doesn't help. It seems that the message isn't being generated by the button click for several seconds after the click is made.

Cheers for the suggestion!

Mich.

Edited by Mich9874
Link to comment
Share on other sites

  • Moderators

Mich9874,

I have just run the code you posted on a 1500x1000 window and I found the average time for your TestColors function was about 20ms. The [X] on the GUI I added to the code reacted instantly the function returned - which at 20ms means virtually instaneously. :oops:

#include <GUIConstantsEx.au3>

Global $Quit = 0, $Quadrants[4], $ColorAccuracy = 50, $SkipPixels = 1

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

GUISetState()

; Confirm the size of the window being checked
$size = WinGetPos("[CLASS:SciTEWindow]")
ConsoleWrite($size[2] & " - " & $size[3] & @CRLF)

Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            $Quit = 1
    EndSelect
    ; Time the function
    $iBegin = TimerInit()
    $Quadrants = TestColors("[CLASS:SciTEWindow]", 0xFDFDFD)
    ConsoleWrite(TimerDiff($iBegin) & @CRLF)

Until $Quit = 1
Exit

Func TestColors($checkbox, $DColor)
    Local $foundcount[4]

    $foundcount[0] = 0
    $foundcount[1] = 0
    $foundcount[2] = 0
    $foundcount[3] = 0

    $size = WinGetPos($checkbox)
    $areatopleft = PixelSearch($size[0], $size[1], $size[0] + ($size[2] / 2), $size[1] + ($size[3] / 2), $DColor, $ColorAccuracy, $SkipPixels)
    If Not @error Then
        $foundcount[0] = 1
    EndIf
    $areatopright = PixelSearch($size[0] + ($size[2] / 2), $size[1], $size[0] + $size[2], $size[1] + ($size[3] / 2), $DColor, $ColorAccuracy, $SkipPixels)
    If Not @error Then
        $foundcount[1] = 1
    EndIf
    $areabottomleft = PixelSearch($size[0], $size[1] + ($size[3] / 2), $size[0] + ($size[2] / 2), $size[1] + $size[3], $DColor, $ColorAccuracy, $SkipPixels)
    If Not @error Then
        $foundcount[2] = 1
    EndIf
    $areabottomright = PixelSearch($size[0] + ($size[2] / 2), $size[1] + ($size[3] / 2), $size[0] + $size[2], $size[1] + $size[3], $DColor, $ColorAccuracy, $SkipPixels)
    If Not @error Then
        $foundcount[3] = 1
    EndIf
    Return $foundcount
EndFunc   ;==>TestColors

Are you sure you are not running something else in the loop or in the function because at the moment I can see no reason why you get a sluggish response from your GUI? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Are you sure you are not running something else in the loop or in the function because at the moment I can see no reason why you get a sluggish response from your GUI? :D

When I run the code you provided (modified to run the TestColors function twice in a row with different variables, which my program does) the delay on clicking x is between 1 second and about 6. It changes every time I test it. If I run the function only once in the loop, it exits fast... Can you see any reason why running the function twice back to back would cause problems?

Thanks for helping....

Mich.

Edited by Mich9874
Link to comment
Share on other sites

  • Moderators

Mich9874,

What does the timer return and how big is your scanned area? You see the values in the bottom SciTE window. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ive found this make a huge difference in performance

_DwmEnable(False)
 
Func _DwmEnable($WhatToDo)
DllCall("dwmapi.dll", "long", "DwmEnableComposition", "uint", $WhatToDo)
EndFunc

cant remeber who i got it from but thanks to them not me if it helps

seb

GC - Program to rapidly manipulate DNA SequencesRotaMol - Program to measure Protein Size
Link to comment
Share on other sites

Mich9874,

What does the timer return and how big is your scanned area? You see the values in the bottom SciTE window. :D

M23

The scanned area is 1733 x 1021 and the timing is ~80 for one function call per loop and ~150 for two. With one function call per loop the program exits reasonably fast, with two it takes a considerably longer time.

With the function sebgg suggested (thankyou!!!!) the timing changes to ~8 for one function call and ~14 for two! A ten fold increase in performance! Wow!

Mich.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...