MOULDLKnowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › General Engineering & Case Studies › How to Select a Machine Vision
HomeModels
Table of contents

General Engineering & Case Studies (60 articles)

Knowledge Base Home

📐 Standard Data

🧮 Calculators

📖 Selection Guides

🏭 Material Grades

❓ Engineer FAQ

🗂 Quick-Reference Categories

❌ Error Case Studies

📚 Technical Articles

How to Select a Machine Vision Camera and Lens: Resolution, Focal Length and Depth of Field in Six Steps

🛠️ Baisi Technical Handbook · Intelligent selection and calculation for 500+ standard parts
Covers the full range of pneumatic / motor / power transmission / reducer / coupling / bearing / hydraulic / pneumatic / thread / worm / spring parts
Avoid 95% of design errors, improve design efficiency by 80%
Master 10 years of senior engineer experience in 3 months
Download: https://pan.baidu.com/s/1bquayZpfas6oYBbG0gp3Gw?pwd=2giv

📖 Next issue: Sheet Metal Flattening Calculation

The most common failure in vision selection is not "cannot capture it clearly" but capturing it clearly yet not measuring it accurately. Pixel accuracy, magnification, depth of field and diffraction all constrain each other: to see a larger object you need a short focal length, and a short focal length makes the pixel accuracy coarse; to extend the depth of field you stop down, and stopping down blurs the edges through diffraction. Below we use a dimensional inspection case of a 50×30 mm stamping part, calculating from the field of view through to the aperture in six steps, and then expand into the formulas.

I. Complete Worked Example

Step 1 — Nail down the duty conditions
ItemValueSource
Object size50 × 30 mm (outline + two locating holes)Part drawing
Measurement accuracy requirement0.05 mmTolerance band ÷ 3
Working distance WD225 mmMeasured from the conveyor surface to the camera mounting flange
Takt≥ 15 pieces/secondLine takt
Surface being viewedStamped steel part, with an oil film producing reflectionsOn site

If any one of these five numbers is missing, nothing after it can be calculated. The accuracy requirement must come from the tolerance band, not from writing down 0.01 mm off the top of your head — raising the accuracy by one band quadruples the number of pixels and triples the price.

Step 2 — Field of view FOV with a margin
FOV = object size × (1 + 10%)

FOVX = 50 × 1.1 = 55 mm  FOVY = 30 × 1.1 = 33 mm

That 10% is not waste; it is reserved for positioning error: 2 mm of cylinder loading offset, 3 mm of belt tracking drift, 1 mm of fixture wear, which together eat more than 5 mm. Without a margin the direct consequence is that a part occasionally lands at the edge of the frame and the inspection station starts missing parts at random.

Step 3 — Calculate the minimum resolution and fix the camera pixels
Nmin = FOV ÷ pixel accuracy requirement

By the Nyquist sampling rule, one accuracy unit must fall on at least 2 pixels:

NX = 55 ÷ (0.05/2) = 2200 px  NY = 33 ÷ 0.025 = 1320 px

Calculating all the criteria gives very different answers:

CriterionMeaningRequired resolutionCorresponding camera
2 px/accuracyThe Nyquist floor, the theoretical minimum2200 × 13203MP 2048×1536 (barely)
3 px/accuracyCommon for production inspection, allowing for edge uncertainty3300 × 19806MP 3072×2048 (slightly short)
4 px/accuracyHigh-reliability measurement, where repeatability must be assessed4400 × 26408MP and above

This example takes the 2 px floor plus a sub-pixel edge algorithm, and selects a 6MP 3072 × 2048, pixel 2.4 μm, 1/1.8″. Why not 3 px? Select the lens first and then come back to this — resolution is not the only variable.

Step 4 — Calculate the focal length (the step most easily got wrong)

Many references give f = WD × sensor ÷ FOV directly, which is the thin-lens approximation and only holds when the magnification is much less than 1. In this case the magnification is 1:8 and the error is already 12%, so the exact formula must be used:

m = sensor width ÷ FOV width → f = WD · m / (1 + m)

6MP sensor (effective imaging area) = 3072 × 2.4 μm = 7.373 mm (height 4.915 mm)

m = 7.373 ÷ 55 = 0.1340

f = 225 × 0.1340 ÷ 1.1340 = 26.6 mm → select the standard 25 mm

The focal length can only be rounded down, not to the nearest.The approximation gives 30.2 mm and the closest standard lens is 35 mm — fitted, the actual FOV is only 40.0 × 26.7 mm, so a 50 mm wide part does not fit in the frame at all. Taking 25 mm gives an FOV of 59.0 × 39.3 mm, which safely covers it.
Step 5 — Back-calculate the actual pixel accuracy
Pixel accuracy = actual FOV ÷ camera resolution

