You have an area scan camera on the line and a trained detector waiting for its frames, and the instinct from classical machine vision says filter the image first. That instinct is usually wrong for deep learning. The model's own loader resizes, pads and normalizes, while hand-applied filters delete the gradients and texture the network was trained on. This guide gives you the letterbox arithmetic, the pixel budget that decides whether your smallest feature survives the resize, and the exposure number that replaces denoising. A 50-frame test settles the question on your parts, with camera and controller numbers to match.
Do you need OpenCV preprocessing before YOLO inference?
Usually no: feed the raw 8-bit frame straight to the model. Its own pipeline resizes and normalizes the image, while filters such as denoising, sharpening or edge detection strip texture and gradients the convolution layers would have used to find the part.
A convolutional network is itself a stack of learned filters. Trained on raw frames, it absorbs your lighting, your sensor noise and your part textures. A Canny edge map or an adaptive threshold throws away the gray-level structure those learned filters key on. Classical preprocessing belongs to hand-coded pipelines, where every rule had to be explicit. A detector replaces those rules, so the filter chain that used to be step one becomes a bug.
The one thing you must still do yourself is deliver the frame the way training saw it: same bit depth, same geometry, same 8-bit pixels. That is acquisition, not filtering, and the sections below put numbers on it.
What does YOLO already do to every frame you send it?
The framework letterboxes each frame to a fixed square input — 640 × 640 by default. It resizes so the shorter side fits, pads the rest, then scales pixel values to 0-1. The resize, pad and normalize steps you would otherwise hand-code are already done for you.
A 4000 × 3000 frame into a 640 input: s = 640/4000 = 0.16, so the frame lands as 640 × 480 inside 160 rows of padding. Nothing about your parts changed, but every feature shrank to 16 % of its raw extent — exactly the number the pixel budget below manages. Recent framework versions divide by 255 and stop there; the resize-pad-normalize sequence is the documented preprocessing path of the library.
Because the input size is fixed, a frame your code delivers at the wrong size either fails or distorts — YOLO inference image size mismatch: fix visual accuracy is the repair guide. Stretching instead of padding silently changes object shapes, and the geometry must match between training and deployment; direct stretch resize vs letterbox: match training and inference shows the difference.
Which classical filters hurt detection accuracy, and why?
Median, Gaussian and bilateral denoising, Canny edges, adaptive thresholding and histogram equalization all compress or discard gray-level information. A detector trained on raw frames scores worse when you remove that information before inference.
Blur kernels merge neighboring pixels; a median filter deletes the speckle that separates a real pit from a highlight. Thresholding turns 256 gray levels into two, a decision better left to training. Equalization remaps contrast by a curve computed from each frame, so the same part looks different every cycle. The network learned on raw statistics; feed it anything else and you are testing a model on data it never saw.
Two acquisition details are not filters. A mono frame carries all the information a mono sensor ever had, and the loader replicates it across the three input channels — see feeding grayscale images to a 3-channel model input. And noise added at training time is augmentation, not preprocessing: it widens the conditions the model tolerates. One reason a model trained on many varied images survives a dirty lens — sizing that training set is covered in how many images to train an object detection model.
When does preprocessing before inference actually help?
Preprocessing pays when it fixes the image before the network sees it — exposure, motion blur, focus, mounting geometry and cropping to the inspection region. These change what reaches the sensor, not what the model does with it.
Crop to the inspection region. Suppose only a 1600 px wide strip of a 4000 px wide frame ever contains parts. The strip letterboxes at s = 640/1600 = 0.40 instead of 0.16: 2.5× more pixels on every feature at the same input size, for one crop rectangle. The same ratio lets you drop imgsz to 256 with pixels-on-feature unchanged, because 256/1600 = 0.16 — and 256² is 16 % of 640², roughly six times less input compute.
Square the geometry. A camera mounted 5° off square turns circles into ellipses and shifts labels. Fix the mount, or rotate the feed before the network — rotate a camera feed before neural network detection covers the transform and its cost.
Calibrate the sensor once. Fixed-pattern noise and lens shading are calibration applied identically to every frame — capture-side work like dark frame subtraction for fixed pattern noise: how many frames — not a filter chain in the inference loop.
How many pixels does your smallest feature need at the network input?
Keep the defining dimension of the smallest feature at 10-20 pixels after the letterbox resize. The first detection grid reads the image in 8-px cells, so a feature under about 10 input pixels sits inside a single cell and the head cannot place it reliably.
A 12 MP, 4000 × 3000 sensor gives this budget real headroom, and 30 fps over USB3 keeps a belt fed:
- Sensor format
- 1/1.7"
- Interface
- USB3
- Resolution
- 12 MP
- Shutter
- Rolling
Worked example — a 1.5 mm scratch on a machined face, imaged over a 200 × 150 mm field of view:
- mm_per_px = 200 mm / 4000 px = 0.05 mm/px.
- Raw pixels on the scratch: 1.5 mm / 0.05 mm/px = 30 px.
- Letterbox into a 640 input: s = 0.16, so px_input = 30 × 0.16 = 4.8 px. Under the 10 px floor: the detector will miss it or guess.
- Decision rule for this geometry: feature_mm ≥ 10 × mm_per_px / s = 10 × 0.05 / 0.16 = 3.1 mm. Anything smaller needs one of three fixes:
- Tighten the field of view to 80 × 60 mm: 0.02 mm/px, 75 raw px, 75 × 0.16 = 12 px at the input. Costs a lens and stand change only.
- Crop to the 1600 px strip: s = 0.40, 30 × 0.40 = 12 px. Costs nothing if the fixture holds part position.
- Raise imgsz: 1280 gives s = 0.32 and 30 × 0.32 = 9.6 px, still short; 1600 reaches 12 px at (1600/640)² ≈ 6.3× the input compute. Last resort.
The camera configurator pairs sensor and lens to a tighter field of view. Choose YOLO imgsz from your smallest object size turns this same budget into an imgsz choice. Frames too large for one pass go to tiling instead — minimum defect size for anomaly detection: pixels, tiling, cropping.
Can preprocessing rescue motion blur or sensor noise?
No: software cannot undo motion blur, and denoising before inference deletes the fine detail a detector keys on. The fix is a shorter exposure with more light at capture, which removes the blur where it happens, on the sensor.
A belt at 120 mm/s under the 0.05 mm/px optics above wants exposure ≤ 1 × 0.05 / 120 = 0.42 ms. If the scene cannot deliver that in available light, add light or slow the line; sharpening afterwards creates artifacts the model never saw in training. Minimum exposure has mechanics of its own — see does minimum exposure time include sensor readout time.
Rolling shutter adds skew: rows expose at different instants, so a part at speed leans. Global shutter ends that at the source:
MV-CH120-11UC pairs a 12 MP global shutter with USB3 for these moving-part stations:
- Sensor format
- 1.1"
- Lens mount
- C-mount
- Interface
- USB3
- Resolution
- 12 MP
Sensor noise rises with gain, and the cure is photons, not filters. Noise you cannot eliminate belongs in the training set — photograph it, label it, let the model learn it — while fixed pattern goes to the calibration link above.
What hardware runs YOLO inference on the line?
For one or two cameras, a fanless vision controller with an Intel Core i5-class CPU and 32 GB of memory is the standard host. CPU inference covers inspection tempos at a 640 input, and PoE ports plus built-in light channels run the station from one box.
Inference time scales with S², so the imgsz decision above is also the throughput decision. The crop-plus-256 option from the pixel section moves about six times the frames per second of the plain 640 pipeline. Object detection without a GPU: CPU inference for inspection works through when a CPU host is enough and when to step up.
Size the host from the camera plan: PoE ports where the cameras take them, one light channel per strobed light, USB3 where the cameras need it. The vision controllers category filters on all three. A box sized that way:
MV-VC5525-256G70-NN brings PoE camera ports, 8 built-in light channels and 32 GB of memory around an Intel Core i5:
- LAN ports
- 5+ LAN ports
- USB 3 ports
- 3-4 USB 3 ports
- PoE
- PoE camera ports
- Light outputs
- 8 built-in channels
Choose the camera side first — the area scan camera finder filters by resolution, shutter and interface — then check the host against it with the system configurator.
How do you prove preprocessing helps on your own parts?
Run a 50-frame ablation: label production frames, evaluate the raw pipeline, then add one change at a time and keep only what raises recall on the smallest class by 2 or more points — measured, not eyeballed.
- Collect 50 production frames that span the lighting range of a full shift.
- Measure pixels on the smallest feature in the raw frames, using the budget from the pixel section.
- Run the model on the raw frames; record recall and precision per class.
- Add one change at a time — crop, exposure, imgsz, then at most one candidate filter — and re-run the same 50.
- Keep a change only at +2 recall points or better on the smallest class; drop everything else.
- Time 100 inferences before and after any imgsz change: the input-pixel ratio above predicts the speed ratio, minus loader overhead.
| Change | Fixes | Cost at inference |
|---|---|---|
| Crop to the ROI (4000 → 1600 px strip) | Input pixels on feature, 4.8 → 12 px in the example | None |
| Tighter field of view (200 → 80 mm) | Resolution at the sensor | Lens and stand |
| imgsz 640 → 1600 | Small features at the input | ≈ 6.3× input compute |
| Exposure ≤ 0.42 ms | Motion blur | Lighting budget |
| Denoise, sharpen, equalize | Nothing the model needs | Recall drops |
The decision, case by case: geometry, light and exposure get fixed before capture; the ROI gets cropped; imgsz rises only when the first two cannot reach 10 px on the feature. No filter stays in the pipeline without a measured 2-point win. If the station is still on paper, the systems topic hub gathers these choices in one place, and the team answers camera-to-model questions on the contact page.
Questions
Can I feed 12-bit camera frames to a detector directly?
Convert to 8-bit first: the network input is 0-255 per channel, and a 12-bit stream usually arrives in a 16-bit container with values shifted up. That inflates bandwidth and can render near-black if scaled wrong. Set the camera's pixel format to 8-bit output, or scale the 16-bit values down by 16.
Does CLAHE or histogram equalization improve detection accuracy?
Rarely at inference. The network learned contrast statistics from raw training frames, and equalization remaps them every frame by a curve computed from that frame. It earns a place only when you apply the identical equalization during training too. Even then better-placed or strobed light usually beats it on low-contrast parts. Let the 50-frame ablation decide.
Is a mono camera good enough for deep learning detection?
For most industrial classes, yes: shape, texture and grayscale contrast carry the decision, and a single-channel frame is valid input as delivered. Color earns its keep only when class identity lives in hue — wire colors, film tints, ripeness. Judge it with the ablation on your own classes before paying for color.
Should I sharpen images before object detection?
No. Unsharp masks amplify sensor noise and ring around edges — artifacts the model never saw in training. Get sharpness from the optics instead: correct focus at working distance, a resolution-matched lens and enough exposure. If focus drifts between shifts, that is a mechanical problem no filter should be hiding.
Can cropping before inference cause errors?
Yes, at the borders. A part half-inside the crop reads as a truncated object unless training contained truncated examples. Leave a margin of at least half the largest object's longest dimension on every side of the crop. Also make sure the staging fixture keeps parts inside that region cycle after cycle.


