Mixed parts arrive in one tray, and the robot or PLC has to know which size each piece is before it picks. Teaching one reference image per size works, but every new size then means another teaching run and another locate node in the program. Measuring beats recognising here: one snapshot, every object segmented, each one classified by calibrated size. This how-to sets that up on a smart camera or vision sensor. You will calibrate millimetres per pixel, segment and measure every blob, set thresholds with real margin, and run the checks that prove the sorter before it goes live.
Teach one class or measure every blob
The locate-per-class route teaches each object, then runs one locate command per class. Each locate behaves like an if-statement inside the robot program, and a flag or state variable records which class matched. It is the right tool when the classes also differ in appearance — print, shape, texture — because the reference carries that too. The cost is growth: every new size means a new teaching run and one more locate node to maintain.
The measure-everything route skips teaching. One segmentation pass finds every connected region in the snapshot, measures its pixel area and bounding size, and the classifier is plain arithmetic on calibrated pixels. A new size is one more number, not a new reference. When the classes share a shape and finish and differ only in size, this is the method to build, and the rest of the page sets it up.
| Teach per class, locate each | Segment and measure | |
|---|---|---|
| Decides with | match to a taught reference | calibrated pixel size |
| New size | new teaching run + new locate node | one more threshold band |
| Separates shapes too | yes | no |
| Weak spot | reference ages with wear and lighting | parts touch, or sizes sit too close |
Both routes run from one snapshot of a separated tray. If the parts differ in several dimensions rather than one, the same calibrated pixels feed the fuller check in part identification by dimensions. And if the task is picking every object out of the tray rather than sorting by size, the multiple object detection in one snapshot workflow slots in ahead of this classifier.
Calibrate the field of view first
Every threshold below stands on one number: millimetres per pixel. Do not compute it from the nominal focal length and working distance, because lens tolerance and set-up error put that estimate off by a few percent. Put a known width in the field instead: a 60.0 mm gauge block spanning 720 px gives s = 60.0 / 720 = 0.0833 mm per pixel. Store s in the classifier and recalibrate whenever the lens, the working distance or the mount moves.
To plan the field before anything is mounted, work from the lens equation: field width = sensor width x working distance / focal length. The lens focal length calculator runs it backwards from the field a part needs. The gauge calibration still happens after mounting, because it absorbs the real lens and set-up tolerances.
Two limits frame the field. Locate tools generally refuse objects smaller than about 10% of the field's shorter side — 7.5 mm on a 100 x 75 mm field — so keep the smallest part dimension well above that line. A part larger than the field is a different problem altogether, covered in template matching a part larger than the field of view.
What you need
- A smart camera or vision sensor that runs connected-component (blob) analysis on board, or a camera with your own image library. The smart cameras range runs from 0.3 MP sensors to over 25 MP smart cameras, most with the inspection running on the device.
- One stable light. Backlight through a glass or slotted plate gives the cleanest silhouette; where the fixture blocks it, dark field or a low-angle ring lights rims and leaves flats dark.
- A known-width gauge for calibration, at least a third of the field wide.
- Presentation that separates parts: at least half the smaller part's width of free space between neighbours.
- A PLC or robot link — digital outputs or fieldbus — carrying one count and one centroid per class.
Three units from the range cover the pixel budgets worked below: a 1.6 MP mono vision sensor, a 5 MP colour model on Fast Ethernet, and a 6 MP SC5000X series smart camera with an 8 mm M12-mount lens.
- Interface
- Fast Ethernet
- Resolution
- Up to 3 MP
- Interface
- Fast Ethernet
- Resolution
- 5 MP
- Interface
- GigE
- Resolution
- 6-10 MP
Where the light and the processor should live inside the camera itself, the 1.6 MP LS-SMC-0063 carries a 16 mm lens, white light and a 60 fps rate — one part instead of three.
- Interface
- GigE
- Resolution
- Up to 3 MP
From snapshot to sorted output: the steps
- Fix the geometry. Square the camera to the part plane and keep parts at one height. Measured size shifts by roughly the height change divided by the working distance: at a 300 mm working distance, ±3 mm of height wobble moves every reading by about ±1%.
- Light for an outline. Backlight gives a silhouette whose edge stays soft within 1 px; dark field or a low-angle ring does the same job where backlight cannot reach.
- Calibrate with the gauge: s = gauge width / pixel span. Write s into the classifier.
- Segment: binarise, then label connected components. Drop specks below about 100 px² — under 1 mm across at 0.083 mm/px — so dust and swarf stay out of the count.
- Measure each blob: pixel area and bounding width and height. For round parts, turn area into an equivalent diameter, d = sqrt(4A / π), which ignores rotation.
- Threshold mid-gap. Convert each class's tolerance extremes to pixels, place each boundary between the largest small part and the smallest large part, and hold at least 20% margin to both sides. A gap that cannot clear 20% needs a narrower field or more pixels, not a finer threshold.
- Output and log. Send one count and one centroid per class to the PLC or robot; the cluster centroid method turns those centroids into pick positions. Log every measured value, so drift shows as a moving distribution, not a sudden fault.
Worked example: separating 30 mm and 55 mm caps in one 120 x 90 mm snapshot
- Classes: moulded caps at 30 mm ± 0.5 mm and 55 mm ± 0.5 mm diameter — the two objects to separate, tolerances as ordered.
- Sensor: 1.6 MP in a 4:3 array, so 1440 x 1080 px (example input for this class of camera).
- Field: set to 120 mm wide, covering 1080 x 0.0833 = 90 mm high.
- Presentation: caps flat, separated and backlit.
The rule: convert every tolerance extreme to pixels with s, put the boundary mid-gap between the largest small cap and the smallest large cap, and hold at least 20% margin on both sides so a 1 px edge flicker cannot flip a class.
Both margins clear the 20% floor. The nominal class areas sit far from the boundary: a 30 mm cap reads 360 px across, so its area is 0.7854 x 360² = 101,800 px², and a 55 mm cap reads 660 px, so 0.7854 x 660² = 342,100 px². The locate floor clears too: the smallest cap dimension, 29.5 mm, is 33% of the 90 mm shorter field side, above the 10% minimum. One pixel of edge error is 0.083 mm, about 0.3% of the small cap's diameter — invisible next to a 22-28% margin.
Set the classifier at 510 px bounding width, or 204,300 px² of area for round parts: below is the 30 mm class, above is the 55 mm class. The margins, 28% down and 22% up, absorb the ±0.5 mm tolerance with room for segmentation noise. If a third size ever lands inside the 366-654 px gap, the margin check fails first — move to a 6 MP sensor at the same field, which roughly halves s and doubles the pixel gap, and re-run the margins before the new class ships. The same chain, worked end to end for coins, is in coin size sorting with a single camera.
Prove it before it runs alone
- Twenty runs of each class alone: the spread stays within 2 px and the mean sits within 1% of the gauge.
- Twenty mixed runs with zero flips. Plot the measured values per class; if any class's worst value comes within 10% of a boundary, reopen the margin before production.
- Rotate a non-round part through 90°: bounding width changes with angle. Classify on area, on both bounding axes, or constrain the part — the trade-off is set out in bounding box area vs object area.
- Slide a part to each corner of the field: lens distortion can stretch an edge-of-field blob by a pixel or two. Keep classified parts inside the central 80% of the field, or calibrate the distortion out.
- Switch the room lights off mid-run. If any classification moves, the light is not stable; shield the station or strobe the light off the camera trigger.
When size alone gives the wrong answer
Touching parts merge into one blob: the merged area lands in the wrong class and the count drops. Space the parts, or measure height instead — a 3D snapshot tells a two-high stack from a single part that a top view merges into one. Where overlapping piles are the normal case, a projected structured-light 3D camera returns the height layer that the 2D view cannot see.
- Type
- Stereo / structured light
Same size, different shape or print: size cannot decide, so do not ask it to. Hand those parts to taught references or edge matching; the edge based pattern matching method holds its results when lighting drifts, and the score threshold reading tells you whether a match was real.
Parts that differ only in thickness — same footprint, different height — are invisible to a 2D top view. That is a job for the 3D sensors range: the 2D or 3D for pick and place comparison walks the choice, and 3D vs 2D machine vision covers the wider case.
Common mistakes
- Calibrating from nominal lens data instead of a gauge: a 2% lens tolerance becomes a 2% size error on every part, enough on its own to eat a 20% margin.
- Classifying a tilted non-round part on bounding width: the width reads long as the part rotates.
- Letting the margin slide below 10% because the nominal sizes look far apart on paper: tolerances and pixel noise take the difference you thought you had.
- Open ambient light: the binarisation threshold drifts across a shift as sunlight and ceiling lights change. Shield the station, or strobe the light and trigger the camera together.
Pick the hardware, then the thresholds
The pixel budget decides the camera: 1.6 MP carries the 30 mm / 55 mm example with margin to spare, while tighter gaps or a third class need 5-6 MP at the same field. Walk the camera finder or the configurator below with the field and tolerance numbers from your drawing, and send the parts list through the quote form — the thresholds come back with the camera. More one-snapshot workflows sit on the applications topic page, and anything odd about the presentation is worth a note to the applications team.
The configurator matches a camera, lens, light, light controller and cables to each other, step by step, and lists only parts that fit what you already picked.
Questions
How accurate is a pixel-based size measurement?
Edge uncertainty dominates: a ±0.5 px edge error moves a measured diameter by about 1 px. At 0.083 mm per pixel that is 0.083 mm on the 360 px (30 mm) cap, roughly 0.3% of the diameter and 0.6% of the pixel area. Gauge calibration keeps the absolute value near 1%, and height variation adds its own share — about 1% of size per 3 mm of height at a 300 mm working distance.
Can one snapshot sort three or four different sizes?
Yes, with bands instead of one boundary. Convert each class's tolerance extremes to pixels, put a boundary mid-gap in every adjacent pair, and check that each gap still clears 20% margin. At 0.083 mm per pixel a 30 / 45 / 55 mm set fails that check: the 45-55 gap is only about 108 px wide, which leaves roughly 9% margin, so that set needs a 6 MP sensor or a narrower field.
Does adding a new size require re-teaching the camera?
No. Segment-and-measure has no per-class teaching: a new size is one more threshold band computed from the new part's drawing tolerances, then checked against the 20% margin rule. You recalibrate millimetres per pixel only when the lens, sensor or working distance changes. Taught-reference locating works differently — each new class needs its own teaching run and its own locate step in the robot program.
What happens when parts touch or overlap in the image?
Two touching blobs read as one merged region, so both the count and the classification come out wrong. Leave at least half the smaller part's diameter of free space between parts, use a vibratory feeder or singulator, or move to height data — a 3D snapshot separates a two-high stack that a 2D top view merges. If overlaps are rare, flag merged blobs and divert them to a manual check.
Should the camera use a global or rolling shutter for a moving sorter?
If parts move during the exposure, choose a global shutter sensor. A rolling shutter scans line by line and skews a moving part, and that skew shows up directly as size error. A stationary or indexed tray tolerates either type. Trigger the exposure from the fixture's in-position signal and keep the exposure short enough that motion blur stays under one pixel at your millimetres-per-pixel value.




