Sign in to follow this  
Followers 0
jvanegmond

Get or Read Pixel from Memory UDF - PixelGetColor .au3

56 posts in this topic

_PixelGetColor_Manadar

Here is a working version of the example first post.

_PixelGetColor_Malkey

;
#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

;

Share this post


Link to post
Share on other sites



To undertake something like that in C or C++ will take some time... I don't think a lot of people can offer this kind of a donation. (hence AutoIt)


Too lazy for anything other than AutoIT.

Share this post


Link to post
Share on other sites

Ya'll may want to look at this instead of using string functions to convert color modes:

http://www.autoitscript.com/forum/index.ph...st&p=534401


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#44 ·  Posted (edited)

Somebody needs to make a Guitar Hero bot with this. =]]] I could write it pretty easily but my computer can't run the game :) If somebody were to get me the pixel coords and hex colors of the note however, I could write the routines petty easily/quickly.

Edit: I would also need what keys to send to for the frets and strum, etc.

I wrote something like that for DJ Max Portable 2 on the PSP. I'm running RemoteJoyLite v0.19 on my PSP and computer, so I can pull a live view of the screen to the PC. I'm capturing a small region where there's less clutter from flashing stuff in the display, so I can spot the notes and hit them. It requires I have the game run the notes down the screen at 3x normal speed, but it's working. It's getting a lot of C grades on the game by itself, Bs when it's lucky, gotten an A once or twice, and a lot of Ds. It's just a proof of concept, but I still wanted to also ask OP, is there any way we could make this capture method faster? It only seems to miss the notes because of the small small section I have to target in order to not get false-hits because of flashy stuff. I'm going to try this with DJ Max Fever and DJ Max Clazziquai Edition and see if I can get better results with those.

EDIT: Actually I found out where my bottleneck was, and I've since corrected it. I'm just waiting on a video camera so I can record this thing in action. I'm working on correcting the accuracy right now, but I do have a perfectly functional proof of concept that on any given day... could kick my butt at the game. :party:

Edited by Cynagen

Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

Share this post


Link to post
Share on other sites

MANADAR! Linkie plz!

Kthxbai!

Probably makes no sense to some people, so translation:

Hi Manadar!

I can't find a link for this. Can you please post it?

Thanks,

Brett

Share this post


Link to post
Share on other sites

Sorry, Brett. In the 7000 AutoIt files that I have I could not find this UDF anymore.

I don't have any other places to search for this; All lost in a hard drive crash.

Share this post


Link to post
Share on other sites

#48 ·  Posted (edited)

I found a old version of the UDF. In my PM box. O.o

Attached it to the forum this time.

Edit: Readded the $hDll parameter.

Edited by Manadar

Share this post


Link to post
Share on other sites

