OCRExtractRelative: A larger pink box OCR area is usually better

We found that a typical root cause for bad/wrong OCR results is that the pink box (that marks the area for text recognition) is made too small. This is especially true for number OCR.

Solution:

  • Add more white space around the text

  • And (for number OCR) to include some additional text (e. g. the label). If you do not need the text part, you can remove it after the OCR by splitting the OCR result string.

Example: In this example we need to screen-scrape the number behind the “Type:” label (here: 0):

screen

Pink area too small => single number not OCR’ed correctly

smallpink

Pink area includes label => good OCR result

goodpink

Screen scraping video:

In this macro we test both pink areas. The small area returns “” as resul and the larger pink area returns “Type: 0” as expected.

Macro source code:

{
  "Name": "ocr2",
  "CreationDate": "2021-8-27",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://imgur.com/D7BhlEl",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "eng",
      "Value": "!OCRLanguage",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "2",
      "Value": "!OCREngine",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "false",
      "Value": "!OCRScale",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "false",
      "Value": "!OCRTableExtraction",
      "Description": ""
    },
    {
      "Command": "OCRExtractRelative",
      "Target": "toosmall2_dpi_168.png",
      "Value": "a",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Result A: ${a}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "OCRExtractRelative",
      "Target": "larger2_dpi_168.png",
      "Value": "b",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Result B: ${b}",
      "Value": "green",
      "Description": ""
    }
  ]
}