Knowledge / Mechatronics / Machine vision

Machine vision

Mechatronics (B.E./B.Tech) · Robotics · free study notes for exams, placements and interviews

In short

Machine vision is the use of cameras, lighting, optics and image-processing algorithms to let a machine or robot measure, inspect, locate and identify objects automatically. In robotics it closes the loop between sensing and motion — the camera tells the robot *where* the part is, so the robot need not rely on fixtures holding every part in an exact pose. It is examined in Mechatronics and Robotics papers, in GATE (Instrumentation, EC and the Mechanical "mechatronics/measurement" sections) and in automation electives, usually through camera geometry, image-processing steps, resolution calculations and system block diagrams. Indian employers — Bosch, Tata Motors, Maruti Suzuki, Hyundai, Ather, Cognex/Keyence India partners, Addverb, GreyOrange, Omron, ISRO and the semiconductor and pharma packaging industry — hire for vision inspection and vision-guided robotics roles.

Explained

What a machine vision system contains

Image fundamentals

Image-processing pipeline (standard exam sequence)

  1. Acquisition: trigger (encoder or photo-sensor), expose, transfer; fix gain, exposure and lighting so they never float.
  2. Pre-processing (enhancement/restoration): noise removal — mean/Gaussian filter (blurs edges), median filter (best for salt-and-pepper, preserves edges); contrast stretching, histogram equalisation; shading/flat-field correction; geometric distortion correction.
  3. Segmentation: separate object from background — global thresholding, Otsu's method (automatic threshold maximising between-class variance), adaptive/local thresholding (for uneven lighting), region growing, watershed, edge-based segmentation, colour segmentation in HSV.
  4. Edge detection: gradient operators Sobel, Prewitt, Roberts; Laplacian (second derivative, zero crossings); Laplacian of Gaussian (LoG); Canny — the optimal multi-stage detector: Gaussian smoothing → gradient magnitude and direction → non-maximum suppression → hysteresis double thresholding.
  5. Morphological operations (on binary images, with a structuring element): erosion shrinks and removes specks; dilation grows and fills pinholes; opening = erosion then dilation (removes noise, keeps size); closing = dilation then erosion (closes gaps); hit-or-miss, thinning/skeletonisation, boundary extraction, blob/connected-component labelling.
  6. Feature extraction: area, perimeter, centroid, bounding box, orientation from second moments, circularity 4πA/P², aspect ratio, Euler number (holes), Hu moments (invariant to translation, rotation, scale), Hough transform (lines and circles from edge points), corner detectors (Harris), keypoint descriptors (SIFT/SURF/ORB — ORB is free of patent issues and standard in OpenCV).
  7. Recognition/decision: template matching (normalised cross-correlation), geometric pattern matching (rotation/scale-tolerant), classical classifiers (k-NN, SVM), and CNN-based deep learning for cosmetic defects that cannot be described by rules.
  8. Measurement and output: convert pixel results to millimetres via calibration, compare against tolerance, issue PASS/FAIL or a pose to the robot, log the image.

Camera model, calibration and 3D

Vision-guided robotics and visual servoing

Performance, selection and limitations

Key points

Formulas and examples

Pinhole projection: u = fx·(Xc/Zc) + cx ; v = fy·(Yc/Zc) + cy — u, v in pixels; Xc, Yc, Zc in mm (camera frame); fx, fy in pixels; (cx, cy) principal point in pixels
Full model: s·[u v 1]ᵀ = K·[R | t]·[Xw Yw Zw 1]ᵀ — s = scale (= Zc), K = 3×3 intrinsic matrix, R = 3×3 rotation, t = 3×1 translation (mm)
Magnification: m = (image sensor size) / (field of view) = f / (WD − f) ≈ f / WD for WD ≫ f — WD = working distance (mm)
Lens equation / focal length selection: f ≈ (sensor dimension × WD) / FOV — all lengths in mm
Pixel resolution (spatial sampling): R = FOV / (number of pixels along that FOV), in mm/pixel
Minimum camera resolution: N = (FOV / smallest feature size) × (pixels per feature, 2 to 3)
Radial distortion (Brown): x_d = x(1 + k1r² + k2r⁴ + k3r⁶), r² = x² + y² — x, y normalised image coordinates
Stereo depth: Z = f·b / d — f (pixels), b = baseline (mm), d = disparity (pixels), Z (mm)
Depth uncertainty: ΔZ ≈ (Z² / (f·b))·Δd — shows error rising with the square of range
Image-based visual servoing: ṡ = L(s, Z)·v ; v = −λ·L⁺·(s − s*) — s = feature vector, v = camera twist (6×1), λ = gain, L⁺ = pseudo-inverse of the image Jacobian
Circularity: C = 4πA / P² (= 1 for a perfect circle); Area A in pixels² or mm², perimeter P in pixels or mm
Centroid of a blob: x̄ = (Σ xᵢ)/n, ȳ = (Σ yᵢ)/n over the n object pixels
Otsu: maximise σ²_b = ω₀ω₁(μ₀ − μ₁)² over threshold t — ω = class probabilities, μ = class means
Exposure limit for motion blur: t_exp ≤ (allowed blur in mm) / (part speed in mm/s)

Example 1 — Lens and resolution selection for a gasket inspection. Field of view required 120 mm × 90 mm, camera 2,448 × 2,048 px, sensor 2/3″ (8.45 mm × 7.07 mm), working distance fixed at 300 mm, smallest defect 0.3 mm.

Example 2 — Motion blur and strobe timing. Parts move on a conveyor at 0.5 m/s = 500 mm/s; allowed blur is half a pixel at 0.049 mm/pixel = 0.0245 mm.

Example 3 — Stereo depth and its uncertainty. Stereo pair: f = 1,200 px, baseline b = 80 mm, measured disparity d = 48 px, disparity matching accuracy Δd = 0.25 px.

Example 4 — Pixel-to-world calibration and a robot pick. A fixed overhead camera views a flat conveyor. Two known marks 200.0 mm apart appear 3,968 px apart.

Example 5 — Throughput check. Exposure 0.05 ms, image transfer of a 5 MP mono image over GigE at 100 MB/s effective ≈ 5,000,000/100,000,000 s = 50 ms, processing 25 ms, I/O 2 ms.

Aspect2D vision3D vision
Outputx, y, θ on a plane; grey/colour featuresx, y, z plus surface normals, full 6-DOF pose
Typical sensorArea-scan or line-scan cameraStereo, laser triangulation, structured light, ToF
StrengthFast, cheap, mature, high lateral accuracyHeight, volume, warp, bin picking, variable-height parts
WeaknessNo height; sensitive to perspective and lightingSlower, costlier, struggles on shiny/transparent surfaces
Example useLabel OCR, presence check, flat-part pickingWeld seam tracking, bin picking, dent/flushness checks
Filter/operatorWhat it doesUse it for
Mean / GaussianAverages neighbourhoodGeneral Gaussian noise; blurs edges
MedianTakes neighbourhood medianSalt-and-pepper noise, edges preserved
Sobel / PrewittFirst-derivative gradientFast edge magnitude and direction
Laplacian / LoGSecond derivative, zero crossingsFine edges, blob detection; noise-sensitive
CannyMulti-stage optimal detectorThin, connected, well-localised edges
Erosion / dilationShrinks / grows binary regionsSpeck removal, hole filling
Opening / closingErode-dilate / dilate-erodeClean binary mask before blob analysis
# Classical pipeline: locate a part on a conveyor and report its pose in mm
import cv2, numpy as np
img  = cv2.imread("part.png", cv2.IMREAD_GRAYSCALE)
img  = cv2.medianBlur(img, 5)                       # salt-and-pepper noise
_, bw = cv2.threshold(img, 0, 255,
                      cv2.THRESH_BINARY + cv2.THRESH_OTSU)   # auto threshold
k    = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
bw   = cv2.morphologyEx(bw, cv2.MORPH_OPEN, k)      # remove specks
cnts, _ = cv2.findContours(bw, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
c    = max(cnts, key=cv2.contourArea)               # largest blob = the part
M    = cv2.moments(c)
cx, cy = M["m10"]/M["m00"], M["m01"]/M["m00"]       # centroid in pixels
(_, _), (w, h), theta = cv2.minAreaRect(c)          # orientation in degrees
A, P = cv2.contourArea(c), cv2.arcLength(c, True)
circ = 4*np.pi*A/(P*P)                              # circularity, 1 = circle
SCALE = 0.05040                                     # mm per pixel, calibrated
print(round(cx*SCALE, 2), round(cy*SCALE, 2), round(theta, 1), round(circ, 3))

Where it is used

Interview questions

Common mistakes

Related topics

Robot kinematics · Robot programming and ROS basics · Industrial robots and applications · Sensors and transducers in mechatronics · Digital image processing · PLC and industrial automation · Machine learning for perception

Open in the Knowledge reader →Find jobs →