Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Get or Read Pixel from Memory UDF - PixelGetColor .au3


  • Please log in to reply
55 replies to this topic

#41 Malkey

Malkey

  • Active Members
  • PipPipPipPipPipPip
  • 1,496 posts

Posted 12 May 2009 - 02:06 AM

_PixelGetColor_Manadar

Here is a working version of the example first post.

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








#42 dexto

dexto

    Polymath

  • Active Members
  • PipPipPipPip
  • 240 posts

Posted 12 May 2009 - 12:17 PM

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 then AutoIT.

#43 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,730 posts

Posted 12 May 2009 - 12:42 PM

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

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.


#44 Cynagen

Cynagen

    Seeker

  • Active Members
  • 37 posts

Posted 18 May 2009 - 05:47 AM

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, 19 May 2009 - 02:08 AM.

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.

#45 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 26 July 2009 - 02:10 AM

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

#46 Manadar

Manadar

         

  • MVPs
  • 10,773 posts

Posted 27 July 2009 - 04:57 PM

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.

#47 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 28 July 2009 - 01:14 PM

OH NOES!

Well I found another that was pretty similar... >_<

Thanks anyways!

#48 Manadar

Manadar

         

  • MVPs
  • 10,773 posts

Posted 22 August 2009 - 11:38 AM

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, 22 August 2009 - 12:00 PM.


#49 Archon

Archon

    Seeker

  • Active Members
  • 9 posts

Posted 19 February 2010 - 04:39 PM

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:

#50 dexto

dexto

    Polymath

  • Active Members
  • PipPipPipPip
  • 240 posts

Posted 26 February 2010 - 09:42 AM

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, 26 February 2010 - 09:43 AM.

Too lazy for anything other then AutoIT.

#51 newbie210

newbie210

    Seeker

  • Active Members
  • 17 posts

Posted 14 April 2012 - 05:45 AM

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


#52 Manadar

Manadar

         

  • MVPs
  • 10,773 posts

Posted 16 April 2012 - 08:39 AM

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.

#53 Jappers

Jappers

    Seeker

  • New Members
  • 1 posts

Posted 13 September 2012 - 11:27 AM

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

#54 au3ForMe

au3ForMe

    Seeker

  • Normal Members
  • 4 posts

Posted 07 May 2013 - 07:21 AM

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, 07 May 2013 - 07:22 AM.


#55 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,730 posts

Posted 07 May 2013 - 08:52 PM

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, 07 May 2013 - 08:52 PM.

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.


#56 xekon

xekon

    Seeker

  • Active Members
  • 17 posts

Posted 14 December 2013 - 09:51 AM

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users