I dont know why, but this UDF dont speed up taking pixel colours :( I make tests on area about 280x220. My computer is slow so don't be shock times ;D

I'm using XP windows.

PixelGetColor

>Running:(3.3.4.0):C:\Programy\AutoIt3\autoit3.exe "D:\_Main.au3"

czas: 9041.1272941114 //CPU taking program

czas: 7494.57486915236 //CPU taking program

czas: 8105.26645146241 //CPU taking program

czas: 8200.67047627562 //CPU taking program

czas: 7605.61579753851 //CPU taking program

czas: 3343.90516113081 //win

czas: 1267.01158946179 //win

czas: 1223.60830775979 //win

czas: 1227.73620669666 //win

czas: 1305.64052135118 //win

czas: 8271.13418046148 //CPU taking program

czas: 7382.12482312696 //CPU taking program

czas: 1237.24579520582 //win

__PixelGetColor_GetPixelRaw

>Running:(3.3.4.0):C:\Programy\AutoIt3\autoit3.exe "_Main.au3"

czas: 6067.85443401326 //win

czas: 4562.02562057468 //win

czas: 4398.57607600966 //win

czas: 15460.6406680179 //CPU taking program

czas: 15298.6519236383 //CPU taking program

czas: 15242.1986593268 //CPU taking program

czas: 14585.1193377929 //CPU taking program

czas: 9020.23776764924 //win

Manadar, you UDF should speed up this. From example it speeds almost 9x :lol: Whats going up?

So is there way to speed up this? Much speed up, to take under 1s on CPU used by other program, not 7 :/

Maybe DLL's from C++ about was talking dexto. Where that files I can find? :mellow:

Share this post


Link to post
Share on other sites

#50 ·  Posted (edited)

I dont know why, but this UDF dont speed up taking pixel colours :( I make tests on area about 280x220. My computer is slow so don't be shock times ;D

I'm using XP windows.

PixelGetColor

...

Manadar, you UDF should speed up this. From example it speeds almost 9x :lol: Whats going up?

So is there way to speed up this? Much speed up, to take under 1s on CPU used by other program, not 7 :/

Maybe DLL's from C++ about was talking dexto. Where that files I can find? :mellow:

I did not have a pressing need to create such DLL myself, only suggested that that could be a viable solution.

Edited by dexto

Too lazy for anything other than AutoIT.

Share this post


Link to post
Share on other sites

First thanks for the great script, however there is a small error:

In the Speedtest.au3 and also the example.au3 the

_PixelGetColor_CaptureRegion($vDC, 0,0,$xmax,$ymax,$hDll)

function is missing the $fCursor argument in your code.

It should be _PixelGetColor_CaptureRegion($vDC, 0,0,$xmax,$ymax,FALSE,$hDll)

Thanks Greg

Func CaptureUDF($xmax, $ymax)
$vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,$xmax,$ymax,FALSE,$hDll)
For $x = 0 to $xmax
  For $y = 0 to $ymax
   _PixelGetColor_GetPixelRaw($vDC, $x, $y, $hDll)
  Next
Next
_PixelGetColor_ReleaseRegion($vRegion)
EndFunc

Share this post


Link to post
Share on other sites

First thanks for the great script, however there is a small error:

In the Speedtest.au3 and also the example.au3 the

_PixelGetColor_CaptureRegion($vDC, 0,0,$xmax,$ymax,$hDll)

function is missing the $fCursor argument in your code.

It should be _PixelGetColor_CaptureRegion($vDC, 0,0,$xmax,$ymax,FALSE,$hDll)

Fixed this. Thanks.

Reuploaded new script.

Share this post


Link to post
Share on other sites

I wonder if you can use this UDF to an image file. If so, how?

Thanks for the support.

Share this post


Link to post
Share on other sites

#54 ·  Posted (edited)

Why if im trying to use such example:

Func CaptureUDF($xmax, $ymax)
Local $var1, $var2
$vRegion = _PixelGetColor_CaptureRegion($vDC, 0, 0, $xmax, $ymax, False, $hDll)
For $x = 0 To $xmax
For $y = 0 To $ymax
$var1 = "0x"&Hex(PixelGetColor($x, $y))
$var2 = "0x"&Hex(_PixelGetColor_GetPixelRaw($vDC, $x, $y, $hDll))
If $var1<>$var2 Then MsgBox(0,"Error "&$x&", "&$y,$var1&"<>"&$var2)
Next
Next
_PixelGetColor_ReleaseRegion($vRegion)
EndFunc ;==>CaptureUDF

The result in same pixel from the PixelGetColor and _PixelGetColor_GetPixelRaw is different?

Edited by au3ForMe

Share this post


Link to post
Share on other sites

#55 ·  Posted (edited)

The GetPixelRaw() func returns BGR color:

;Function Header:
;Description ...: Gets a pixel color from the DC in decimal BGR.

PixelGetColor() returns RGB.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

excellent script, and this example works for me:

#include <_PixelGetColor.au3>
#include <Misc.au3>

$init=TimerInit()
For $x=1 To 4
    For $y=1 To 10
        PixelGetColor($x,$y)
    Next
Next
MsgBox(0,"","100%: " & TimerDiff($init) & @crlf & "Average: " & TimerDiff($init)/($x * $y))

$hDll = DllOpen("gdi32.dll")
$vDC = _PixelGetColor_CreateDC($hDll)
$vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,320,240,$hDll)
$init=TimerInit()
For $x=1 To 4
    For $y=1 To 10
        _PixelGetColor_GetPixel($vDC, $x,$y, $hDll)
    Next
Next
MsgBox(0,"","100%: " & TimerDiff($init) & @crlf & "Average: " & TimerDiff($init)/($x * $y))

Also on page 2 there were some speed comparisons. The difference for me was a LOT more than those posted, this script speeds things up lightning quick.

PixelGetColor() Avg: ~12.3588 ms

_PixelGetColor_CreateDC() Avg: ~0.0331 ms

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