Building My Own Tool Scanner — Part 8: The Lens Rabbit Hole
The scanner worked.
The physical tests worked.
The C920 was giving me the accuracy I actually needed.
So naturally, I decided this would be an excellent time to start changing things.
There was one part of the system that had bothered me throughout development:
The image could be sharper.
The Logitech C920 is a perfectly decent webcam.
But it isn't an industrial machine-vision camera.
And if I'm trying to determine the edge of an object as accurately as possible, a sharper image should make that edge easier to locate.
At least, that was the theory.
Enter the M12 lenses
I started experimenting with replacement M12 lenses.
Different fields of view.
Different focus characteristics.
More control over exactly what the camera could see.
I tested approximately 58° and 65° lenses, hoping to get a sharper image while still covering the complete scanning area.
And initially, it seemed like a very sensible upgrade.
Better optics.
More control.
Potentially better focus.
What could possibly go wrong?
Quite a lot, apparently. 😂
More distortion, not less
The replacement lenses introduced significantly more barrel distortion than the original C920 optics.
Straight geometry towards the edges of the image became increasingly distorted.
Now, technically, I already had a calibration system designed to model spatial distortion.
So this wasn't necessarily fatal.
In theory:
Let calibration deal with it.
But calibration can only do so much with the information available.
The stronger distortion also meant I was losing usable grid information around parts of the image.
Rows of calibration points that had previously been comfortably visible were now becoming problematic.
I'd gained some control over focus...
But made the geometry considerably worse.
Better in one way isn't necessarily better
This became another recurring lesson from the project.
Changing one component doesn't improve one isolated property.
It changes the system.
A lens might produce a sharper centre.
Great.
But if it also creates considerably more distortion towards the edges, reduces the usable field of view and makes calibration less stable, have I actually improved anything?
For this application:
Probably not.
The scanner doesn't need the prettiest photograph.
It needs the most useful measurement.
Those are not the same thing.
Back to the stock lens
Eventually I abandoned the M12 experiment and refitted the original C920 lens.
But while doing that, I spent more time getting the stock lens properly centred and focused.
And something rather interesting happened.
The calibration got better.
After refitting and recentering the original optics, my hold-out results improved substantially.
Random hold-out P95 dropped from roughly:
0.185 mm → 0.145 mm
The random maximum error dropped from approximately:
0.550 mm → 0.306 mm
Checkerboard P95 improved from roughly:
0.187 mm → 0.141 mm
The centre of the workspace was particularly good, with a regional P95 of approximately:
0.093 mm.
So after experimenting with replacement optics...
One of the best improvements came from putting the original lens back in properly. 😂
So that was that?
Not quite.
The lens experiment had made me wonder about something else.
The C920 gives me a 1920 × 1080 image.
That's just over two megapixels.
What would happen if I gave exactly the same calibration system considerably more image data?
I happened to have an old Samsung Galaxy A3 sitting around.
Its camera could produce images at around 8 megapixels.
It cost me nothing.
And I already had Python, ADB and a complete calibration system waiting to abuse it.
There was only one sensible thing to do.
Next: Part 9 — More Pixels Must Be Better... Right?
The C920 worked.
The replacement lenses didn't improve it.
So instead of changing the lens...
I changed the entire camera. 😂
