Malkey Posted May 12, 2009 Posted May 12, 2009 _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 ;
dexto Posted May 12, 2009 Posted May 12, 2009 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)
Moderators SmOke_N Posted May 12, 2009 Moderators Posted May 12, 2009 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.
Cynagen Posted May 18, 2009 Posted May 18, 2009 (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. Edited May 19, 2009 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.
BrettF Posted July 26, 2009 Posted July 26, 2009 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 Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
jvanegmond Posted July 27, 2009 Author Posted July 27, 2009 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. github.com/jvanegmond
BrettF Posted July 28, 2009 Posted July 28, 2009 OH NOES! Well I found another that was pretty similar... >_< Thanks anyways! Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
jvanegmond Posted August 22, 2009 Author Posted August 22, 2009 (edited) I found a old version of the UDF. In my PM box. O.oAttached it to the forum this time.Edit: Readded the $hDll parameter. Edited August 22, 2009 by Manadar github.com/jvanegmond
Archon Posted February 19, 2010 Posted February 19, 2010 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 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?
dexto Posted February 26, 2010 Posted February 26, 2010 (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 ;DI'm using XP windows.PixelGetColor...Manadar, you UDF should speed up this. From example it speeds almost 9x 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? I did not have a pressing need to create such DLL myself, only suggested that that could be a viable solution. Edited February 26, 2010 by dexto
newbie210 Posted April 14, 2012 Posted April 14, 2012 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
jvanegmond Posted April 16, 2012 Author Posted April 16, 2012 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. github.com/jvanegmond
Jappers Posted September 13, 2012 Posted September 13, 2012 I wonder if you can use this UDF to an image file. If so, how? Thanks for the support.
au3ForMe Posted May 7, 2013 Posted May 7, 2013 (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 May 7, 2013 by au3ForMe
Moderators SmOke_N Posted May 7, 2013 Moderators Posted May 7, 2013 (edited) The GetPixelRaw() func returns BGR color: ;Function Header: ;Description ...: Gets a pixel color from the DC in decimal BGR. PixelGetColor() returns RGB. Edited May 7, 2013 by SmOke_N 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.
xekon Posted December 14, 2013 Posted December 14, 2013 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
Yirrlaar Posted July 10, 2019 Posted July 10, 2019 Don't mean to bring back the dead, but what if you already have you're "_ScreenCapture_Capture" file and you want to load that file into memory and search?
Texos Posted May 6, 2022 Posted May 6, 2022 Hey, just had to register to put another way in here :). It is for sure an old old thread, but the "core" will not change so let's put this here expandcollapse popup#include <Misc.au3> #include <ScreenCapture.au3> #include <GDIPlus.au3> #include-once $init=TimerInit() For $x=1 To 4 For $y=1 To 10 PixelGetColor($x,$y) Next Next Consolewrite("100%: " & TimerDiff($init) & @crlf & "Average: " & TimerDiff($init)/($x * $y) & @CRLF) $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 Consolewrite("100%: " & TimerDiff($init) & @crlf & "Average: " & TimerDiff($init)/($x * $y) & @CRLF) Local $iWidth = 4, $iHeight = 10 _GDIPlus_Startup() $hBMP = _ScreenCapture_Capture("", 0, 0, 320, 240) $pBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) $tBitmapData = _GDIPlus_BitmapLockBits($pBitmap, 0, 0, $iWidth, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32ARGB) $tPixel = DllStructCreate("dword[" & $iWidth * $iHeight & "];", DllStructGetData($tBitmapData, "Scan0")) $init=TimerInit() For $iX = 0 To $iWidth - 1 For $iY = 0 To $iHeight - 1 Hex(BitAND(DllStructGetData($tPixel, 1, $iY * $iWidth + $iX + 1), 0xFFFFFF), 6) Next Next Consolewrite("100%: " & TimerDiff($init) & @crlf & "Average: " & TimerDiff($init)/($iWidth * $iHeight) & @CRLF) _GDIPlus_BitmapUnlockBits($pBitmap, $tBitmapData) _GDIPlus_BitmapDispose($pBitmap) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() I've also increased the loops to have a better result 🧐 100%: ~79990.1388ms Average: ~19.3166280608549ms 1060 times faster: 100%: ~75.4109ms Average: ~0.0182133542622555ms 9452 times faster 100%: ~8.4622ms Average: ~0.00211755ms
Texos Posted May 6, 2022 Posted May 6, 2022 Sorry, didnt updated the code for increased runloops but for the speedrun it was already changed. Can't even edit . Sad story.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now