Having trouble comparing texts with OCR

Hi everyone,

I am trying to read the text on my images on 2 websites and compare them to see if the texts are the same. The script I am trying to run read’s the images I captured and determines if they are the same by logging success or fail. The problem is when I read 2 of the same texts on these different websites I get different results. I captured both images the same way and tried many different variations and it reads the text wrong giving random letters and symbols. The script and the results are below :

Put readtext ((ImageRectangle(“filter1”)), multiLine: true, Contrast:On, ContrastColor: White) into filter1

log filter1

click “prep”

Put readtext ((ImageRectangle(“filter2”)), multiLine: true, Contrast:On, ContrastColor: White) into filter2
log filter2

if filter1=filter2
log “Success”
else
log “Fail”
end if

I’m not surprised that you’re having trouble with reading the text with the contrast color set to white when none of the text that you’re having trouble reading has white as either the foreground or the background color. You should set the contrast color to a value as close as possible to the actual background color – I’m actually surprised that it’s reading anything at all with the current settings. You’re probably going to need to do a more line-by-line reading of the text with settings specific to the text colors in those regions.

That said, the OCR may or may not read those values accurately. Since a number of the fields do not contain common words, they are essentially random strings of characters as far as the OCR is concerned and it may have trouble reading them as the values you expect. When the OCR is not certain what a character is, it turns to a dictionary list to resolve the uncertainty base on known words – when what it’s looking at is not a word at all, then it just gives its best guess, which may or may not be correct.

You need to increase your DPI…

ReadText() Function

Examples:
Log ReadText ((230,355)) // Logs the text near the point (230,355)
Log ReadText ((14,130,140,149)) // Logs the text in the rectangle (230,355)
Log ReadText ((14,130,140,149)),(multiLine: true)) //Logs text in the given rectangle, specifying that there are multiple lines to read.

Parameters: A required point or rectangle indicating the region of the screen to read; an optional property list that may contain any number of the following properties:

• DPI: integer. Dots per inch of the SUT screen. The default DPI is 72.
• Contrast: boolean. When Contrast is on, the OCR engine treats the ReadText rectangle as a flat, two-color image. The primary color is taken from the top left pixel of the rectangle, or the ContrastColor property. Pixels that fall within the ContrastTolerance value of that color are considered to have that color. All other pixels are assigned the secondary color. Text can be read in either color. The default value of Contrast is off.
• ContrastColor: color. When Contrast is on, ContrastColor is the color that is treated as the primary color of the ReadText rectangle. If you do not set the ContrastColor property, contrast color is taken from the top left pixel of the rectangle.
• ContrastTolerance: boolean. When Contrast is on, ContrastTolerance is a measure of how much a pixel can differ from the RGB value of the ContrastColor and still be considered the primary color. The default ContrastTolerance is 45.
• MultiLine: boolean. This property only applies when reading text near a point, as opposed to reading text within a rectangle. When MultiLine is on, the readText function returns the line of text associated with your point, and any subsequent lines that appear to belong to the same text block. When MultiLine is off, the ReadText function only returns the line of text associated with your point. The default MultiLine is off.
• SingleColumnMode: boolean. When SingleColumnMode is on, the OCR engine presumes that there is only one column of text on the screen. When SingleColumnMode is off, the OCR engine may detect multiple columns and order lines of text accordingly in the return value.
• TextLanguage: language. This property determines which character sets are valid for your ReadText return value. TextLanguage can include multiple languages, separated by commas, such as “English, French, German”. The default TextLanguage is English.
• Trim: boolean. When Trim is on, the OCR engine trims each edge of the ReadText rectangle until a non- background pixel is encountered. The background color is taken from the top left pixel of the rectangle, or the TrimColor property. The default value of Trim is off.
• TrimBorder: integer. When Trim is on, TrimBorder is the pixel-width of background that is not trimmed from the ReadText rectangle. The TrimBorder can be set to a negative number, to trim non-background edges from the rectangle. The default TrimBorder is 0.
• TrimColor: color. When Trim is on, TrimColor is the color that is considered the background of the ReadText rectangle. If you do not set the TrimColor property, the background color is taken from the top left pixel of the rectangle.
• TrimTolerance: integer. When Trim is on, TrimTolerance is a measure of how much a pixel can differ from the RGB value of the TrimColor and still be considered background. The default TrimTolerance is 0.
• TrimWhitespace: boolean. When TrimWhitespace is on, all whitespace characters are removed from the beginning and end of returned text. When TrimWhitespace is off, ReadText may return text that starts or ends with whitespace characters. The default TrimWhitespace is on.
• ValidCharacters: string. The set of characters that may be returned by the ReadText function. The ValidCharacters property overrides the TextLanguage property; characters that are not part of ValidCharacters are not returned by the ReadText function. By default, all characters in your chosen TextLanguage are valid.

Example from my own scripts…

put readtext ((110, 730, 415, 785), contrast:on, contrastColor:black, validCharacters:"$.,0123456789", IgnoreSpaces:On, DPI:288) into Var

Good Luck!

@Eggplant Matt -

You mentioned that the OCR will turn to a dictionary to try and pick up on what word you are attempting to read in. Can this dictionary have words added to it by the user? Or this locked down?

It is not currently possible to modify the dictionary used by the OCR.