Lateral = 58.98 ÷ 3072 = 0.0192 mm/px (19.2 μm)
Vertical = 39.32 ÷ 2048 = 0.0192 mm/px ✓ the two directions agree (the 3:2 sensor matches the 3:2 FOV)

How many pixels does each 0.05 mm accuracy unit fall on:

0.05 ÷ 0.0192 = 2.60 px

2.60 px clears the 2 px floor but does not reach the 3 px safe value. This result shows that adding more pixels is useless — an 8MP camera with a 35 mm lens only reaches 18.7 μm, still 2.67 px, because the larger sensor forces a longer focal length and the FOV grows with it, cancelling out on both sides. To genuinely improve the accuracy you must reduce the FOV or move to a larger sensor with a longer WD, not simply pile on pixels.

ConfigurationSensorRequired focal lengthSelected focal lengthActual FOVPixel accuracypx/accuracy
2MP 1620×12207.13×5.3725.82557.0×42.935.2 μm1.42 ✗
3MP 2048×15367.07×5.3025.62556.5×42.427.6 μm1.81 ✗
5MP 2448×20488.45×7.0730.02567.6×56.527.6 μm1.81 ✗
6MP 3072×20487.37×4.9226.62559.0×39.319.2 μm2.60 ✓
8MP 4096×300014.13×10.3546.03576.7×56.218.7 μm2.67
Step 6 — Depth of field and diffraction: squeezed out in two directions

The magnification m = 25 ÷ (225 − 25) = 0.125 (1:8), and the circle of confusion is taken as 2 pixels c = 2 × 19.2 μm = 0.0384 mm.

DOF = 2 · N · c · (1 + m) / m²
Aperture NDepth of field DOFAiry disc diameterAs a fraction of a pixelAssessment
F1.47.7 mm1.88 μm0.78 pxDepth of field rather thin
F2.011.1 mm2.68 μm1.12 pxUsable, small margin
F2.815.5 mm3.76 μm1.57 pxSelected in this example
F4.022.2 mm5.37 μm2.24 pxThe edges begin to blur
F5.631.0 mm7.52 μm3.13 pxDiffraction eats the accuracy

The part has an 8 mm flange height difference, and adding 2 mm of belt bounce the depth of field needs to be at least 10 mm. The 11.1 mm of F2.0 just scrapes past, while the 15.5 mm of F2.8 leaves a 50% margin and the 1.57 px diffraction spot is still within an acceptable range. F2.8 is the sweet spot for this set of parameters.

The diffraction limit expression:

dAiry = 2.44 · λ · N (λ = 0.55 μm)

The criterion: the Airy disc diameter ≤ 2 pixels. Beyond 2 px the edge transition band widens and the accuracy of the sub-pixel algorithm falls away sharply. Enough depth of field ≠ the smaller the aperture the better — the two are squeezed from opposite directions.

Step 7 — Lighting, interfaces and bandwidth

① Light source: measuring the outline of a stamping uses parallel backlighting

The surface has an oil film, and forward lighting produces random highlights on the workpiece so the edge position drifts with them. Parallel backlighting turns the part into a pure black silhouette, maximising the edge contrast so that the sub-pixel algorithm is stable. Hole detection benefits in the same way — a hole is a bright void in the silhouette.

② Interfaces and bandwidth

Bandwidth = resolution × bit depth ÷ 8 × frame rate

3072 × 2048 × 1 B × 15 fps = 94 MB/s, and the practical bandwidth of GigE is about 110 MB/s, so it is enough.

But if the output is 12 bit (1.5 B/px): 94 × 1.5 = 142 MB/s, over the Gigabit Ethernet limit. Either switch to 8 bit or go to 10GigE / Camera Link. If this step is skipped, the symptom after installation is dropped frames, corrupted images and occasional timeouts, which is extremely tedious to diagnose.

Step 8 — Final configuration sheet
ComponentSpecificationKey reason
Camera6MP 3072×2048, 2.4 μm, 1/1.8″, global shutter, GigE2.60 px/accuracy; the global shutter avoids motion smear
Lens25 mm prime, C-mount, F2.8, maximum image circle ≥ 1/1.8″f=26.6 can only be rounded down; an insufficient image circle darkens the corners
Working distance225 mm (FOV 59.0 × 39.3 mm)Leaves an 18% lateral margin
Light sourceParallel backlight 90 × 90 mm, white (or red 625 nm)Silhouette measurement, suppresses oil-film reflections
Light controller2-channel digital dimming, 256 levelsCalibratable brightness, no re-tuning when the batch changes
ApertureF2.8 (depth of field 15.5 mm, diffraction 1.57 px)The balance point between depth of field and sharpness

