Jump to content

Recommended Posts

Posted

_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

;
Posted

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)

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.

  • 2 months later...
Posted

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

  • 4 weeks later...
  • 5 months later...
Posted

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:

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
  • 2 years later...
Posted

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
Posted

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.

  • 4 months later...
  • 7 months later...
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
  • Moderators
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

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.

  • 7 months later...
Posted

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

  • 5 years later...
Posted

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?

  • 2 years later...
Posted

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 :) 

 

#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

 

Posted

Sorry, didnt updated the code for increased runloops but for the speedrun it was already changed. Can't even edit :). Sad story.

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
  • Recently Browsing   0 members

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