Uniqueness of cameraMatrix from calibration

Unless you have a specific reason to use that or other webcams (for example, you are developing software that you want “anyone” to be able to use with an off-the-shelf camera), I would consider getting a different camera with a fixed lens - it makes things a lot easier. If you have an appetite for that option, I might be able to recommend a lens if you tell me your requirements - I have evaluated many dozens of lenses and have notes on most of them.

Be aware that, even if you can “lock” the focus setting via software, the actual focal length might vary from day to day or maybe minute to minute. I presume your webcam employs a voice-coil focusing system, and I have run into some repeatability issues on similar cameras. While testing one camera (voice coil focus, OV5640 sensor) I found that the focal length is pretty consistent, but does change over time (maybe thermal?). The bigger problem I ran into was significant image center shift over the first 30-90 seconds of operation. I attributed this to thermal changes as the camera heated up from use, but I don’t know if it was related to the voice coil focusing or something else about the specific camera. I don’t recall exact numbers, but I think the image center was shifting 5-10 pixels, which was more than enough to blow through my error budget.

If you stick with the webcam, you might want to query the CAP_PROP_FOCUS and CAP_PROP_AUTOFOCUS in addition to setting them. I seem to remember running into problems when setting the manual focus value and it not “sticking”. My memory is really foggy here, but, for example, if the camera reverts to auto-focus mode it might ignore any manual focus commands. Again, a camera that can’t possibly change the focus has advantages.

If you get desperate, you might be able to glue (epoxy) the lens in a fixed position. Get it focused how you want and carefully glue the lens around the perimeter, leave it alone for a lot longer than 5 minutes (overnight).

1 Like