Acceptance criteria: repeatability ≤ 0.005 mm (about 1/4 of a pixel), and a deviation of ≤ 0.02 mm against a vernier caliper. After installation, run 30 standard parts through a GR&R study first — do not simply judge whether a single image looks clear.

📐 This algorithm does not need hand calculation
The Baisi Technical Handbook has integrated this calculation module into the Group 2 Selection Enhancement calculation module. Enter the duty parameters and it automatically outputs the selection result. Say goodbye to paging through handbooks, to hand calculations and to rule-of-thumb estimates. —— Baisi Technical Handbook download https://pan.baidu.com/s/1bquayZpfas6oYBbG0gp3Gw?pwd=2giv

II. The Basics of the Four Main Elements of Machine Vision

1. The camera: what matters is the sensor and the pixel size, not the pixel count

For the same 5 megapixels, a 2/3″ sensor gives a 3.45 μm pixel while a 1/1.8″ sensor may be only 2.4 μm. Smaller pixels mean lower sensitivity, a smaller full-well capacity and a narrower dynamic range, but better accuracy over the same field of view. The larger the sensor, the more expensive the lens and the shallower the depth of field — this is a complete cost chain.

SensorWidth × height (mm)DiagonalTypical pairing
1/3″4.8 × 3.66.0Small FOV, low-cost inspection
1/2″6.4 × 4.88.0General entry level
1/1.8″7.18 × 5.328.93The mainstream for 2~6MP
2/3″8.8 × 6.611.0The 5MP industrial standard
1″12.8 × 9.616.0High-accuracy measurement
4/3″18.0 × 13.522.5Large format, defect inspection
The "1/1.8″" in the sensor specification is a package code, not the width of the imaging area. The real imaging area must be calculated from resolution × pixel size: 3072 × 2.4 μm = 7.373 mm. The focal length must be calculated with this true value; using the 7.18 mm from a code lookup table introduces a 3% error.

2. The lens: prime, zoom or telecentric — three routes

TypeCharacteristicsApplicationsPrice order
PrimeLow distortion, large aperture, simple constructionFixed station batch inspection, 90% of cases1×
ZoomThe FOV can be adjusted on site, but distortion changes with the focal rangePrototype commissioning, many varieties in small batches2~3×
TelecentricThe chief rays are parallel, no perspective error, the magnification stays constant over the depth of fieldPrecision dimensional measurement, parts with a height difference8~20×

The f = WD·m/(1+m) formula cannot be applied to a telecentric lens: its magnification is determined by the double telecentric optical structure, so the nominal 0.5×, 1× and 2× are selected directly and the working distance is also fixed in a few discrete steps. Using the ordinary lens formula for a telecentric lens always gives a wrong answer.

3. The light source: decide the lighting method first, then talk about brightness

Lighting methodWhat you seeTypical applications
Parallel backlightA pure silhouette, the sharpest edgesOutline dimensions, hole positions, gap measurement
Ring lightSurface texture, scratchesAppearance defects, characters
Coaxial lightSpecular reflection, suppresses reflectionsPolished metal surfaces, glass, chips
Low-angle lightHighlights raised features and pitsEmbossing, scratches, raised characters
Dome lightShadow-free uniform illuminationCurved surfaces, complex highly reflective parts

The order must not be reversed: first decide the lighting method by the feature you need to see, then size it by the field of view, and only then adjust the brightness. Doing it the other way round usually ends up buying a very bright lamp with the feature still not visible.

4. The interface: calculate the bandwidth first, then choose the type

InterfacePractical bandwidthCable lengthApplications
USB 3.0~350 MB/s≤ 5 mStandalone, low cost, below 2MP
GigE~110 MB/s≤ 100 mMultiple machines on a line, long distances (the most common)
10GigE~1000 MB/s≤ 100 mHigh frame rate, large sensors
Camera Link~680 MB/s≤ 10 mHigh-speed line scan, retrofitting older lines

III. Core Calculation Formulas

1. Field of view FOV

FOV = object size × (1 + margin factor) , margin 10%~20%

2. Minimum resolution

Nmin = FOV ÷ (accuracy requirement ÷ k) , k = 2~4 px

k=2 is the Nyquist floor, k=3 the production-safe value, and k=4 is used for precision measurement where repeatability is assessed.

3. Magnification and focal length (exact form)

m = sensor size ÷ FOV  f = WD · m ÷ (1 + m)

The approximation f ≈ WD × sensor ÷ FOV has a negligible error only when m < 0.05. At m ≥ 0.1 the exact form must be used, otherwise the selected focal length comes out too long and the field of view is insufficient.

4. Actual pixel accuracy

Pixel accuracy = actual FOV ÷ camera resolution (mm/px)

Both the lateral and the vertical must be calculated and the two values must be close, otherwise the sensor aspect ratio does not match the field of view aspect ratio and pixels are wasted.

5. Depth of field

DOF = 2 · N · c · (1 + m) / m² , c taken as 2 pixels

The more precise form (near and far object distances):

H = f²/(N·c) + f  Lnear = WD(H−f)/(H+WD−2f)  Lfar = WD(H−f)/(H−WD)

In this example at F2.8: DOF = 15.48 mm, near 217.5 mm, far 233.0 mm, which differs from the approximate form by 0.02 mm, showing that the approximation is sufficient when m < 0.2.

6. The diffraction limit

dAiry = 2.44 · λ · N , requirement dAiry ≤ 2 × pixel size

For white light take λ = 0.55 μm. At F4 it is 5.37 μm, already occupying 2.24 pixels, and the edges begin to go soft. So the depth of field is not something you stack up by stopping down.

7. Transmission bandwidth

Bandwidth = resolution × bit depth/8 × frame rate ≤ practical interface bandwidth × 0.8

IV. Parameter Selection Reference Tables

Accuracy requirement → pixels per accuracy unit

Applicationk valueExplanation
Presence/absence judgement, coarse positioning1~2No dimensional measurement
General dimensional measurement2~3Combined with a sub-pixel edge algorithm
Precision measurement, GR&R assessment3~4Fixture and thermal drift have to be considered
Defect inspection (based on the defect size)3~5The smallest defect must occupy at least 3×3 pixels

Common accuracy requirements and camera selection (FOV around 60 mm)

Accuracy requirementPixels needed at k=3Recommended cameraPixel accuracy
0.10 mm18002MP 1620×122037 μm
0.05 mm36006MP 3072×204819 μm
0.02 mm900012MP 4096×300015 μm
0.01 mm1800020MP + telecentric lens6 μm

Aperture selection quick reference (m = 1:8, pixel 19 μm)

ApertureDepth of fieldDiffraction as a fraction of a pixelRecommended scenario
F1.4~F27.7~11.1 mm<1.2 pxThin sheet and flat parts, where the sharpest edges are needed
F2.815.5 mm1.57 pxThe general first choice
F422.2 mm2.24 pxHeight differences, relaxed accuracy requirements
F5.6 and above>31 mm>3 pxNot recommended for measurement

V. Common Errors and How to Avoid Them

Wrong practiceConsequenceCorrect practice
Using the approximation f = WD×sensor/FOV for the focal length and then taking the "closest" standard lensThe approximation is 12% long, and stepping up one more size shrinks the FOV from 59 mm to 40 mm, so the part does not fit in the frameUse f = WD·m/(1+m) and only round down to a standard focal length, then back-calculate the FOV to check
Using the package code to look up the sensor size (1/1.8″ = 7.18 mm)The focal length is 3% off and parts at the edge occasionally fall out of frameCalculate the real imaging area from resolution × pixel size
Selecting the camera at 2 px/accuracy and considering it doneJust enough in theory, but the measured repeatability is poor and GR&R failsTake 3 px for production and 4 px for precision measurement, or explicitly use a sub-pixel algorithm and verify the repeatability
Estimating the depth of field as "aperture number × pixel accuracy × a constant"This example gives 19 mm when the actual value is only 11 mm, and the mechanism is designed for 19 mm, so half the parts are out of focus after installationDOF = 2Nc(1+m)/m² with c taken as 2 pixels; the larger m is, the shallower the depth of field, and it is not a linear relation with the pixel accuracy
Stopping all the way down to F8 to extend the depth of fieldThe 10.7 μm Airy disc occupies 4.5 pixels, the edges blur into a gradient and the sub-pixel accuracy collapsesCalculate the diffraction first, with dAiry ≤ 2 pixels as the limit; if the depth of field is insufficient, change the mechanism or move to a telecentric lens
Calculating only the resolution and not the bandwidth6MP 12 bit at 17 fps needs 160 MB/s while Gigabit Ethernet only provides 110 MB/s, so frames are dropped and images are corrupted after installationBandwidth = resolution×bit depth/8×frame rate with a 20% margin; if it exceeds the limit, use 8 bit or move to 10GigE
Using ring forward lighting to measure the dimensions of a reflective metal partThe oil-film highlights drift randomly and the edge position moves by more than 0.05 mmSwitch to parallel backlighting to form a silhouette, which maximises the edge contrast and stabilises the sub-pixel result
One-line mnemonic: the field of view sets the resolution, the magnification sets the focal length, and the depth of field and diffraction squeeze out the aperture. Once these three steps are done, the camera, lens and light source are essentially settled; what remains is the bandwidth and the acceptance criteria.
Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Mechanical Engineering Knowledge Base · free self-study reference for machine designers, 3D CAD models at MOULDL