r/computervision • • 4d ago

Research Publication LiteCalib: Camera Calibration from Single Image

https://kocurvik.github.io/litecalib

Hi we just released LiteCalib, a fast single-image camera calibration method. You give it one photo and it returns the focal length and lens distortion. Similarly to AnyCalib, it works with pinhole, radial, division, UCM/EUCM, Kannala-Brandt and other radially symmetric models. The network outputs an intermediate representation and you can choose which camera model you fit to it.

This is useful if you have distorted images (e.g. from action camera) and want to run a pipeline that was trained on pinhole images such as 3D reconstruction methods such as VGGT, Pi3, DepthAnythingV3, MapAnything, monocular depth estimators such as MoGe, UniDepth, SurGe or even classical pipelines like COLMAP. It can also estimate focal lengths for individual images if you need to use crowdsourced or user-provided images.

This is not new as previous methods such as AnyCalib or GeoCalib have similar capabilities. However, our network was trained using much broader distribution making it much more accurate than previous SOTA. We have also made the full camera calibartion faster by predicting only a sparse representation instead of dense one and making parts of the network much lighter. Our whole network with the camera model fit runs in 9.7 ms on A100 compared to 50+ ms for AnyCalib. We have also trained ViT-S and ViT-B variants when you are even more compute constrained.

Try it:

pip install litecalib

import litecalib

model = litecalib.load("litecalib_vitl")

calib = model.calibrate("photo.jpg", cam_id="division:1")

calib.K #pinhole intrinsics

undistorted = calib.undistort("photo.jpg") #undistorted image

- More info on our project page: https://kocurvik.github.io/litecalib

76 Upvotes

13 comments sorted by

3

u/blobules 4d ago

Any constraint on what is photographed? If not, how does it differentiate an undistorted view of a curved object from a distorted view if a straight object?

It seems to me that this can only work if you look at "known objects" (I.e. present in the training set). Is this the case?

1

u/kocurvik 4d ago

As with any trained network it may struggle on out of distribution data and even in-distribution there is some error. Compared to previous work we use a much broader training distribution. In man-made environments it will probably work well as there are usually many objects with approximately known geometry. For example even in buildings with weird architecture the windows and doors are usually still rectangular and it is easy for a network to learn this. Some adversarial scenes that are curved just right may confuse the network, but in general it is quite unlikely that the whole scene would be curved consistently with some specific camera model. In those cases the error would be higher, but hopefully not catastrophic. In many use-cases you can use our intrinsics as initialization and optimize them later so some error can ve corrected later.

All of this is harder for natural scenes. There are some in the training data and usually some geometric cues are available (often you can at least see the curvature of the horizon) so it may also work well enough even on such images. Of course if you give it an image of blue sky it will probably fail.

1

u/tdgros 3d ago

cool work! the fit-on-rays approach reminds me of dust3r

Do you have results on videos, so we can gauge the stability? I'm especially interested in models with more than just one distortion parameter.

2

u/kocurvik 3d ago

Thanks! The benchmark evals include InFlux and InFlux++ which are datasets of recorded videos with changing zoom and focus with GT intrinsics provided per-frame. For a video where intrinsics do not change it would actually be better to run inference on all frames and then fit the camera model to the output representation jointly. The API we provide already has this capability. We do not discuss this regime in the paper that much, but it is possible that there could be some improvements made.

2

u/tcdoey 3d ago edited 3d ago

Hey that's great. I do my own camera calibration with a color grid frame 3D printed. I should ask at the github these questions, but just jotting down here. I've been reading the code/md, so far just briefly and I don't see anything about color calibration, but your mapping method is far superior than my simple lens-optical transform-mapping method. Apologies, I'm a noob at this and prob using wrong terminology.

Does this do any kind of, or can added color calibration/grading step be intrinsically included? I know, it may not be necessary, and might just at first thought to leave as an outside step, but the issue I've seen is that color changes with depth on most cameras, becoming more 'vibrant' closer to the cam, and less further away, and even changing hue.

I could describe more but I think that's enough to get the reason for my question across. Thanks, and I'm going to continue to wade through this. Looks super.

1

u/kocurvik 3d ago

LiteCalib does not provide color calibration only camera intrinsics (geometric calibration). I am not familiar with color calibration. Though if the effect of colors becoming less vibrant occurs I would assume that the network could have learned that somehow.

If you have your own calibration pattern or grid and can freely take images of it then the resulting calibration will probably be more accurate than using LiteCalib as using calibration grids is the gold standard. For that you can use standard OpenCV methods such as Zhang's calibration method. LiteCalib is for situations where you cannot do that. So usually if you do not have access to the camera to take images of a calibration grid.

1

u/tcdoey 2d ago

Thanks! I will take all of that into consideration. For some situations/cameras using the cal grid is unfeasible, which is where your method will be very useful.

1

u/tdgros 1d ago

The fact that color fades with distance is not from the camera! it's the medium (air/clouds/fog/...) that affects the light's spectrum. You can find the simple models for hazing in any dehazing paper, here is a foundational one: https://people.csail.mit.edu/kaiming/publications/cvpr09.pdf

1

u/tcdoey 19h ago

Hey thanks, but it's not haze. This happens all the time with my webcam(s) in a simple room. I think it has something to do with 'well saturation', but it's probably more complex than that. Still, thanks for the link and info, I'll consider that.

Webcams have different firmware, which does some proprietary on-camera-chip processing that could (or might not) affect color-vs-distance. For example, when I'm sitting in front of my current webcam (nexigo n60) and I have an orange hat on, and I lean towards the camera the orange gets really 'oranger' (basically saturates), and when I lean back further away, the orange color then goes back to looking 'normal'.

So, because I can't change or adjust the cam's firmware, my option is to calibrate to a range. I hold a printed, known color target at various distances to the camera, using an RVM and 'depth anything' to get a quantified distance metric. I know this is very crude and innacurate, but at least it's something. Then I map the color saturation dependent on this crude depth estimation.

It's more of an educational exercise than a real-world need, unless of course you want very controllable and refined color correction for some good reason. If I can find the time, I'll make a video example.

Meanwhile, I've been working on this. Cheers!

https://youtu.be/xOrkg836aNs

1

u/tdgros 19h ago edited 19h ago

hmm, I've worked for quite a long time around sensor calibration and tuning and there's no such physical phenomenon apart from hazing, and the cameras absolutely do not measure distance... You're probably seeing a combination of white balance and denoising acting out (e.g. from up close you're lit by a different light than from afar, edit: because you block stuff, not because of the distance, lol).

If you really wanted to calibrate the colors, you'd take raw images of color checkers, under different light spectra. Raw means virtually out of the sensor, before all the ISP processings. You can find tutorials on color calibration all over the web. Michael Brown, from York University (and Samsung) has good papers on related subjects, and classes on ISP tuning.

You're trying to calibrate the color from a "normal" yuv stream, then you're seeing the image that went through white balance, color correction and tone mapping, which depend on the lighting conditions and have a subjective tuning (no camera is tuned towards "realism", no matter what you mean by it). That's not to say your attempt is dumb, but I'm pretty sure it won't generalize to other places, or even to different lightings in the room you're working in.

2

u/Ribhai 4d ago

Very useful.

1

u/3e8892a 3d ago

Nice! How does accuracy compare to printing a checkerboard and running opencv calibration?

And if I have video, can I gain a more accurate calibration by processing multiple frames?

1

u/bfyvfftujijg 3d ago

Nice! I’m surprised the big foundation models don’t have this capability “built in”.