Hello, I'm working with some types of charts and graphs. I want help in writing Pixelsearch code which finds two colors in specific part of a webpage and repeat the search for the same two colors at another part of the webpage.
Kindly refer to the image attached. In the image, I have marked the area where two lines(chocolate and black) made a cross over.
Thank you.
How to search for two colors at a specific part in a webpage using pixel search
-
- Posts: 21
- Joined: 02 Jun 2016, 00:07
How to search for two colors at a specific part in a webpage using pixel search
- Attachments
-
- IMG_20210416_190108.jpg (14.56 KiB) Viewed 403 times
Last edited by gregster on 18 Apr 2021, 03:16, edited 1 time in total.
Reason: Topic moved to 'Ask For Help' (v1).
Reason: Topic moved to 'Ask For Help' (v1).
Re: How to search for two colors at a specific part in a webpage using pixel search
Based on your other posts, it appears you are using AHK v1. You posted in the section for v2, which is in alpha testing.
To answer your question, the parameters x1, y1, x2, y2 of PixelSearch are how you define which area of a window or the screen you want to search. You would perform a search for one color using a certain area then another for the other color in that area, then do both again for the other area.
If you are asking how the script can dynamically determine the areas to search or how to scroll the webpage in browser so the area of interest is displayed, that’s something different, and I think it requires more detailed description on what you are trying to accomplish.
If you are asking how to determine the area where the lines of the different colors cross, that sounds like a chicken and egg scenario. Are you wanting to use PixelSearch to find where they cross, or are you looking to use PixelSearch in that area given that you know where they cross?
To answer your question, the parameters x1, y1, x2, y2 of PixelSearch are how you define which area of a window or the screen you want to search. You would perform a search for one color using a certain area then another for the other color in that area, then do both again for the other area.
If you are asking how the script can dynamically determine the areas to search or how to scroll the webpage in browser so the area of interest is displayed, that’s something different, and I think it requires more detailed description on what you are trying to accomplish.
If you are asking how to determine the area where the lines of the different colors cross, that sounds like a chicken and egg scenario. Are you wanting to use PixelSearch to find where they cross, or are you looking to use PixelSearch in that area given that you know where they cross?
-
- Posts: 21
- Joined: 02 Jun 2016, 00:07
Re: How to search for two colors at a specific part in a webpage using pixel search
Hello, thanks for replying and notifying me that I have posted my query in V2 instead of V1. I'm sorry, that was unintentional.
You are right. The most preferred result I'm expecting is, I want to search for two colors crossover. If it's possible, kindly guide me how to do it.
Alternatively, it can be done by searching a fixed area for color one and if color one exists, then search for color two. If both colors exist, then notify through message box.
Browser page scrolling isn't needed. Thank you.
You are right. The most preferred result I'm expecting is, I want to search for two colors crossover. If it's possible, kindly guide me how to do it.
Alternatively, it can be done by searching a fixed area for color one and if color one exists, then search for color two. If both colors exist, then notify through message box.
Browser page scrolling isn't needed. Thank you.
Re: How to search for two colors at a specific part in a webpage using pixel search
This works for me when I display your image in an MS Paint window (with the red circle removed). It searches in 20 pixel-wide vertical stripes for the first line's color, and then looks for the other line's color in a 20x20 pixel box from where the first one was found. If it finds it, then it's close, so it starts searching in little vertical boxes with a width of 1 pixel until it can't find at least one of the colors because at least one gets obscured at the crossover.
It doesn't make it all the way to the exact crossover because at some point the overlapping of the lines causes neither to be found because it's sort of a mix of the two or because as it moves pixel by pixel, the variation in the color of the drawn line prevents it from being found at some single pixel widths (zoom in to see the variation). Whichever is the case, at that point it declares success and moves the mouse pointer to the near crossover point and reports the location. It would more accurately find the crossover if the lines were of pure color rather than being "smoothed" by being made up of various shades of the main color.
It doesn't make it all the way to the exact crossover because at some point the overlapping of the lines causes neither to be found because it's sort of a mix of the two or because as it moves pixel by pixel, the variation in the color of the drawn line prevents it from being found at some single pixel widths (zoom in to see the variation). Whichever is the case, at that point it declares success and moves the mouse pointer to the near crossover point and reports the location. It would more accurately find the crossover if the lines were of pure color rather than being "smoothed" by being made up of various shades of the main color.
Code: Select all
Color1 := 0x7F5549
Color2 := 0x000000
Variation := 50 ; allowable variation in color when searching
WinActivate, ahk_exe mspaint.exe
WinGetPos,,, w, h, ahk_exe mspaint.exe
loop, % w / 20 {
PixelSearch, FoundX, FoundY, (A_Index - 1) * 20 + 20, 150, (A_Index - 1) * 20 + 39, h - 55, Color1, Variation, Fast RGB
if !ErrorLevel {
PixelSearch, FoundX, FoundY, FoundX, FoundY - 10, FoundX + 20, FoundY + 10, Color2, Variation, Fast RGB
if !ErrorLevel {
loop, 20 {
LastFoundX := FoundX
LastFoundY := Y1
PixelSearch, X, Y1, FoundX + A_Index, FoundY - 10, FoundX + A_Index, FoundY + 10, Color1, Variation, Fast RGB
E1 := ErrorLevel
PixelSearch, X, Y2, FoundX + A_Index, FoundY - 10, FoundX + A_Index, FoundY + 10, Color1, Variation, Fast RGB
E2 := ErrorLevel
} until E1 || E2
MouseMove, LastFoundX, LastFoundY
MsgBox, % "Mouse is pointing near crossover: " LastFoundX ", " . LastFoundY
ExitApp
}
}
}
return
Re: How to search for two colors at a specific part in a webpage using pixel search
opencv can do it if u run some hough lines on the red channel(optionally cleaning the image up some beforehand) and find their intersection
or since u say this is on a webpage, theres probably more information u can glean from it instead
or since u say this is on a webpage, theres probably more information u can glean from it instead