Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Help finding known pixels in an unknown location

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
thenewguy
Grandmaster Cheater
Reputation: -1

Joined: 04 Jun 2006
Posts: 972

PostPosted: Mon Oct 08, 2007 6:19 am    Post subject: Help finding known pixels in an unknown location Reply with quote

Trying to find an easier way to location the location of a set of known pixels. Pixel range is about 5x15 and can be easily converted to a bitmap to use as a compare. Looking for a way to easily find the pixels and return the location of.

2 methods I've used to do this:
1) Take the window and cut off some of the top/the bottom and the sides to reduce the area I have to search in. Then starting in the top left of what's left go 1 pixel to the right and test. Repeat till you reach the right side then go down 1 pixel and start again from the left. When I find 3 pixels of the same color in a row I then send that location. I've later changed it to search by 4(1, 5, 9, 13,,,,) and if I find 1 pixel that matches I then check the right/left of it. If either the right/left are the same as well I check right/left once more to be sure then send that location. Very involved and considering I'm only trying to do this to make a bot more simple, this is far from simple.

2)Kind of the same method as described above except using recursion instead. It's really no different except it does seems to find a valid target quicker since it's covering more of the top left of the screen and spanning out where the other one just scans all of the top then goes down to repeat.

Any ideas, thoughts or pointers would be greatly appreciated.
Back to top
View user's profile Send private message
TerryDonahugh
Master Cheater
Reputation: 0

Joined: 12 Sep 2007
Posts: 412
Location: .nl

PostPosted: Mon Oct 08, 2007 8:38 am    Post subject: Reply with quote

What is this for?

In case you can do exact matching this problem is not that hard. If your template and source images are small enough a naive exhaustive search should be fast enough. There are a lot of tricks to speed this up though.

Here is an idea I whipped up:

I <- 0
J <- 0

Take a N pixel horizontal segment from your source image starting at position I,J.

Compare this segment against all rows in your template image. If row K of your template matches, you have a high probability that the whole template matches. Set J <- J -K and compare the rest of the scanlines to validate this.

If there is no match set I <- I+1.

If you reached the end of the row set J <- J + M

_________________
Hello? Mule Farm
Back to top
View user's profile Send private message Send e-mail
thenewguy
Grandmaster Cheater
Reputation: -1

Joined: 04 Jun 2006
Posts: 972

PostPosted: Mon Oct 08, 2007 10:43 am    Post subject: Reply with quote

well, the pixel constant that I'm comparing is 7x25,, lets say. On the screen there maybe be many, there may be none. Of the 7x25,, all the pixels aren't the same so taking a horizontal segment sounds like a good idea but if there is the 7x25 near the segment and it gets cut in half, that would then defeat the purpose since it would never match. of the 7x25 there was 1 pixel row that was the exact same color, at least in the middle like 1x7. I was using that as my basis to search but still had to go pixel by pixel, skipping some to increase speed. sounds like there really isn't an easy way to do this in C++ then is there? I was hoping to find something like pixelsearch for autoit.
Back to top
View user's profile Send private message
TerryDonahugh
Master Cheater
Reputation: 0

Joined: 12 Sep 2007
Posts: 412
Location: .nl

PostPosted: Mon Oct 08, 2007 12:19 pm    Post subject: Reply with quote

thenewguy wrote:
well, the pixel constant that I'm comparing is 7x25,, lets say. On the screen there maybe be many, there may be none. Of the 7x25,, all the pixels aren't the same so taking a horizontal segment sounds like a good idea but if there is the 7x25 near the segment and it gets cut in half, that would then defeat the purpose since it would never match. of the 7x25 there was 1 pixel row that was the exact same color, at least in the middle like 1x7. I was using that as my basis to search but still had to go pixel by pixel, skipping some to increase speed. sounds like there really isn't an easy way to do this in C++ then is there? I was hoping to find something like pixelsearch for autoit.


You have to clip in the cases near the edges of the screen. There is no easy way in C++, but as I said before even the naive way of searching should not be that slow if implemented properly.

_________________
Hello? Mule Farm
Back to top
View user's profile Send private message Send e-mail
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Mon Oct 08, 2007 1:21 pm    Post subject: Reply with quote

Is your problem basically searching for a pattern match in a 2D array? If so, 4 nested loops can do the job:

Code:
int R, C, M, N;
int[] [] b = new int [R] [C];   //int array of RxC, source image, big
int[] [] s = new int [M] [N];   //int array of MxN, pattern, small
int x, y;                       //upper left corner of the first match
int cnt;

for (int i = 0 ; i < R - M ; i++)  // loop through the source image
    for (int j = 0 ; j < C - N ; j++)           //within bounds
        for (int a = 0 ; a < M ; a++) // loop through pattern
        {
            cnt = 0;
            for (int b = 0 ; b < N && b [i + a] [j + b] == s [a] [b] ; b++)
            {
                cnt++;      //increase number of matched in current row
                if (a == M - 1 && b == N - 1)   //matched last pixel, found
                {
                    x = i;      //stores location
                    y = j;
                }
            }

            if (cnt != N - 1) // if not all matched, discard
                a = M;
        }

It's in Java but should be easy to convert to C++. I just typed it up without testing, so there might be some bugs. It sets the variables x and y as the location of the last found matching pattern. If you want to find all, put the results in an array.

_________________

Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for?
Back to top
View user's profile Send private message
thenewguy
Grandmaster Cheater
Reputation: -1

Joined: 04 Jun 2006
Posts: 972

PostPosted: Mon Oct 08, 2007 2:41 pm    Post subject: Reply with quote

TerryDonahugh wrote:
You have to clip in the cases near the edges of the screen. There is no easy way in C++, but as I said before even the naive way of searching should not be that slow if implemented properly.


thanks =) looks like I can't get any better off then I already am =\ kinda sucks but oh well. You never know until you try/ask.

DeltaFlyer:
I've done it with 2 loops. 1 for x, 1 for y. I've also done it with recursion. I was just hoping there was an easier way but I'm guessing there isn't. Thanks for the suggestion tnough =)
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Oct 08, 2007 2:43 pm    Post subject: Reply with quote

AutoIT does Pixel detection by pixel CRC's. You could look at the source of AutoIT (parts are open source, not sure if the pixel stuff is or not) and see if that would be of any help.

http://www.autoitscript.com/autoit3/files/archive/autoit/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites