Skip to content

fix: camera calibration script and add ability to scale homography matrix - #420

Draft
jphzazueta wants to merge 3 commits into
autowarefoundation:mainfrom
jphzazueta:main
Draft

jphzazueta wants to merge 3 commits into
autowarefoundation:mainfrom
jphzazueta:main

Conversation

@jphzazueta

Copy link
Copy Markdown

Camera calibration

I noticed that Calibration/calc_front_camera_homography.py was always failing with the following error:

cv2.error: OpenCV(5.0.0) D:\a\opencv-python\opencv-python\opencv\modules\objdetect\src\calibinit.cpp:666: error: (-211:One of the arguments' values is out of range) Both width and height of the pattern should have bigger than 2 in function 'cv::findChessboardCorners'

Interestingly, the official documentation does not mention this. However, the issue was pretty clear from the error message, so the script was adapted to work with a 4x4 checkerboard instead.

In order to help with debugging --debug-mask and --save-frame were also added as CL arguments. I personally found --debug-mask especially useful for figuring out a good placement for the checkerboards, as it allows you to see which ones are not getting detected.

The ability to use video as an input was also added, using the first frame of the video as the calibration image.

Scaling

After fixing the pattern size error, there was the issue of OpenCV failing to properly detect some of the checkerboards. I tried moving them around the camera view, which helped with the detection, but the two top checkerboards could not get identified with the camera resolution of 1024x512. Since I'm working inside a simulation software, I temporarily changed the resolution to 2048x1024, and this allowed a successful calibration.

Calibration/scale_H.py is meant to scale down the homography matrix to then work with the lower resolution of 1024x512. Of course, this was just my specific case, and any combination of resolutions can be used, as long as they both have the same aspect ratio.

Readme

Calibration/README.md was updated to reflect the new changes.

…d and also allow video as an input.

Add some extra arguments useful for debugging.
Replace 2x2 checkerboard with a 4x4 one of the same size.
…o a different resolution with the same aspect ratio.

Update calibration README.md.
@jphzazueta jphzazueta changed the title Fix camera calibration script and add ability to scale homography matrix fix: camera calibration script and add ability to scale homography matrix Sep 15, 2026
@jphzazueta
jphzazueta marked this pull request as draft September 15, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant