Skip to main content
One Lighting Angle Decides the OCR Read Rate on Molded Characters
Lighting Design,  Vision Algorithm

One Lighting Angle Decides the OCR Read Rate on Molded Characters

LIGHTING

Colorless molded characters are read by their shadows. For characters 50 μm high with 300 μm stroke spacing, the lighting elevation must not drop below 18.4°.

Taking the cavity number on a black matte ABS housing, I calculated the shadow length, the character position that the ring diameter dictates, and difference compositing from four-direction lighting.

About 12 min read

On the back of a black matte ABS housing sits a cavity number molded along with the part. Unlike ink printing, the characters and the background are the same resin and the same color, and only a height difference of about 50 μm separates them. Matte resin is a surface of diffuse reflection1 that scatters light in every direction, so under even light from above, the tops of the characters and the background image the same grey, and the OCR2 engine, hunting for letters on an almost blank image, returns the wrong ones. Misread a cavity number and the faulty mold cavity cannot be pinpointed, so every cavity has to stop together, and the station where people reread failed parts hardens into permanent staffing. A history mixed with misreads is more dangerous than a read failure. A wrong record stays looking like a right one and points to the wrong cavity when the cause is traced back later.

The fix is a low-angle ring light3 that turns height differences into brightness differences. Lay the light close to horizontal and shadows form on the background beside the strokes, and those shadows become the outlines of the characters. For a cavity number with 50 μm high characters and 300 μm stroke spacing, I calculated the lighting angle from those two numbers on the drawing instead of picking it by feel.

Lit from above, one resin is one grey

The brightness of a matte surface follows the cosine of the angle at which light strikes it. Call the lighting angle measured from the floor the elevation4 E, and a flat background is sin E as bright as under vertical light taken as 1. That is 0.34 at an elevation of 20° and 0.71 at 45°. The tops of the characters are flat too, so they give the same value as the background, and no matter how brightly they are lit from above, no difference appears between the two. Height leaves no trace in the image.

The difference arises beside the strokes. A wall facing the light brightens by its slope, and on the background opposite, the stroke blocks the light and casts a shadow. It is the same as an evening with the sun low, when every gap in the paving blocks stretches a long shadow and the block pattern looks sharper than at noon. The length of the shadow is set by height and light angle, and that length becomes the thickness of the outline handed to the OCR.

Lowering the elevation darkens the background too, and that must not be missed. At 20° the background is a little over a third as bright as under vertical light, so with the same exposure the whole image sinks. I would set the exposure and light output of this setup with about three times the margin from the start. With a resin that reflects strongly, such as glossy PC, the walls facing the light can blow out into white highlights, so whether the same calculation holds cannot be guaranteed before a sample test.

Shadow length is height divided by a tangent

When a stroke of height h receives light at elevation E, a shadow of length L = h ÷ tan E forms on the background. Too short and the shadow covers only a few pixels and never becomes an outline; too long and it covers the gap to the next stroke, merging two strokes into one lump. My rule is a shadow of 3 px or more and no more than half the stroke spacing. The cross-section below draws height, angle, shadow and the brightness profile together.

Cross-section showing lit walls and shadows that low-angle light creates on an embossed stroke and an engraved groove, the shadow length relation L = h / tan E and the resulting top-view intensity profile
Follow how the shadow length set by stroke height h and elevation E becomes the width of the dark trough in the brightness profile.

The calculation setup is a 2,448 × 2,048 px sensor with a 35 mm F/8 lens viewing 30.0 mm across, one pixel covering 12.25 μm (all assumed). To stay within 150 μm, half the 300 μm stroke spacing, E ≥ atan(50 ÷ 150) = 18.4°, and to keep the shadow from getting shorter than 3 px (36.8 μm), E ≤ atan(50 ÷ 36.8) = 53.7°. The usable elevation lies in between. Choose 20° and the shadow is 50 ÷ tan 20° = 137 μm, 11.2 px; drop to 10° and it grows to 284 μm, covering almost all of the 300 μm gap, so the numerals 8 and 0 start to look joined. At 45°, on the other hand, the shadow shrinks to 50 μm, 4.1 px. It still reads, with little margin.

The reason to pick the low end of the range is mold wear. As characters wear shallower their shadows shorten too, and at 20° the minimum height that still casts a 3 px shadow is 36.8 × tan 20° = 13.4 μm. That means a 50 μm character still reads after wearing down to 13.4 μm. Run the same calculation at 45° and the minimum height is 36.8 μm, so the character hits the reading limit after only about 13 μm of wear.

The ring diameter decides where characters may sit

20° is measured at the very center of the field. Put a ring 120 mm across at 21.8 mm above the part and the elevation is 20° at the center, but 15 mm out at the end of the field it spreads to 25.9° toward the nearer LEDs and 16.2° toward the farther ones. The shadows swing from 103 μm to 172 μm, and the 172 μm on the far side exceeds 150 μm, half the stroke spacing. The far side breaks the rule.

Calculate the range where the far-side elevation does not fall below 18.4° and you get ±5.5 mm from the center of the field. Keeping this ring means aligning part pose and field of view so the cavity number sits inside that zone. To hold the condition out to 15 mm at the end of the field while keeping 20° at the center, the ring would have to grow to 326 mm across at a height of 59.4 mm. A larger ring takes more LEDs for the same illuminance and a wider installation space, so I would first gather the characters toward the center of the field.

18.4°

Minimum elevation at which shadows stay within half a 300 μm gap

±5.5mm

Character zone where the far-side elevation of a 120 mm ring stays at 18.4° or more

13.4μm

Minimum character height that casts a 3 px shadow at 20°

Of the three numbers, 18.4° and 13.4 μm are set by the drawing, and ±5.5 mm by the ring. So when a model change alters character height or stroke spacing, I would recalculate the ring position and the field layout together. Change only the character size while the ring diameter stays, and a reading gap tends to appear, with characters readable at the center and joined at the edges.

Light four directions apart and edge direction returns

Switch the whole ring on at once and light from every side fills in the shadows of the others. Light that strikes the left wall fills the right shadow at the same time, so the pair of bright wall and dark shadow fades. Quadrant lighting5, which splits the ring into north, south, east and west sections lit in turn, gets the shadows for each direction separately.

After taking four images, subtract opposite sections (north − south, east − west), and the flat background that is equally bright from both sides cancels, leaving only the edges that are bright or dark from one side. Pick, pixel by pixel, the larger absolute value of the two differences, and the outlines of strokes in any direction gather in one image. My judgment is that this is enough for outlines handed to OCR without going as far as recovering surface normals.

Each section has its own elevation distribution and therefore its own brightness gradient across the field, so shading correction6 is done separately per section with an image of a reference surface without characters. Four exposures lengthen the cycle time, and if the part moves between them, the four images fall out of registration and false edges appear in the differences. Synchronizing transport is a separate review. Shadows erased in a single fully lit image cannot be brought back by an algorithm, so the direction information has to be secured at the lighting stage.

From 50 μm characters to read confidence, three spec lines

Moved into a spec, the calculation becomes three lines: character dimensions, ring and lens, and the reading algorithm. The WD (working distance)7, the distance from the front of the lens to the part, is a value to check down to whether the top of the ring light collides with the lens, and the binarization before reading uses adaptive thresholding8, which holds up even when a brightness gradient remains.

