Sign in to follow this  
Followers 0
AU3Newbie

How to make it faster when using pixelgetcolor?

13 posts in this topic

As we all know from the help file,PixelChecksum function has been upgrated to a faster speed,while PixelGetColor hasn't.

When I get every Pixelcolor from (0,0)~(1024,768) using 2 FOR sentences, it took me more than 30 minutes to finish getting all DATAs with my somehow superPC.If I need to get the such DATAs every second,obviously it cann't do.

But the Pixelchecksum function is so fast. I've tested it,it's true,very fast indeed!

It's said in the help file that the function of PixelChecksum used to be "extremely slow,and now significantly faster",that is to say that we can also make our getpixelcolor more faster too.

What shAll I do when I need to get every pixelcolor from (0,0)~(1024,768) and compare every pixelcolor each second?

Any advice?Thank you!

Share this post


Link to post
Share on other sites



As we all know from the help file,PixelChecksum function has been upgrated to a faster speed,while PixelGetColor hasn't.

When I get every Pixelcolor from (0,0)~(1024,768) using 2 FOR sentences, it took me more than 30 minutes to finish getting all DATAs with my somehow superPC.If I need to get the such DATAs every second,obviously it cann't do.

But the Pixelchecksum function is so fast. I've tested it,it's true,very fast indeed!

It's said in the help file that the function of PixelChecksum used to be "extremely slow,and now significantly faster",that is to say that we can also make our getpixelcolor more faster too.

What shAll I do when I need to get every pixelcolor from (0,0)~(1024,768) and compare every pixelcolor each second?

Any advice?Thank you!

I'm curious, why in the world you would need so many pixels vs... just using PixelCheckSum itself.

