A long, thin part — an extension spring, a wire form, a slim stamping — is the shape a whole-part template matcher handles worst. The part either runs past the edges of the field of view, or it fits and shows row after row of identical coils with nothing unique to lock onto. The fix is not a better matcher: teach one rigid, distinctive section of the part, such as its loop, and let the system find that section wherever the part lies. This walkthrough gives the rules for choosing that section, the pixel and working-distance numbers that make the teach hold, and the way to calibrate at one height while snapshotting at another.
Why the whole spring will not teach
Two walls stop a whole-spring model, and you hit the first before the matcher even runs. Close up, the part is longer than the field of view, so a complete model can never be captured — the same wall described for oversized parts in template matching a part larger than the field of view.
Back off until the whole part fits and you meet the second wall: uniqueness. A spring is periodic. Slide the model along the part axis by one coil pitch and almost nothing changes, so the correlation surface carries a ridge instead of a peak, and the reported position can walk a full pitch between shots. Coils also flex: a spring handled twice no longer matches the coil spacing you taught, and every changed coil drags the score down although the part itself is good.
Two numbers govern whether any section can be taught at all:
- Pixels across the diameter. Below about 50 pixels on the smallest taught dimension, one pixel of edge shift moves the score several points and pass thresholds start to overlap. Plan on 100 pixels as the floor and 200 as comfortable.
- Unique geometry. The taught region must hold geometry that exists exactly once on the part. Straight coil runs fail this test; loops, tags, bends and cut wire ends pass it.
Teach the loop, not the spring
In pattern-recognition terms this is feature subset selection: keep the features that discriminate, drop the ones that repeat. Three checks pick the section:
- Rigid. The loop at the end of an extension spring keeps its shape through handling; free coils do not.
- Unique. It appears once on the part. The loop section of the demo spring, with its crossing wire, is the classic choice.
- Sized to the field. Keep the region between one-tenth and one-half of the field of view in each direction, with at least 100 pixels on its smallest side.
A loop also hands the matcher a closed curve to localize, so the teach doubles as a part-center locator — the geometry used in robot vision for locating part center points. If nothing on the part is unique, make something unique: a marked dot at a fixed spot, or a switch to silhouette location, covered in the last section of this guide.
Worked example: teaching a 120 × 6 mm spring at 130 mm
Inputs, each with its source:
- Part: extension spring, 120 mm long, 6.0 mm outside diameter, 2 mm coil pitch, loop section about 8 mm long — a representative slender spring.
- Snapshot height: 130 mm from camera to part, the height used in the booth demo this method comes from.
- Mechanical floor: 70 mm above the workplane, the closest that demo's wrist-mounted camera could approach.
- Camera: 12 MP, 4000 × 3000 pixels, 1/1.7" sensor type.
- Lens: 16 mm focal length.
- Sensor size: a type-1/1.7" sensor is about 7.6 × 5.7 mm, the standard optical-format width, so one pixel is 7.6 ÷ 4000 = 1.9 µm.
Work the arithmetic at the 130 mm snapshot height:
- Magnification: m = 16 / (130 - 16) = 16 / 114 = 0.14
- Field of view: 7.6 / 0.14 = 54 mm wide; 5.7 / 0.14 = 41 mm tall
- Object pixel: 54 mm ÷ 4000 = 13.5 µm
- Spring diameter: 6.0 mm ÷ 13.5 µm = 444 pixels across — clear of the 200-pixel comfort line
- Loop section: 8 mm ÷ 13.5 µm ≈ 590 pixels long, one-seventh of the frame width, inside the tenth-to-half band
Now teach the whole spring instead and the arithmetic turns against you. The field must reach 120 mm, so m = 7.6 / 120 = 0.063 and WD = 16 × (1 + 1 / 0.063) ≈ 270 mm. The spring then spans the full 4000 pixels end to end but only 200 pixels across its diameter, and sixty coils of it look identical. The pixel count survives; the geometry does not.
Aperture and exposure finish the set:
- At f/5.6 the depth of field is 2 × 5.6 × 0.0038 mm × 1.14 / 0.0197 ≈ 2.5 mm total. Thin — but a spring lying on a flat workplane keeps its loop within about a millimetre of the plane, so focus on the loop where it sits. On 1.9 µm pixels, diffraction past f/8 (Airy diameter 2.44 × 0.55 µm × 8 ≈ 10.7 µm, about 6 pixels) costs you more sharpness than the extra depth returns. The pixel-size trade behind this is laid out in small pixel camera selection: resolution versus usable detail.
- With the robot paused, 10 ms at f/5.6 under a standard ring is a normal exposure. Snapshot on the move at 100 mm/s and blur must stay under one pixel: 13.5 µm ÷ 100 mm/s = 135 µs, so strobe the light in 100 µs pulses.
Decision: 444 pixels across the wire, 590 pixels of loop, 2.5 mm of depth of field and a 135 µs strobe budget — the teach holds at 130 mm. Plug your own working distance and target field into the calculator to land on a focal length.
Calibrate high, snapshot low
At 130 mm the field is 54 × 41 mm and a standard calibration board is bigger than that, so the board cannot fit — exactly the wall the demo hit. The way through: the calibration position and the snapshot position do not have to be the same point in space.
Raise the camera until the whole board sits inside the field, filling roughly 70-90 % of the short side, and calibrate there. At 200 mm the field is 87 × 65 mm (m = 16 / 184 = 0.087), and a 55 mm board sits at 84 % of the short side. Then come back down to 130 mm and take snapshots.
Why this is sound: hand-eye calibration fixes the transform between camera and robot flange, and the robot knows the move between the two heights. The board must be flat on the same workplane and fully inside the field — the margins are the ones set out in calibration target field of view and lens coverage margins.
Focus and iris behave differently, and mixing them up is the classic failure:
- Focus sets the image scale. Focus on the loop at the snapshot height, lock the ring, and leave it alone.
- Iris does not change magnification. Stop down for the calibration frame if the board overexposes; with focus at 130 mm, the board at 200 mm carries about 0.35 mm of blur (1 mm aperture at f/16 × 70 mm ÷ 200 mm), and a symmetric blur disc does not bias a dot centroid.
Cameras, lens and light for these numbers
If the station is still on paper, selecting a machine vision system for parts inspection walks through the camera-versus-PC decision for this class of part. For the pixel count this example needs, the same 12 MP, 1/1.7" IMX226 sensor comes in two interfaces:
| Specification | LS-CMR-0053 | LS-CMR-0166 |
|---|---|---|
| Resolution | 4000 px x 3000 px | 4000 × 3000 (12MP) |
| Pixel size | 1.85 μm x 1.85 μm | 1.85 μm |
| Max. frame rate | 9 fps | 30 fps |
| Sensor model | IMX 226 | Sony IMX226 |
| Shutter | Rolling Shutter | rolling shutter |
| Data interface | GigE | USB 3.0 |
| Pixel bit depth | 8 / 10 / 12 bits | 10-bit |
| Price | $560.00 | $560.00 |
All 2 share: Sensor size 1/1.7". Values as printed in each product's data sheet; open a part for its drawing and full specifications.
The USB3 body at 30 fps suits a wrist snapshot station on short cables; the GigE body at 9 fps is plenty for a fixed overhead camera on a long cable run.
- Sensor format
- 1/1.7"
- Interface
- USB3
- Resolution
- 12 MP
- Shutter
- Rolling
The lens must cover the sensor with resolution to spare, and its image circle has to swallow the sensor whole. The LS-FFL-0567 is a 16 mm C-mount lens rated for 1.1" sensors at 20 MP, so a 1/1.7" sensor sits well inside its circle:
- Type
- Machine vision fixed
- Sensor format
- 1.1"
- Mount
- C-mount
- Resolution
- 16-25 MP
Shiny spring steel throws a specular stripe straight back at a bare ring. A diffused ring with the lens looking through its center calms the highlight — the same treatment shown for lighting shiny metal pins without glare — while a low-angle ring is the tool when you want the coil silhouette instead of the surface, the choice unpacked in machine vision lighting angles: surface or silhouette?.
- Size
- 100-200 mm
- Type
- Diffused
- Angle
- 30°
- Voltage
- 24 V
The LS-RNG-0143 is a 100 mm diffused ring with a 30° beam on 24 V. Browse wider ranges through the finders as your numbers move: area scan cameras, machine vision lenses, ring lights.
Teach it, step by step
- Pick the section. Loop plus two or three coil pitches; one-tenth to one-half of the field; 100 pixels minimum on the short side.
- Set the snapshot height. As close as the mechanics allow — 70 mm is the floor for wrist setups like the demo, which used 130 mm. Compute pixels across the diameter at that height before anything else.
- Focus and lock. Focus on the loop at the snapshot height, tighten the focus ring, set the iris between f/5.6 and f/8.
- Calibrate high. Raise the camera until the board fills 70-90 % of the short side and sits fully inside the field; calibrate; return to the snapshot height.
- Light it. Diffused ring on the loop; rotate the part a full turn and confirm no hot band rolls across the loop.
- Teach the model. Capture at the snapshot height under production lighting; draw the model region on the loop only.
- Prove it. Place the part at random positions and rotations across the cell, 20 placements minimum. Pass at a score above 0.7, and at least 0.2 above the strongest wrong peak.
- Hand off the pose. Report the loop center plus the taught offset to the gripper point.
Verify the teach
- Static repeatability. Leave the part still and re-run detection 10 times; the reported loop center should scatter by less than 0.5 pixels, about 7 µm at this magnification. The robot itself repeats to a few hundredths of a millimetre, so the matcher is not the weak link.
- Rotation sweep. Turn the part in 30° steps through a full revolution; the score should stay flat within a few points.
- Disturbed-part test. Bend one coil pitch slightly and re-run. A loop teach must still find the loop — the coils are not in the model.
- Empty-scene test. Run detection on the bare workplane and on neighbouring parts; nothing should score near threshold.
The bench sequence for trialling lens and light together before you commit is in machine vision lens and lighting selection: a test plan.
When a section is the wrong thing to teach
- The whole part must be inspected. A feature teach locates; it does not examine. Add a second pass at longer working distance for the full spring, or a line-scan pass when parts stream past on a conveyor — the approach in an area scan camera run in line scan mode.
- The loop itself varies. Left- and right-hand loops between part variants need one model per variant, selected by recipe.
- The diameter is under 100 pixels even at the floor. At 70 mm the 16 mm lens gives a 26 mm field and 6.4 µm pixels, so a 0.5 mm wire is 78 pixels — short. Move to a shorter-working-distance or macro option from the lens finder.
- The part is featureless round wire. Drop correlation for a silhouette: low-angle ring, dark background, locate the axis and measure — the method in machine vision dimensional measurement for small parts.
Checklist before you teach
- Section chosen: rigid, unique, one-tenth to one-half of the field, 100 pixels on the short side
- Pixels across the diameter computed at the snapshot height (floor 100, target 200)
- Snapshot height at the mechanical limit (70 mm wrist floor; 130 mm in the example)
- Focus locked at the snapshot height; iris between f/5.6 and f/8
- Calibration board flat, fully inside the field, at 70-90 % of the short side
- Model captured under production lighting and part finish
- 20-placement sweep passed with a 0.2 false-peak margin
- Grasp offset taught from the loop center and checked on the robot
When the part family changes, rerun the arithmetic and the lens step of the system configurator; if the numbers will not close, bring the part to us through the contact page and we will size the station with you.
Questions
Why does a long spring fail to match even when the whole part fits the field of view?
Because the geometry repeats. Slide the model along the coil axis by one pitch and almost nothing changes, so the correlation surface is a ridge rather than a peak, and the reported position can jump a full pitch between shots. Coils that flexed since teaching pull the score down everywhere at once, even though the part is good. Teach one rigid feature and the periodicity problem disappears.
Can the calibration height and the snapshot height be different?
Yes, and with small fields they usually must be. Hand-eye calibration fixes the camera-to-flange transform, and the robot knows the move between the two heights. Keep the board flat on the same workplane and fully inside the field, and lock focus before calibrating. Refocusing, not the height change, is what corrupts a taught offset.
How many pixels across a thin part do I need for a reliable teach?
Treat 100 pixels across the smallest taught dimension as the floor and 200 as comfortable. Below about 50 pixels, one pixel of edge shift moves the score several points, so pass thresholds overlap with wrong locations. The arithmetic is diameter divided by the object pixel size: 6 mm divided by 13.5 µm gives 444 pixels at the example height.
Do I have to physically cut the spring to teach it?
No. Cutting was a bench shortcut to isolate the loop at a trade-show demo. In production you teach a region of interest inside a full image of the part: draw the model on the loop section only, and the matcher searches for that region wherever the whole spring lies. Cut a sample only when you want a quick demonstration part.
What if the spring has no loop or any unique feature?
Use the cut wire end, whose tail geometry exists once on the part, add a marked fiducial at a fixed spot, or drop correlation for a silhouette pass: low-angle ring, dark field, locate the axis and measure the diameter instead of matching. Truly featureless round wire is a metrology task, not a template task.
How close can a wrist-mounted camera get to the part?
In the demo setup the wrist camera's floor was 70 mm above the workplane, set by body and connector clearance rather than optics. The spring teach used 130 mm to leave room for lighting. Check your own wrist collision envelope, then compute pixels across the diameter at that height before committing to a lens.


