Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Pixel Matrix Search


  • Please log in to reply
31 replies to this topic
Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
I finally completed this script. It is like ImageSearch, but it doesn't require an image file and works better for me. It has 2 functions, GetMatrix & FindMatrix.
There is an example in the script to find a 3x3 matrix.

Note: For faster searching, make sure the first pixel of matrix is not abundant on the screen.

Script

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for sharing this. I know ImageSearch can be cumbersome to use, and PixelSearch can often be too crude. Your solution is a great compromise.

BoBo
  • Guests
  • Last active:
  • Joined: --
Hi Rajat :D
won't the following line (taken from your script) restrict it to a 800x600 screen resolution :?:

Result := FindMatrix(1,800,1,600,3,Matrix)

Thx for sharing it. 8)

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004

won't the following line (taken from your script) restrict it to a 800x600 screen resolution

yes it will. but its not hard-coded in the function, its just part of the example. i cud've restricted it to just the systray too.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
I might be dumb, but I don't quite understand what this is for.
If I execute the script and press F4, it returns me two values (coordinates?) - but what to do with these?

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
It searches for an 3x3 pixel color matrix on your screen. If you have pressed F4 with your mouse somewhere inside the 800x600 area of your screen. You should get back that position.
What the code does: It gets the matrix under your mouse pointer and starts to search for that matrix on your screen (the 800x600 upper left part). If it finds it it reports back the coordinates.
As Rajat said, it is faster then ImageSearch and it doesn't require an image.
You can use it to find a pattern (the 3x3 matix) on the screen if it unique. E.g. an icon, a picture or an item in a game.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
Oh, I see - thanks for the clarification!

rund
  • Guests
  • Last active:
  • Joined: --
its i fine script, but how can make it that my cursor jumps back
on that matrix
it shows me a little red dot and the scipt ends

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
just do a MouseMove at the received coordinates

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


j88chan
  • Guests
  • Last active:
  • Joined: --
hi,
i'm very impressed with this pixel matrix thing, but i'm hoping someone can help me out

once i find my 9 by 9 matrix, what code should i input for me to save it so i can refer to it later. i would like to save a bunch of 9 by 9 matrix's and just name them matrix1.bmp and matrix2.bmp and so on, so i can search the screen for the same matrix and do the required mouseclick.

also, if i increase the matrix size to say a 4x4, the image comparison would be better right?, but would it bog down the script too much?

GetMatrix(StartX,StartY,Dimension)
{
	Loop, %Dimension%
	{
		Loop, %Dimension%
		{
			PixelGetColor, Pix, %StartX%, %StartY%
			Matrix = %Matrix%|%Pix%
			StartX ++
		}
		
		StartY ++
		StartX -= %Dimension%
	}
	StringTrimLeft, Matrix, Matrix, 1
	Return %Matrix%
}

anyhelp is much appricated

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
with this script you can save the recd matrix in the script itself and it doesn't need a separate file. if you want to save .bmp files then u better use the imagesearch command instead of this script, as the recd matrix from this script is plain text and not an image.

the image finding would definitely be better with a bigger matrix. and just take care of the first pixel thing and you should be fine.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


j88chan
  • Guests
  • Last active:
  • Joined: --
thanks for the quick reply.

i have tried using image search, but so far no luck

my problem is i get a screen shot, crop out the selected image i want to search for and try it out. it will find the image by itself, meaning alone.

but it won't find the image in the screen shot without it being cropped. that is why i think i need to go the matrix way.

how do i save the matrix file, can i save the text of the matrix, and use it later?

not-logged-in-rajat
  • Guests
  • Last active:
  • Joined: --

how do i save the matrix file, can i save the text of the matrix, and use it later?


yes you can, that's the point!... just like you can define a control name for most apps in scripts, for apps which don't have recognisable controls can be automated this way and the pixel matrix for its control can be retrieved from the first function and saved in the script... later on the second function can find it and do button presses etc.

j8chan
  • Members
  • 2 posts
  • Last active: Jan 21 2010 05:36 PM
  • Joined: 11 Jul 2006
ok, i feel stupid, i've been trying this for a few hrs

please help me

i want to use the script you wrote. but instead of using the getmatrix sub function, i want to just define my matrix. i have tied some things, but i'm guessing it has to do with inputing the 9 pixels into a 3 by 3 array. i just can't do it, i'm dumb. this is my matrix in text.


0x000000|0x205D47|0x215E48|0x000000|0x1B5640|0x1C5741|0x000000|0x777777|0x18513C

can someone give me the 2-3 lines of code that replaces "getmatrix" for the matrix above. From there i should be able to continue the rest of the program

thanks

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
assuming that the matrix you posted is available on your screen, you can do this:

matrix = {your matrix}
Result := FindMatrix(1,A_ScreenWidth,1,A_ScreenHeight,9,matrix)
StringSplit, Result, Result, %A_Space%

now result1 & result2 contain the x & y coords of your target.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat