Code readingGuide

Detect small printed numbers on part outlines with OCR

Size the camera from digit height, find each digit as a dark blob, then crop and run OCR — pixel-height rules for small printed numbers, with a worked example.

LumaSpec Vision11 min read Share on LinkedIn

On this page 9 sections
  1. 01How small can printed numbers be before OCR stops reading them?
  2. 02How do you find the digits without a trained model?
  3. 03How much camera resolution does your field of view need?
  4. 04Which lighting makes dark ink read reliably?
  5. 05How do you filter the blobs down to just the numbers?
  6. 06Should the pipeline run on a smart camera or a PC?
  7. 07When should you drop blob detection and train a detector instead?
  8. 08What should you check before you order parts?
  9. 09Questions

Small printed numbers inside outlined regions — reference digits on a kit panel, batch codes inside printed frames, paint-by-numbers style artwork — defeat OCR when you throw the whole image at the engine. The outlines and the paper texture bury the digits, and the characters are often under 5 mm tall. The fix is a two-stage pipeline: locate each digit as a dark connected blob, filter the blobs by digit geometry, then run OCR on tight crops. This guide gives you the two pixel-height rules that decide whether the reads succeed, a worked example that sizes the camera, lens and light from a 4 mm digit, and the geometry gates that turn hundreds of blobs into a clean list of numbers. It is written for anyone building the inspection on a smart camera or a PC.

How small can printed numbers be before OCR stops reading them?

Size the image so each digit is at least 20 pixels tall — that keeps every stroke at or above the 4-pixel minimum OCR engines need — and use 30 pixels as the working target, because stroke quality, not the OCR engine, sets the accuracy limit.

The floor comes from the smallest feature, not the whole character. The standard rule in machine vision is to image the smallest feature of a character — for a printed digit, its stroke — with at least a 4 × 4 pixel patch. A digit stands five to seven stroke-widths tall, so a bold face clears the floor at 20 pixels of height, while lighter faces with strokes near 15 percent of the character height need the 30-pixel target to keep every stroke 4 pixels wide.

Two consequences follow. The rule is in pixels, not millimeters: a 2 mm digit at 5 pixels/mm lands at 10 pixels of height and will misread regardless of engine. And anti-aliasing grows in relative importance as digits shrink — at a 4-pixel stroke, the blurred edge pixels make up half of it. That is why the pipeline thresholds early and pads each crop by 2-3 pixels, so the classifier never sees a clipped stroke.

How do you find the digits without a trained model?

Threshold the print so the dark digits and outlines go black, then run connected-component blob analysis and keep only regions that match digit size and shape. No training, no annotated images: the printed outline is geometry you can filter out by shape alone.

Binarize the whole sheet once. Under controlled light a fixed threshold is the most repeatable choice; on uneven stock an adaptive method takes over — the adaptive thresholding walkthrough covers that case. Then label the 8-connected components: every digit, outline fragment and ink speck becomes one component with a bounding box, an area and an orientation angle. That component list is the entire detection result; the gates in the filtering section turn it into digits. The same pass drives other jobs too — the blob-analysis line counting guide shows the mechanics on a different part.

How much camera resolution does your field of view need?

Work backwards from the digit: a 4 mm digit at the 30-pixel target needs 7.5 pixels per millimeter, so a 160 mm-wide field needs 1,200 pixels across — a 2 MP sensor covers it, and a 6 MP one leaves room for placement error.

Worked example, with one sheet and one digit size. Inputs: a 160 × 100 mm sheet, digits 4 mm tall in a medium sans face (stroke ≈ 0.15 × 4 mm = 0.6 mm), a 2/3-inch sensor 8.8 mm wide, working distance 150 mm.

px/mm = 30 px / 4 mm = 7.5 px/mm stroke = 0.6 mm × 7.5 px/mm = 4.5 px (clears the 4 px floor) width needed = 160 mm × 7.5 px/mm × 1.2 margin = 1,440 px m = 8.8 mm / 160 mm = 0.055 f = WD × m / (1 + m) = 150 mm × 0.055 / 1.055 = 7.8 mm, so an 8 mm lens

A 2 MP 4:3 sensor runs 1,600 × 1,200 pixels, so the real scale is 1,600 px / 160 mm = 10 px/mm: the digit projects at 40 pixels and its stroke at 6 pixels — margin, not luck. The 7.8 mm figure is the thin-lens starting point; the lens focal length calculator converts your own sensor width and working distance into a catalog focal length, and the camera resolution calculator runs the pixel arithmetic in reverse. The finder below filters cameras to sensors with enough pixels.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

