Rectangle Coordinates for OCR Region Detection

Several IronOCR methods accept a Rectangle so you can run OCR on a single part of an image rather than the whole thing. The four values it needs, x, y, width, and height, can be read straight out of Microsoft Paint.

The constructor looks like this:

Rectangle(int x, int y, int width, int height, MeasurementUnits units = MeasurementUnits.Pixels)
Rectangle(int x, int y, int width, int height, MeasurementUnits units = MeasurementUnits.Pixels)
Rectangle(x As Integer, y As Integer, width As Integer, height As Integer, Optional units As MeasurementUnits = MeasurementUnits.Pixels)
$vbLabelText   $csharpLabel

Each parameter maps to one measurement:

  • x: distance from the left edge of the image to the start of your region.
  • y: distance from the top edge of the image to the start of your region.
  • width: width of the region you want to read.
  • height: height of the region you want to read.
  • MeasurementUnits.Pixels: tells IronOCR the values are in pixels.

Coordinates start at the top-left corner of the image: x grows to the right, y grows downward.

Coordinate system showing origin at top-left with X growing right and Y growing downward

Before you start, you need Microsoft Paint (or any editor that shows cursor position and selection size in pixels), the image you want to read, and IronOCR added to your project.

Solution

1. Read the X and Y Starting Point

Open the image in Microsoft Paint, then move the cursor to the top-left corner of the region you want to read. The cursor position shows in the bottom-left of the window. A readout of 2403, 1653px gives you the start of the region:

Microsoft Paint status bar showing cursor coordinates 2403, 1653px at the top-left of the OCR region

X = 2403
Y = 1653

2. Read the Width and Height

Switch to the Select tool and drag a box over the target text. Paint reports the size of the selection in the bottom-left. A readout of 1031 × 214px is the dimensions of your region:

Microsoft Paint selection around the Testing123 text with status bar showing selection size 1031 x 214px

Width = 1031
Height = 214

3. Build the Rectangle

With the four values in hand, construct the Rectangle. For the Testing123 region above:

var rectangle = new Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels);
var rectangle = new Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels);
Dim rectangle = New Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels)
$vbLabelText   $csharpLabel

4. Pass It to IronOCR

Hand the rectangle to LoadImage to crop the input down to that region before running OCR:

var rectangle = new Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels);
ocrInput.LoadImage(frame, rectangle);
var rectangle = new Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels);
ocrInput.LoadImage(frame, rectangle);
Dim rectangle = New Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels)
ocrInput.LoadImage(frame, rectangle)
$vbLabelText   $csharpLabel

Debug Tips

  • The 1031 × 214px value in the status bar is the width and height of the selection, not a coordinate.
  • The 2403, 1653px cursor readout is the X and Y starting point, meaning the top-left of the region.
  • Paint reports in pixels, so pass MeasurementUnits.Pixels to match.
  • Reading the values by eye leaves them off by a few pixels. If the crop clips part of the text, widen width or height slightly, or lower x or y.

CautionDo not use the full image size, such as 4960 × 7014px, as the rectangle size. That selects the entire image instead of your region.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 6,106,091 | Version: 2026.7 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronOcr
run a sample watch your image become searchable text.