Operations · 7 min read
Camera focus measurement for a fixed camera that slowly goes soft
A lens loosened by vibration fails over weeks, and the model suffers before anyone sees blur. A sharpness score against the camera's own history catches it.
Summary
This post explains how to measure focus on a fixed industrial camera with a sharpness score computed on every frame, and how to set the threshold from that camera's own history rather than a universal number. It concludes that the score belongs in the same alert path as the model's doubted frames, with the frame attached, so a loosened lens becomes a maintenance ticket. It is for the engineers who keep line cameras running.
Rajiya Sultana · Engineering Manager · Sep 27, 2026

Bottling line under a fixed camera, bottles and caps boxed, generated scene with detections from our model
The camera over the capper on the bottling line was focused by hand on the March morning it was mounted, with a technician on a step ladder turning the ring until the cap threads came up sharp on the monitor. It has held that focus for eleven weeks. The capper vibrates, the bracket carries the vibration, and somewhere in week twelve the lock screw on the focus ring backs off a fraction of a turn.
Nobody sees it happen, because nobody is looking at the raw feed. The model is, on every frame, and it is the first thing to suffer.
A lens loosened by vibration is the failure nobody reports
A loose focus ring does not fail on a date. It creeps. The image on Monday is a shade softer than the image the previous Monday, and the shade is well inside what a person glancing at a monitor would call fine. By the end of the month the cap threads are a grey smear, and the only record of when it started is in the model's behaviour.
This is the shape of most camera failures on a line, and the reason they go unreported: there is no event. A knocked bracket is at least a thing that happened. A lens creeping out of focus is a thing that is happening, slowly, to a feed that still looks like a feed. The drift catalog has a name for the step-shaped causes, a moved camera, a replaced sensor, a firmware change, and each of those leaves a ticket. Focus creep leaves none, which is why it has to be measured rather than reported.
Object detection degrades before anyone on the line sees blur
The cap detector was trained on sharp frames. A missing cap, a cocked cap and a properly seated cap are told apart by the edge of the thread and the line where cap meets glass, and those are the features that soften first. On a Monday frame that a person would still call sharp, the model's boxes on the small classes start to wander and the doubted frames start arriving. Object detection on the class that matters most, the cocked cap, degrades first because it depends on the finest edge.
The line notices weeks later, when the count of cocked caps that reached the case packer stops matching the count the model reported. By then the frames from the soft weeks have been reviewed, corrected and, if nobody checked, trained on.
A sharpness score is a number computed from edges on every frame
Focus can be measured from the frame alone, with no reference image, because a sharp frame has more high-frequency content than a soft one. The common measure is the variance of the Laplacian: convolve the greyscale frame with a Laplacian kernel, which responds to edges, and take the variance of the result. Sharp edges give a high variance; blur flattens it. There are alternatives, a gradient-based measure such as Tenengrad among them, and they agree on the ordering that matters, so the choice is less important than the discipline of computing one on every sampled frame and keeping the history.
Two practical details decide whether the number means anything. The score has to be computed on the same region of the frame every time, the capper head and the bottle necks passing it, because the conveyor rail and the far wall have their own sharpness and would swamp the signal. And it has to be computed at the resolution the model sees, after any resize in the pipeline, because a resize is itself a blur.
The variance of the Laplacian was first popularised as an autofocus measure for microscopes, where the specimen moves and the lens stays put, which is the opposite of the problem on the line.
The threshold comes from the camera's own history
There is no universal sharpness number. The score depends on the lens, the lighting, the region and the content, and the same camera will score differently at 6 am with the shutters up and at 2 pm under the skylights. A threshold copied from another camera, or from a tutorial, will either alarm constantly or never.
The threshold that works is a fraction of that camera's own baseline, built over the first sharp weeks and compared like with like: the same hour, the same shift pattern, the same product running. On the bottling line the score dips every time the line switches from clear glass to amber, because amber bottles have less contrast at the neck, and a baseline that does not know the product schedule will call every amber run a focus failure.
Compare each camera against itself. The camera at the labeller has a different lens, a different distance and a different baseline, and the only number it shares with the capper camera is the fraction.
A step in the score is a knock and a slope is the lens creeping
The history does more than set the threshold. Its shape says what happened. A step down at the exact hour a crew washed the housing on Tuesday is a knock, and the fix is a technician with a step ladder. A slope over weeks is the ring backing off, and the fix is the same technician plus a drop of thread locker. A step down on every camera at once, on the night of a recorder update, is a compression change, and the catalog files that under a firmware or encoding change because the lens is fine and the bitrate is not.
The sharpness score cannot tell those apart on its own. The score plus the change log can, and that is why the score is logged per camera per hour rather than checked once a day.
The alert is a maintenance ticket with the frame attached
The score drops below the fraction for a full shift, and a rule fires: a sentence, with a severity and a cooldown, approved before it went live. The capper camera is soft, routine, to the maintenance channel, with the frame attached so the person reading it can see the smear on the threads and judge from a phone whether it is a wipe or a refocus. A cooldown of a shift means the ticket is raised once, not every two seconds until someone climbs the ladder.
On the lines we run this goes through the same path as the model's own alerts, described in a sentence and delivered to Slack or email, because a maintenance team with two channels reads one of them. My own view is that focus belongs in the review queue beside the model's doubted frames rather than on a dashboard of its own. A dashboard is opened when something has already gone wrong. A doubted frame arrives before that.
The frames from the soft weeks are not training frames
The last thing a loose lens does is poison the next model. The doubted frames from the soft weeks come back to a person, the person corrects the boxes as best they can on a blurred cap, and those corrections are queued to train the next version. A model trained on soft frames learns that a cocked cap is a grey smear, and it will carry that lesson back onto the sharp frames once the lens is fixed.
LexData takes the cap model through its whole life. You type what to look for, Lexi puts a box on every frame, and a person checks each label before anything trains on it. The model then watches the camera over the capper, in the cloud, on your servers, or on a runner beside the recorder. Frames it is unsure of come back to a person, the corrections retrain it, and the new version replaces the old one with no downtime. The sharpness score is what keeps the soft weeks out of that path: frames below the fraction are held rather than corrected, and the retrain waits for the lens.
See it on your own footage.
Start with your footageMore in Operations

Operations · 7 min read
Active learning for computer vision on a line camera that never stops
The weld camera runs three shifts. The model returns the frames it doubts, the inspector corrects them, and past the threshold a new version trains and ships.
Rob Hickey · Sep 27, 2026

Operations · 6 min read
Danger zone monitoring with object detection on a site camera
A polygon over the crane swing radius on a site camera. People and vehicles as classes, the bottom of the box as the test, the alert with the frame attached.
Esdras Ntuyenabo · Sep 27, 2026

Operations · 8 min read
Collecting image training data from a production line without keeping every frame
A carton line's model starts missing a new print. Sample the frames it doubts, drop near-duplicates, review them, and let corrections train the next version.
Sheikh Srijon · Sep 27, 2026