Stop the lens around f/5.6. The sheet is flat and fixed, so you are trading depth you do not need for contrast you do: depth of field at m = 0.055 with a two-pixel blur circle (2 × 5.5 µm = 11 µm, from 8.8 mm / 1,600 px) is 2 × 5.6 × 0.011 mm × 1.055 / 0.055² = 0.130 mm / 0.003025 ≈ 43 mm. The depth-of-field calculator replays it for your own numbers. Start exposure at 5 ms under a continuous LED bar, then adjust until paper sits at 70-80 percent of full scale and ink at 20-35 percent; freeze motion with a strobe rather than by pushing exposure down into noise.

Which lighting makes dark ink read reliably?

Light the print evenly and shoot for grayscale contrast: ink near 25 percent brightness, paper near 75 percent, at least 50 gray levels of separation after thresholding. A diffuse bar behind a diffuser plate beats a bare LED, which prints a hot spot through your threshold.

Bright field from above over a broad angle suits this job: the ink absorbs, the paper reflects, and the threshold lands midway between them. Darkfield works against you here — it lights paper edges and embossing, not the ink. If the sheet is laminated or glossy, specular glare floods the ink back toward white; crossed polarizers on lens and light remove it, as the cross-polarizer glare guide shows.

Evenness is the other half. The lighting accessories range includes diffuser plates sized to bar lights: the LS-LAC-0010 is a 170 × 30 mm plate for the matching bar width, and the accessories finder lists the other sizes. White and red light both read black ink on light stock; choose white if colored artwork on the same sheet may need inspection later. Shroud the station or strobe the light so a nearby window cannot move the threshold between shifts — the bar and area lights section covers illuminators when you need a new one.

Lighting accessories170 x 30 mm bar light diffuser plate (LS-LAC-0010)LS-LAC-0010
Size
100-200 mm
$24.00View partBuild a system with it

How do you filter the blobs down to just the numbers?

Apply three gates: height between 25 and 55 pixels (the 4 mm digit at 10 pixels/mm), width-to-height ratio between 0.35 and 0.9, and elongation under 4 — the outline lines are long and thin, so they fall out on elongation, not brightness.

First clean the binary image with a 3 × 3 opening to shed speckle, then label. For the worked example at 10 px/mm the gates read: height 25-55 px, area 150-2,200 px², width-to-height 0.35-0.9 (drop the floor to 0.25 for a bare '1', or accept one exception per sheet), and elongation under 4. An outline line 800 pixels long and 2 pixels wide has an elongation in the hundreds; it never survives the third gate.

Crop each surviving box with 2 pixels of padding and pass the crop, the threshold level and the component's orientation angle to the reader — the angle feeds deskew when prints arrive tilted. Store the gates in px/mm rather than raw pixels, so a change of scale moves the whole chain at once: at 7.5 px/mm the same height gate becomes 19-41 px without retuning anything else.

Should the pipeline run on a smart camera or a PC?

Run blob analysis and OCR on the device when the sheet is the only inspection: an x86-class smart camera handles both in one cycle over GigE. Move to a PC when you also archive full images or share results across lines.

The smart cameras range splits into fixed-lens vision sensors and C-mount smart cameras. The MV-SC5060XM-08M-WBN is a 6 MP mono smart camera with an 8 mm M12-mount lens on GigE. Six-megapixel sensors carry roughly 3,000 pixels across, so the 1,440-pixel requirement of the worked example is met twice over. One more spec matters: this camera has a rolling shutter — no cost when the sheet stops for the shot, but pick a global-shutter sensor for digits on a moving web.

Smart cameras & vision sensorsHikrobot MV-SC5060XM-08M-WBN SC5000X series Smart Camera, 6 MP, Mono, 8 mm focal length, M12-mountMV-SC5060XM-08M-WBN
Interface
GigE
Resolution
6-10 MP
Sensor format
1/2.4"
Shutter
Rolling
$1,629.00View part

When you want free lens choice, the LS-SMC-0017 pairs an 8.8 MP global-shutter sensor with an x86 platform behind a C-mount. The example calls for an 8 mm lens on a 2/3-inch chip, and the mount takes any computed focal length, including that one.

Smart cameras & vision sensorsSC / SC smart camera (X86 platform), 8.8 MP, USB3, Color/Mono, global shutter (LS-SMC-0017)LS-SMC-0017
Interface
USB 2.0
Resolution
6-10 MP
Sensor format
1"
Shutter
Global
$1,359.00View part

For smaller fields, both of the Fast Ethernet vision sensors below carry global shutters and run the same locate-then-read chain.