ItemReference valueCondition and basisIn plain words
① Minimum defect size · reading targetRaised 50 μm, stroke width and spacing 300 μm, character height 2.0 mmStroke 24.5 px, character 163 px at 12.25 μm/px. Design assumptionHeight and gaps of the letters to read
① Minimum defect size · missing stroke60 μm long or more4.9 px. Design assumptionA short underfilled piece of stroke
① Minimum defect size · reading-limit height13.4 μm (at 20°)Shadow 3 px = 36.8 μm × tan 20°Still readable worn down to this
② Optical setup · lightingLow-angle ring 120 mm across, 21.8 mm high, four sections lit in turnElevation 20° at the center, 18.4° minimum. Characters within ±5.5 mm of centerLow light switched on in four parts
② Optical setup · shadowRaised 137 μm (11.2 px), engraved 80 μm deep gives 220 μmL = h ÷ tan E. Raised 103 to 172 μm at the end of the fieldWidth of the dark band beside a letter
② Optical setup · lens and sensor35 mm F/8, 2,448 × 2,048 px, 12.25 μm/pxMagnification 0.282, thin-lens object distance 159.3 mm. Design assumption30 mm across in one image
② Optical setup · WDWD of 140 mm or more secured (design assumption)Measured from the front of the lens barrel. Measure that it clears the top of the ringA height where lens and ring do not collide
③ Algorithm parameters · correction and compositingAfter per-section shading correction, the larger of |north − south| and |east − west|The flat background cancels and only edges remainDrop the background, gather the outlines
③ Algorithm parameters · binarization and readingAdaptive threshold window 75 px, character height 163 px normalized to 32 px, reread below 0.90 confidenceWindow about 3 times the stroke width. 0.90 is an assumption; holding a read beats misreadingWhen unsure, hold rather than misread

The first thing to see in the table is that the bottleneck of this setup lies in the spatial spread of elevation more than in resolution. A 300 μm stroke is 24.5 px and a 60 μm missing segment 4.9 px, leaving room in pixels, but at the end of the field the shadow of the same character stretches to 172 μm and passes half the stroke spacing. To make reading quality even across the field, the design decision to gather the characters within ±5.5 mm or to enlarge the ring has to come first.

There are cases where low angles do not fit. Characters whose surface color has changed, as with laser marking, need no height information, so a diffuse dome or coaxial light makes a cleaner image without surface-texture noise. On parts textured coarser than the characters, such as a grained mold finish, the texture casts stronger shadows than the characters at low angles, and a 3D method that measures height directly may do better. On a line with no time for four images, a single shot with a one-direction low-angle bar light aligned to the characters is a realistic compromise. There is also a layout that puts a dome and a low-angle light in one station and splits character reading from appearance inspection between them. The gain from low angles varies widely with resin type, gloss and surface texture, so which method wins cannot be guaranteed before a sample test.

Drawing the lighting angle out of character height and stroke spacing takes only a single tangent, yet it is the first calculation an engineer who designs lighting learns by hand. For a buyer comparing quotes, asking how many micrometers of mold wear the reading survives and how far across the field the same read rate holds reveals real performance better than the name of the OCR engine. This article explains technology and is not investment advice. See our Disclaimer.

Field Note

To read a raised cavity number on a molded housing, I would not start by lowering the elevation; I would check character height and stroke spacing on the drawing and calculate the usable elevation range. For these characters it is 18.4° to 53.7°, and the closer to the low end, the larger the margin for mold wear. Next, with the ring height fixed, the same character goes at the center and at the end of the field to measure shadow length and see whether any spot passes 150 μm on the far side. After the mold is reworked, character height gets measured again and the range recalculated.

Field Checkpoints

Once the elevation range and the shadows at the end of the field are checked, I go over the rest with the questions below.

  • Is a WD of 140 mm or more secured by measurement, including clearance between the front of the lens barrel, the top of the ring light and the top of the part? (whether lens and ring collide)
  • Have the surface material and reflectance of the part been confirmed first? (matte resin, glossy resin, or a grained texture)
  • Has the usable elevation range been calculated from character height and stroke spacing on the drawing? (18.4° to 53.7° for these characters)
  • Is the shadow still half the stroke spacing or less at the far-side elevation at the end of the field? (with a 120 mm ring, characters within ±5.5 mm of center)
  • Has a shading correction image been taken separately for each quadrant section? (each section has its own brightness gradient)
  • Do the four exposures fit within the cycle time with the part holding still? (whether false edges appear in the differences)
  • Has a sample confirmed reading down to the minimum character height assumed for mold wear (13.4 μm at 20°)? (whether worn letters still read)

Frequently Asked Questions

Does the same calculation work for engraved characters?

With engraved characters the shadow falls on the floor of the groove. Light an 80 μm deep groove at 20° and the shadow is 220 μm, darkening a little over two thirds of a 300 μm wide groove floor. Darkening the entire floor takes an elevation below atan(80 ÷ 300) = 14.9°, which lengthens the shadows of neighboring raised characters, so if one part carries both kinds, calculate each and look for the overlapping range.

What else should be checked on glossy resin?

On the walls facing the light, specular highlights can blow out white and break the outline. Setting exposure for the highlights buries the shadow side, so compare, on the same sample, an image with lower light output and an image with polarizing filters crossed on the light and the lens. Measuring in advance what share of highlight pixels hit saturation makes the comparison quicker.

Glossary

  • [1] Diffuse reflection diffuse reflection
    Reflection in which a rough surface scatters light in many directions. Brightness looks similar from any side, so without shadows height does not show. ↩
  • [2] OCR optical character recognition
    Reading that finds characters in an image and turns them into character codes. When outlines break or join, it reads them as other characters of similar shape. ↩
  • [3] Low-angle ring light low-angle ring light
    Lighting that places a ring of LEDs low and close to the part and shines at an angle near horizontal. It casts shadows beside relief and turns height into brightness. ↩
  • [4] Elevation elevation angle
    The angle of the light as seen looking up from the surface of the part. The lower it is, the longer the shadows and the darker the background. ↩
  • [5] Quadrant lighting quadrant lighting
    A method that splits a ring light into four sections and captures with one section on at a time. The shadows from each direction are obtained separately and subtracted from each other. ↩
  • [6] Shading correction shading correction
    A correction that divides out the brightness gradient from lighting and lens using a reference image. If the gradient differs by section, the reference images are taken separately too. ↩
  • [7] WD working distance
    The distance from the front of the lens to the surface being inspected. A ring light placed low must not collide with the lens within it. ↩
  • [8] Adaptive thresholding adaptive thresholding
    Binarization that splits black from white at each pixel by the average of a surrounding window. It keeps character outlines even when one side of the image is darker. ↩

References

  • Edmund Optics Knowledge Center, Darkfield Illumination with Ring Lights for Machine Vision (how a ring light shining at low angles reveals edges, engravings and deep scratches, its use with a telecentric lens for OCR of small text etched into plastic or metal surfaces, and placing the light close to the part at about 50 mm)
  • Formulas: flat-surface brightness ∝ sin E (Lambertian reflection, elevation E), shadow length L = h ÷ tan E, minimum elevation = atan(h ÷ half the stroke spacing), maximum elevation = atan(h ÷ length of 3 px), reading-limit height = length of 3 px × tan E, ring elevation = atan(H ÷ (Rr ∓ x)), far-side condition x ≤ H ÷ tan Emin − Rr, elevation darkening the whole engraved floor = atan(depth ÷ groove width), magnification m = sensor width ÷ field of view, u = f × (1 + 1/m)

Related reading — Six Machine-Vision Lighting Methods and How to Choose · Reserve Room for Vision Cameras and Lighting at the Mechanical Design Stage · In Automotive Part Appearance Inspection, Lighting Design Comes First

An engineer who has handled mechanical design and project management for production equipment since 2005. Here I work through the cameras, lenses and lighting that go into equipment with formulas and public data, and record the assumptions and sources alongside the numbers.

Leave a Reply

Your email address will not be published. Required fields are marked *