Sign in to follow this  
Followers 0
XIXI

Pixels who we all love and adore.

11 posts in this topic

Okey this is whats up. I need to read 200+ diffrent cordinates of pixels, using pixelgetcolor for each, the problem is that I need to do this within one second and inbetween add alot of conditions and calculations.

Local $starttime = _Timer_Init()
    For $i = 0 To 500
    PixelGetColor(10,10)
    Next
$time = _Timer_Diff($starttime)

This takes 10 seconds. So was wondering if theres some other way to get around this and speed this up greatly?

Sorry for not being active on the forums.

Share this post


Link to post
Share on other sites



Have a look at this:

#include <WinApi.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>

Local $hDll, $vDC, $vRegion, $aPos, $sColor, $colRGB
$hDll = DllOpen("gdi32.dll")

$vDC = _WinAPI_CreateCompatibleDC(0)

$vRegion = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, False)
_WinAPI_SelectObject($vDC, $vRegion)

; click left mouse button to exit
While Not _IsPressed(0x01)
    $aPos = _PixelGetColor_MouseGetPos()
    $sColor = DllCall($hDll, "int", "GetPixel", "int", $vDC, "int", $aPos[0], "int", $aPos[1])
    ; Added next line for RGB display
    $colRGB = "0x" & StringRegExpReplace(Hex($sColor[0], 6), "(.{2})(.{2})(.{2})", "\3\2\1")
    ToolTip("The color under your mouse is: " & $colRGB, $aPos[0] + 3, $aPos[1] + 3, "_PixelGetColor_GetPixel return", $hDll)
WEnd

_WinAPI_DeleteObject($vRegion)

_WinAPI_ReleaseDC($vDC, $hDll)
DllClose($hDll)


Func _PixelGetColor_MouseGetPos()
    Return MouseGetPos()
EndFunc   ;==>_PixelGetColor_MouseGetPos

http://www.autoitscript.com/forum/index.php?showtopic=62681

Share this post


Link to post
Share on other sites

I had a feeling you would answer. Will read up! >_

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Edit: I'll just go with what you gave me and make my own functions.

Edited by XIXI

Share this post


Link to post
Share on other sites

Edit: I'll just go with what you gave me and make my own functions.

I built a nice UDF around the method once but I accidentally lost it permanently.

Share this post


Link to post
Share on other sites

anyone got any speed / performance comparisons between the two different methods out of curiosity?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I found the old _PixelGetColor UDF and reuploaded it:

http://www.autoitscript.com/forum/index.php?showtopic=63318

By the way, there is a problem with native PixelGetColor and Vista + Aero. You are probably experiencing it too; The solution for this is to specify a window handle in the PixelGetColor parameters but it will not be as fast as the UDF.

Some performance testing with latest UDF:

In a 10x10 field:

Native: 2198.66336
UDF   : 36.03904
Edited by Manadar

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Manadar, i have dl'ed the _PixelGetColor.au3 with the example and speed test. (in the speedtest) i noticed their is a tooltip() call in the CaptureNative() loop and after removing the tooltip i see CaptureNative out performing the UDF on 10x10 and 100x100, am i messing something up here?

Edited by laffo16

Share this post


Link to post
Share on other sites

Manadar, i have dl'ed the _PixelGetColor.au3 with the example and speed test. (in the speedtest) i noticed their is a tooltip() call in the CaptureNative() loop and after removing the tooltip i see CaptureNative out performing the UDF on 10x10 and 100x100, am i messing something up here?

I missed the tooltip. It definitely affected the test I posted before. I reuploaded the example but now without the tooltip.

The speed of native PixelGetColor depends on your OS too. I'm using a Vista machine and these are the results I am getting (time in ms - without the tooltip):

Starting test in field (0,0) to (10,10)
Native: 2198.66336
UDF   : 36.03904

Starting test in field (0,0) to (100,100)
Native: 194312.06288
UDF   : 298.4992

Other OS may behave differently.

Just remember that speed is not the only benefit of using this method.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I missed the tooltip. It definitely affected the test I posted before. I reuploaded the example but now without the tooltip.

The speed of native PixelGetColor depends on your OS too. I'm using a Vista machine and these are the results I am getting (time in ms - without the tooltip):

Starting test in field (0,0) to (10,10)
Native: 2198.66336
UDF   : 36.03904

Starting test in field (0,0) to (100,100)
Native: 194312.06288
UDF   : 298.4992

Other OS may behave differently.

Just remember that speed is not the only benefit of using this method.

Hehe thank you for the answers and tests, but I'm soon done with my project and the only thing missing is....THE AI. The UDF is not really needed unless your programming with other people than yourself which I'm not and I don't expect to share the code anyway.

About my post with EDIT:, I was gonna ask you for the UDF but I just went on and continued without it.

Edited by XIXI

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Some tags for future searchers? >_<

PixelSearch, Pixel Search, Compare Hex, Compare colors

I couldn't find this fast enough so made my own, maybe not the best. But hey it works :(

#include <Color.au3>

Func CompareHex($hex, $compareTo, $level)

    If (Abs(_ColorGetRed($hex) - _ColorGetRed($compareTo)) < $level) And _
            (Abs(_ColorGetGreen($hex) - _ColorGetGreen($compareTo)) < $level) And _
            (Abs(_ColorGetBlue($hex) - _ColorGetBlue($compareTo)) < $level) Then
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>CompareHex

If CompareHex(0x000000, 0x090505, 10) Then
    ConsoleWrite("WORKS")
Else
    ConsoleWrite("NO")
EndIf
Edited by XIXI

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