How to find text against a certain background color?

Hello,

I am trying to use Eggplant’s OCR to find a desired input text against a certain background color. This is because on the SUT I am testing on, there are many same word selections on the website and things tend to move around a lot so searchRectangles do not always provide the best search functionality.

I understand that you can use a dynamic searchRectangle to narrow search selections down, but I want to add additional search capability using background color as a parameter for OCR.

I could not find any documentation for OCR searching against a particular background color. For example, I was looking for something like

put EveryImageLocation(Text:“My Text”, Image:“Background Color”)

where this would search for text on the page which contained contain the inputted background color and then would return the coordinates of all known locations. Obviously, this line doesn’t work, but I was hoping for an in-built function that can help do this.

Are there any functions that can search text against a certain background color? If not, how can this be accomplished using existing built-in Eggplant functions?

Thank you.

Hello RobbyK,
please have a look to e.g. Working with OCR.
So put EveryImageLocation(text:“My text”, Contrast:On, ContrastColor: ) my solve your issue, if “my color” is either your background or foreground color. Additionally ’ ContrastTolerance’ may improve the search result.
BR

1 Like

I would think you could use Text: ContrastColor to help differentiate but it would depend on your circumstances and I imagine you will have tried that already.
Alternatively, you could probably use a dynamic searchrectangle to define your coordinates in which to search. Something like:
put everyimagelocation(“Scratch_Logan/SCRATCHWORK/WhiteSquare”)
It looks like EPF caps out at 1,000 found images (reasonable), so depending on what your SUT looks like this might be out of the question.

click text:“WebStore”,searchrectangle:[imagelocation(item 1 of everyimagelocation(“Scratch_Logan/SCRATCHWORK/WhiteSquare”)),imagelocation(the last item of everyimagelocation(“Scratch_Logan/SCRATCHWORK/WhiteSquare”))]

I’ll bet I could figure out a reasonable method if I had an example screenshot of what you are working on. Capture a screenshot using Control > Capture Screen so I can get the native resolution/aspect ratio.

I usually sample the background color with colorAtLocation()
then use
if ImageFound(Text:“text to find”, Contrast:“On”, ContrastColor(R,G,B))
click found image Location()
else if ImageFound (Text:“text to find”, Contrast:“On”, ContrastColor(R,G,B)) //<- you can repeat to try different background colors if needed.