[Internal] Why are the coordinates returned by ReadScreenShot incorrect in IronOCR?
ReadScreenShot may return unexpectedly scaled coordinates because the input image is resized internally for improved OCR accuracy.
If you're using IronOCR's ReadScreenShot
method and noticing that the coordinates returned (such as X
and Y
values) don't match the expected location of the text in the original image, this is a known issue related to how the library processes images internally.
To optimize performance and accuracy, IronOCR may scale down the image before performing OCR. As a result, the coordinates in the output are based on the resized image, not the original one. This can cause confusion when mapping OCR results back to the original image.
Here is the result of the coordinates for the text “AS400” (notice the red rectangle in the wrong location). Instead of boxing the “AS400” text, the rectangle was drawn incorrectly due to unscaled coordinates.
Workaround
Until a fix is released, you can apply a scaling factor to the coordinates in the OCR result. Use the following guide based on your image dimensions:
-
If the original image width is greater than 1500 or height is greater than 1200, multiply the coordinates by 3.
-
If the original image width is greater than 840 or height is greater than 600, multiply the coordinates by 2.
-
Example: For an image sized 1296 x 1010, use a scaling factor of 2.
-
// Example workaround
var x = resultX * 2;
var y = resultY * 2;
var width = resultWidth * 2;
var height = resultHeight * 2;
This scaling will bring the coordinates closer to their expected positions on the original image.
Here is the result after multiplying the coordinates by 2. The red rectangle now correctly highlights the “AS400” text.