[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

I'm curious, why in the world you would need so many pixels vs... just using PixelCheckSum itself.

I found such codes in C++,and it runs normally.

I thought I can traslate such codes to AU3,while it found later that it can do nothing only for the speed.

This is a program to help finding everything on HDC every second and analasys it,then give a good solution to get out of the trouble in the game.And only a 500*300-Pixel*Pixel-Area lasts a long time.

Can the code below be modified to a faster speed?

For $x=0 to 500
For $y=0 to 300
$var[$i]=getpixelcolor(x,y)
next
next

ThANK YOU.

Share this post


Link to post
Share on other sites

I found such codes in C++,and it runs normally.

I thought I can traslate such codes to AU3,while it found later that it can do nothing only for the speed.

This is a program to help finding everything on HDC every second and analasys it,then give a good solution to get out of the trouble in the game.And only a 500*300-Pixel*Pixel-Area lasts a long time.

Can the code below be modified to a faster speed?

For $x=0 to 500
For $y=0 to 300
$var[$i]=getpixelcolor(x,y)
next
next

ThANK YOU.

Don't know what that code is you are showing.

How about we do a reality check. 500 by 300 area is 150,000 loops. I doubt seriously you are managing (properly anyway) 150,000 different situations.

What are you looking for specifically in that area, and maybe I/we can offer an alternative.


[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

Don't know what that code is you are showing.

How about we do a reality check. 500 by 300 area is 150,000 loops. I doubt seriously you are managing (properly anyway) 150,000 different situations.

What are you looking for specifically in that area, and maybe I/we can offer an alternative.

To be honest,it's a tool for playing Internet billiards.

For example in playing America pocket billiard,all the 16 balls are rolling all the time.Firstly the tool should find the CVE BALL on the table,then it should find the object-ball on the table,all this should find in each pixel.The pocket are easyly to be found because they're in fixed positions.We should at least find such three positions so as to decide where to move our mouse to,how to pushstroke the object-ball, calculate the position where the Cue-ball will go and draw the lines on table.

This software not only can I help to do position-exercise,but also can help me out of some repeatly works,I've a good solution in theory but cannot put it into practice in Au3.So my tool only can help me to draw some lines onto the table and it has little use.I know every stamped color of each ball,I should only find it on the table every time to calculate where to pushstroke.Only this.

Any help will be appreciated.

Share this post


Link to post
Share on other sites

To be honest,it's a tool for playing Internet billiards.

For example in playing America pocket billiard,all the 16 balls are rolling all the time.Firstly the tool should find the CVE BALL on the table,then it should find the object-ball on the table,all this should find in each pixel.The pocket are easyly to be found because they're in fixed positions.We should at least find such three positions so as to decide where to move our mouse to,how to pushstroke the object-ball, calculate the position where the Cue-ball will go and draw the lines on table.

This software not only can I help to do position-exercise,but also can help me out of some repeatly works,I've a good solution in theory but cannot put it into practice in Au3.So my tool only can help me to draw some lines onto the table and it has little use.I know every stamped color of each ball,I should only find it on the table every time to calculate where to pushstroke.Only this.

Any help will be appreciated.

Ha!! Billiards, now you're talking my language!!

To be honest though, I still think you are doing it the hard way. What I would do, is get a CheckSum of each ball, so that I can identify them easily by their sums. All of them in the same region, so if I do the Cueball 10 x 10, I'll do 1 - 15 the same way.

After I've gotten my checksums, and stored them in an array of some sort, I'd then use PixelSearch() to find something unique on the ball I'm looking for. Now every ball is likely to have the same pixel color somewhere within it that the CueBall does, so that's where we will use the Checksums, checking Region from Top to Bottom, and moving x and y accordingly.

I believe Larry did something like this not too long ago, but for the life of me I can't remember what he called it to find it.... (Nevermind... Took 5 minutes to find it: http://www.autoitscript.com/forum/index.ph...st&p=134394 )

His is a good example of what I'm talking about.


[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

Ha!! Billiards, now you're talking my language!!

.....

I believe Larry did something like this not too long ago, but for the life of me I can't remember what he called it to find it.... (Nevermind... Took 5 minutes to find it: http://www.autoitscript.com/forum/index.ph...st&p=134394 )

His is a good example of what I'm talking about.

My old code is:

const int m_ClearLeft=30,m_ClearTop=90,m_ClearBottom=395,m_ClearRight=600;
        private void ChangeToMemory()
        {
            for (int y=m_ClearTop; y<m_ClearBottom; y++) 
            { 
                for (int x=m_ClearLeft; x<m_ClearRight; x++)
                {
                    m_ImageArgb[x,y,0]=m_Bitmap.GetPixel(x,y).ToArgb();
                    m_ImageArgb[x,y,1]=m_Bitmap.GetPixel(x,y).R;
                    m_ImageArgb[x,y,2]=m_Bitmap.GetPixel(x,y).G;
                    m_ImageArgb[x,y,3]=m_Bitmap.GetPixel(x,y).B;
                }
            }
        }

But what you provided to me seems more helpful,authough i cannot understand it at once.

Thank you,I'll try~~~

Share this post


Link to post
Share on other sites

A silly question, if it works for you in the old code, why not just make it a dll and call it from autoit returning an array?


[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

A silly question, if it works for you in the old code, why not just make it a dll and call it from autoit returning an array?

You're sure you can return an array with DllCall? The only way I could imagine is to return a pointer to a data structure and use that pointer to "create" a DllStruct which you can then access with DllStructGetData().

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

You're sure you can return an array with DllCall? The only way I could imagine is to return a pointer to a data structure and use that pointer to "create" a DllStruct which you can then access with DllStructGetData().

Cheers

Kurt

No Kurt, I'm not sure you can to be honest... I'm especially not sure at 7:15 in the morning when I haven't seen the back of my eyelids all night long.

I'd probably do the same thing I usually do in AutoIt though... Have the return value a string and then Value & Null Char etc... and StringSplit() the return str.

I'd like to see an example of what you are saying though.


[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

No Kurt, I'm not sure you can to be honest... I'm especially not sure at 7:15 in the morning when I haven't seen the back of my eyelids all night long.

I'd probably do the same thing I usually do in AutoIt though... Have the return value a string and then Value & Null Char etc... and StringSplit() the return str.

I'd like to see an example of what you are saying though.

After testing I found that the code you provided cannot always got what it should get.Maybe three 10th or little it can get what it should get.

...

If you like billiard too,I've some useful C code for you.Although it's incomplete at hand,it's still more than 700 lines and seems useful.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

After testing I found that the code you provided cannot always got what it should get.Maybe three 10th or little it can get what it should get.

...

I don't know how accurate this is going to be (or even if it will work)... I tore apart one of my other functions to do it.

You obviously got my attention with pool, because I never comment anything (bad habit of mine).

#cs

$nNumArray is the number of the array you want to search for

$xPCSumWidth is the width of the are of the object you want to find that you go the checksum for

$yPCSSumHeight is the height of the are of the object you want to find that you go the checksum for

$xTop is the starting position x value of the area to search

$yTop is the starting position y value of the area you want to search

$xBottom is the ending position x value of the area you want to stop the search at

$yBottom is the ending position y value of the area you want to stop the search at

$nColor is the unique color or just color in the left hand upper corner of the object to find

$iShade is the shade difference from the color to find if any

$iStep is the pixels you want to skip in the search in PixelSearch

$iPCSStep is the pixels you want to skip in the search in PixelCheckSum

The return value if it is successful is an Array ([0]= X, [1] = Y) the Top Left X and Y coordinate of the object found

The return value if isn't successuful is nothing.

#ce

Func _FindObject($nNumArray, $xPCSumWidth, $yPCSumHeight, $xTop, $yTop, $xBottom, $yBottom, $nColor, $iShade = 0, $iStep = 1, $iPCSStep = 1)
    ;Below is an array of all the values you've accumilated for each ball 0 - 15
    Local $aObjectValue[16] = [293902390,19393003,393939301,3939330390,393933092,355830220,393023818,4930392093,1103902, _
                183230930239, 390239023, 119393094, 933910019, 55939309, 39495059];PixelCheckSum values for each ball [0] is the cue ball
    Local $aObjectFound[2]
    Local $aPix, $nYAdd
    For $xCC = $xTop To $xBottom
        $nYAdd = 0
        While $nYAdd <= $yBottom
            $aPix = PixelSearch($xCC, $yTop + $nYAdd, $xCC, $yBottom, $nColor, $iShade, $iStep)
            If IsArray($aPix) = 0 Then ExitLoop;If our color wasn't found on this line the exitloop so we can go to the next X position
            ;May Need to adjust $xCC ... This is where the pixel you want is found, I'd probably go for the Top Left corner pixel (hopefully unique)
            ;But doubtful if it's the white cue ball.
            If PixelChecksum($xCC, $yTop + $nYAdd, $xCC + $xPCSumWidth, $yBottom + $yPCSumHeight, $iPCSStep) = $aObjectValue[$nNumArray] Then
                $aObjectFound[0] = $xCC
                $aObjectFound[1] = $yTop + $nYAdd
                Return $aObjectFound
            EndIf
            $nYAdd += ($aPix[1] - $yTop) + 1;Move down 1 for the next search on the next line "same x position"
        WEnd
    Next
    Return SetError(1, 0, '')
EndFunc
I don't even know if it works, but the theory should. And it has to be faster than what you are already doing.

If you like billiard too,I've some useful C code for you.Although it's incomplete at hand,it's still more than 700 lines and seems useful.

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

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

Edit:

Separated the comments, I guess our code tags don't recognize them.

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

I just cannot believe my eyes in reading the topics that your are so good not only at program but at pool,You are such an excellent genius!I couldn't help admiring you,my friend,SmOke_N! :D:D:)

!

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