Smart cameras & vision sensorsHikrobot MV-SC3050XC-16M-ATN-H 5 MP color vision sensorMV-SC3050XC-16M-ATN-H
Interface
Fast Ethernet
Resolution
5 MP
$1,809.00View part
Smart cameras & vision sensorsHikrobot HK-TD032-12-WBN 1.6 MP mono vision sensorHK-TD032-12-WBN
Interface
Fast Ethernet
Resolution
Up to 3 MP
$1,699.00View part

The reader returns strings, not images. Hand them to the PLC the way the character verification walkthrough wires it, or filter the camera finder by resolution and interface when your field differs from the example.

When should you drop blob detection and train a detector instead?

Train a small object detector when geometry fails: digits touching or crossing outline lines, curved or wrinkled stock, handwriting, or several fonts at once. Blob analysis stays the right first tool because it needs zero annotated images; escalate only when the gates reject digits you can see are good.

Even then, keep the two-stage shape: detect candidates, crop, read. A learned detector replaces only the blob stage — the detect-then-read OCR pipeline is the same architecture with a network up front. Tilted prints rarely need that escalation: the orientation angle from the component deskews the crop first, as the deskew before training walkthrough shows, and digits that touch each other rather than the outline respond to the separation tactics in the touching-digits guide.

Labeling a few hundred digit crops costs an afternoon; geometry costs nothing. If the gates pass 98 of 100 digits on real stock, tune the gates and keep a trained detector in reserve for the day the artwork changes.

What should you check before you order parts?

Before you order, confirm the four numbers that decide the build: digit height in millimeters, pixels per millimeter at the sensor, gray-level separation between ink and paper, and cycle time per sheet. Print a test target at 100 percent scale and shoot it before you commit.

Camera:

  • Digit height measured on real artwork — every later number scales from it.
  • Sensor width at least FOV × px/mm × 1.2; for the worked example that is 1,440 px.
  • Mono sensor preferred; global shutter if the sheet moves during exposure.

Lens:

  • Focal length computed from sensor width and working distance — 8 mm in the example.
  • Aperture f/4 to f/5.6 for a flat sheet; confirm depth of field against sheet curvature.

Light:

  • Even diffuse illumination with a diffuser plate; at least 50 gray levels of ink-to-paper separation on the worst sample.
  • Hood or strobe so ambient light cannot move the threshold.

Software:

  • Stroke at least 4 pixels at the chosen px/mm on the thinnest font weight.
  • Geometry gates stored in px/mm, not pixels.
  • Cycle budget: one blob pass plus the digit reads inside the takt time.

When your artwork matches the example — 4 mm digits, a 160 mm field, a fixed 150 mm stand-off — the 6 MP camera, 8 mm lens and diffused bar light above are the order. If it differs, redo the five lines of arithmetic first; five minutes of algebra settles every hardware choice. Start the configurator at the camera step, request a quote, or contact the applications team with your digit height and sheet size. The locate-then-read family has more branches on the code-reading topic page.

Questions

What resolution in dpi does printed-digit OCR need?

In document terms, 150 to 300 dpi is the optimal band, and the practical floor is roughly a 30 by 30 pixel character, which is 7.5-point type at 300 dpi. On the line, translate that to pixels per millimeter: 7.5 px/mm gives a 4 mm digit 30 pixels of height — the same target as the worked example.

Does OCR still work if the digits are tilted or printed on a curve?

Most OCR engines tolerate about 5 to 10 degrees of tilt; beyond that, deskew the crop from the blob's orientation angle before reading. A curved surface is harder: curvature bends strokes and varies scale across the character, so read from directly above at a longer working distance, or expect to train a detector on curved samples.

Should I buy mono or color for reading dark ink on light stock?

Mono is the better buy: every pixel is true signal, so the same sensor resolution delivers sharper strokes and better thresholds. A color camera still works — convert to grayscale and re-check the 30-pixel height target — but Bayer interpolation softens single-pixel strokes, which is exactly what small digits are made of.

How many digits can one smart camera read per cycle?

On an x86-class smart camera, budget roughly 1 to 3 milliseconds per cropped digit for template OCR after a single global threshold, plus one full-image blob pass of 10 to 30 milliseconds. A sheet with 40 numbers therefore reads in well under 200 milliseconds, comfortably inside most pick-and-place cycle budgets.

What if a digit touches the outline line and merges with it?

The merged component fails the geometry gates and gets dropped. First fix: search for digits inside a region inset by 2 to 3 pixels from the printed outline, which cuts the thin joining stroke. Try that before any model work; in most line-art layouts it recovers every merged digit.