Hi, I’m trying to calibrate my raspberry pi camera (HQ model) but I’m getting strange results for the distortion coefficients.
I’m using the C++ calibration code provided by the official opencv tutorial : opencv/camera_calibration.cpp at 3.4 · opencv/opencv · GitHub
I’m using 26 images with different angles and positions.
The undistorted images I get seem strange to me and I’m wondering if I’m doing something wrong, or if it’s just normal.
Here are the distortion coefficients, and the camera matrix
-0.4320 ; -0.08962 ; 0 ; 0 ; 1.0006
4036.7 ;0 ; 2027.5
0 ; 4036.7 ; 1519.5
0 ; 0 ; 1
The code uses a config file ( opencv/in_VID5.xml at 3.4 · opencv/opencv · GitHub ), so I’ve tried to tweak some of the parameters. For example, not setting the k4 and k5 coefficients to zero (true by default), assuming zero tangential distortion, fixing aspect ratio, or using a fish eye model. Overall, it doesn’t really make much difference. What do you recommend for these parameters?
Also, the re-projection error is around 0.9. Do you think that’s an acceptable error ?
I’m trying to get the most accurate calibration results possible because I need to get precise pose estimation of aruco markers.
Do you have any suggestions to improve the calibration results ?
Thanks for the response, I’ll try with a bigger chessboard. The problem is that the working distance of the camera is about 1-2 meters, so I’ll need a really big chessboard for it to cover about half the area of the picture at this distance.
you hold a regular A4/letter sheet that’s not even using all its area for a board.
get at least double the area, and fill it well.
if you don’t feel like buying a professionally made board, at least get some MDF or other engineered material for backing. natural wood, as well as corrugated cardboard, is more likely to warp. MDF can too but usually it’s sold straight.
1-2m may be your working distance for which you dial in the focus but if you go closer with the board and it doesn’t get too blurry, that’s ok too.
You said the image looks strange to you - can you elaborate?
based on the black curved area at the top / bottom, it looks like your lens has a moderate amount of distortion (including an undistorted input image in your post would be helpful)
One quick test you can do to evaluate calibration accuracy is to load your undistorted image into Gimp (or your favorite image editing program) and use the measurement tool (or anything that can make a straight line) to gauge how straight the undistorted world lines are. (The edge of the door, the calibration target, etc) I did this with your image, and things looked pretty good to me.
Even better is to draw lines to the undistorted images that coincide with the calibration target world points. I do this and have found that it is a good visual sanity check.
Is 0.9 accurate enough? That depends on your application and the accuracy that it requires. You can probably improve on the 0.9 number, but how much improvement (and how much effort) depends on a number of factors.
Example of drawing lines to the undistorted image. I look for how well the lines follow the calibration target edges, and how tightly grouped the lines are at the intersection area. In this case the reprojection error was approximately 0.15.
To draw the lines I call projectPoints on the world coordinates of the calibration target, then create “infinite” lines that correspond to row/column edges, and then draw those lines to the undistorted image. Make sure you use the cv::line() drawing function with sub-pixel values to get an accurate line position (I typically use 3 shift bits).
Hi, thanks for taking the time to answer. Here’s the same image before processing.
What I meant by strange was that I didn’t expect those black deformations on the undistorted image, but I guess it’s normal when the lens has some distortion.
I tried to draw straight lines to the undistorted output image and to the input image and it’s much better on the output image : the door for example is much straighter, but it’s not completely straight. Same for the lines on the checkerboard.
I think I’ll try to reduce the re-projection error because I need accurate measurements.