fix: camera calibration script and add ability to scale homography matrix - #420
Draft
jphzazueta wants to merge 3 commits into
Draft
jphzazueta wants to merge 3 commits into
jphzazueta wants to merge 3 commits into
Conversation
…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
marked this pull request as draft
September 15, 2026 10:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.