I believe I posted this question on the wrong forum. You guys might know more about ImageSearch.
So I have made an AHK script that detects an moving image. I now want it to check if an image is underneath it.
k::
ImageSearch, Px, Py, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, image1.bmp
If Errorlevel = 0
ImageSearch, Px, Py, [ Search underneath the location of which the first image was found ], image2.bmp
If Errorlevel = 0
... More code ...
The image1.bmp and image2.bmp can show up multiple times (and at the same time) on the screen. So if I search the entire screen for image1.bmp then image2.bmp might be located at the wrong location (since Errorlevel is still 0)
I have tried for hours to get this to work. I hope I made myself clear and that you can push me into the right direction
If image found search for image underneath it?
-
- Posts: 5
- Joined: 22 Jun 2017, 20:01
Re: If image found search for image underneath it?
Clarify "Underneath".
Given image A is @ x:10, y:10, w: 10, h: 10
Do you mean image B would be @ x:10, y: 10, w:10, h: 10 or @ x:10, y: 30, w: 10, h: 10
The former is not possible, the latter is.
Given image A is @ x:10, y:10, w: 10, h: 10
Do you mean image B would be @ x:10, y: 10, w:10, h: 10 or @ x:10, y: 30, w: 10, h: 10
The former is not possible, the latter is.
-
- Posts: 5
- Joined: 22 Jun 2017, 20:01
Re: If image found search for image underneath it?
Sorry for the late response.evilC wrote:Clarify "Underneath".
Given image A is @ x:10, y:10, w: 10, h: 10
Do you mean image B would be @ x:10, y: 10, w:10, h: 10 or @ x:10, y: 30, w: 10, h: 10
The former is not possible, the latter is.
@ x:10, y: 30, w: 10, h: 10 I'm unsure of how I would put that in my code. But isn't that exact coordinates? The image moves.
I am trying to find an image on the screen. And wherever the image is found. Scan slightly under that location. Image1 can be anywhere on the screen.
There isn't some kind of magic code to get ImageSearch "errorlevel = 0" location? I could do it with "MouseMove, %Px%, %Py%" and then locate mouse coordination. But I don't want the mouse to move, and it doesn't solve the problem of searching beneath that location. Sorry if I'm not very clear, English is not my first language.
Re: If image found search for image underneath it?
That wasnt code, it was coordinates.
I was trying to establish whether you were trying to see something lower in the z-order (ie literally "underneath") or something which had a higher y coordinate (lower down on the screen).
Seeing as you have confirmed the latter, then that is simple.
When the first image search gets a hit, the coordinates where it found the match will be put into the two variables (P1 and P2 in your case) - so when doing the 2nd image search, simply specify coordinates to search in which start below where you got the match for the 1st image.
I was trying to establish whether you were trying to see something lower in the z-order (ie literally "underneath") or something which had a higher y coordinate (lower down on the screen).
Seeing as you have confirmed the latter, then that is simple.
When the first image search gets a hit, the coordinates where it found the match will be put into the two variables (P1 and P2 in your case) - so when doing the 2nd image search, simply specify coordinates to search in which start below where you got the match for the 1st image.
-
- Posts: 5
- Joined: 22 Jun 2017, 20:01
Re: If image found search for image underneath it?
I think I sent the reply without logging in. derpaderk. Sorry for the bloat
Again, sorry for late response.
I feel clueless, I'm starting to question my... mental state.
I don't understand how coordinates work, there seems to be different ways.
I found this:
leftBound := A_ScreenWidth / 2 - 100
rightBound := A_ScreenWidth / 2 + 100
topBound := A_ScreenHeight / 2 - 100
bottomBound := A_ScreenHeight / 2 + 100
This I can somewhat understand. I assume the numbers after "/ 2" are pixels. It creates a box in the middle of the screen.
Not really useful in my situation but I can at least understand it.
I believe I need some sleep, but here is... progress I think.
It doesn't work first of all
I made two images. One blue the other red. If there's a lonely blue or red, do nothing.
But if there's a red pixel/image with blue directly under it, move mouse to blue.
Px1 := P1 - 100
Px2 := P1 + 100
Px3 := P2 + 10
Px4 := P2 - 100
ImageSearch, Px, Py, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *image1.bmp
If Errorlevel = 0
ImageSearch, Px, Py, %Px1%, %Px2%, %Px3%, %Px4%, *image2.bmp
If Errorlevel = 0
MouseMove, %Px%, %Py% // To make sure it only finds the "combination"
I assume it doesn't work because there's no "Py"
ImageSearch, Px, Py, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *image1.bmp
If Errorlevel = 0
ImageSearch, Px, Py, %Px1%, %Px2%, %A_ScreenWidth%, %A_ScreenHeight%, *image2.bmp
If Errorlevel = 0
.....
Works, but presses border of blue when red is anywhere.
I feel like it's really obvious but I just can't see it at the moment.
Will try again after some sleep. Would love another push to the right direction
Again, sorry for late response.
I feel clueless, I'm starting to question my... mental state.
I don't understand how coordinates work, there seems to be different ways.
I found this:
leftBound := A_ScreenWidth / 2 - 100
rightBound := A_ScreenWidth / 2 + 100
topBound := A_ScreenHeight / 2 - 100
bottomBound := A_ScreenHeight / 2 + 100
This I can somewhat understand. I assume the numbers after "/ 2" are pixels. It creates a box in the middle of the screen.
Not really useful in my situation but I can at least understand it.
I believe I need some sleep, but here is... progress I think.
It doesn't work first of all
I made two images. One blue the other red. If there's a lonely blue or red, do nothing.
But if there's a red pixel/image with blue directly under it, move mouse to blue.
Px1 := P1 - 100
Px2 := P1 + 100
Px3 := P2 + 10
Px4 := P2 - 100
ImageSearch, Px, Py, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *image1.bmp
If Errorlevel = 0
ImageSearch, Px, Py, %Px1%, %Px2%, %Px3%, %Px4%, *image2.bmp
If Errorlevel = 0
MouseMove, %Px%, %Py% // To make sure it only finds the "combination"
I assume it doesn't work because there's no "Py"
ImageSearch, Px, Py, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *image1.bmp
If Errorlevel = 0
ImageSearch, Px, Py, %Px1%, %Px2%, %A_ScreenWidth%, %A_ScreenHeight%, *image2.bmp
If Errorlevel = 0
.....
Works, but presses border of blue when red is anywhere.
I feel like it's really obvious but I just can't see it at the moment.
Will try again after some sleep. Would love another push to the right direction
Re: If image found search for image underneath it?
1) Your IFs are not nested, as you have not used {braces}
If you omit braces, only the next line is part of the if - so the imagesearch is in the 1st if,but the 2nd if is not
2) // is not a valid comment, use ;
3) The coordinate params for Imagesearch can be expressions, you do not need to %escape% variables. You can put math in here
So, assuming you have a 1x2 image with one pixel red then one below, you want something like:
If you omit braces, only the next line is part of the if - so the imagesearch is in the 1st if,but the 2nd if is not
2) // is not a valid comment, use ;
3) The coordinate params for Imagesearch can be expressions, you do not need to %escape% variables. You can put math in here
So, assuming you have a 1x2 image with one pixel red then one below, you want something like:
Code: Select all
ImageSearch, x1, y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *image1.bmp
If Errorlevel = 0 {
ImageSearch, x2, y2, x1, y1+1, 1, 1, *image2.bmp ; Look at coordinates x1, y1+1, in a 1x1 box
if (Errorlevel = 0){
MouseMove, x2, y2 ; To make sure it only finds the "combination"
}
}
Last edited by evilC on 27 Jun 2017, 18:02, edited 1 time in total.
-
- Posts: 5
- Joined: 22 Jun 2017, 20:01
Re: If image found search for image underneath it?
That works! Thank you. I didn't know you could do that.
However the y2 coordinates 1, 1, only scans the the top left, i think. can't find an image.
I experimented with it and tried this, to see what happens.
ImageSearch, x2, y2, x1, y1+1, %A_ScreenWidth%, %A_ScreenHeight%, *image2.bmp
Now it scans for red if it finds it searchers for blue, however blue can be anywhere underneath it, including to the far right or left.
Wish is pretty cool. And it makes sense of course.
with something like
leftBound := A_ScreenWidth / 2 - 1
rightBound := A_ScreenWidth / 2 + 1
topBound := A_ScreenHeight / 2 - 500
bottomBound := A_ScreenHeight / 2 + 500
ImageSearch, x1, y1, %leftBound%, %topBound%, %rightBound%, %bottomBound%, *image1.bmp
If Errorlevel = 0 {
ImageSearch, x2, y2, x1, y1+1, %rightBound2%, %bottomBound2%, *image2.bmp
It scans red and then blue but in the same row of pixels, wish it should. But only in the middle of the screen of course, wish it shouldn't.
Maybe there isn't an easy way to do this. I don't know, my knowledge is very limited, so at this moment I'm most likely not asking for a
"push into the right direction" anymore. It's more like spoon-feeding. But if your up for that, great you have taught me something new
already and I'm thankful for that.
However the y2 coordinates 1, 1, only scans the the top left, i think. can't find an image.
I experimented with it and tried this, to see what happens.
ImageSearch, x2, y2, x1, y1+1, %A_ScreenWidth%, %A_ScreenHeight%, *image2.bmp
Now it scans for red if it finds it searchers for blue, however blue can be anywhere underneath it, including to the far right or left.
Wish is pretty cool. And it makes sense of course.
with something like
leftBound := A_ScreenWidth / 2 - 1
rightBound := A_ScreenWidth / 2 + 1
topBound := A_ScreenHeight / 2 - 500
bottomBound := A_ScreenHeight / 2 + 500
ImageSearch, x1, y1, %leftBound%, %topBound%, %rightBound%, %bottomBound%, *image1.bmp
If Errorlevel = 0 {
ImageSearch, x2, y2, x1, y1+1, %rightBound2%, %bottomBound2%, *image2.bmp
It scans red and then blue but in the same row of pixels, wish it should. But only in the middle of the screen of course, wish it shouldn't.
Maybe there isn't an easy way to do this. I don't know, my knowledge is very limited, so at this moment I'm most likely not asking for a
"push into the right direction" anymore. It's more like spoon-feeding. But if your up for that, great you have taught me something new
already and I'm thankful for that.
Re: If image found search for image underneath it?
It is limited to a column below, because we fed in the coordinates of the previously found image as constraints on the x axis...It scans red and then blue but in the same row of pixels, wish it should. But only in the middle of the screen of course, wish it shouldn't.
So just set x to 0 and set the edges of the screen as the right and bottom bounds
Code: Select all
ImageSearch, x1, y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *image1.bmp
If Errorlevel = 0 {
ImageSearch, x2, y2, 0, y1+1, A_ScreenWidth , A_ScreenHeight, *image2.bmp ; Look at coordinates 0, y1+1, in a box that fills the rest of the screen (ie any value of x, y is at least 1 greater than y1)
if (Errorlevel = 0){
MouseMove, x2, y2 ; To make sure it only finds the "combination"
}
}
Who is online
Users browsing this forum: No registered users and 41 guests