Skip to content

Camera calibration with OpenCV and checkerboard #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 4, 2024

Conversation

g3force
Copy link
Member

@g3force g3force commented Jan 9, 2020

Based on the work of @rhololkeolke I've implemented the openCV chessboard calibration with intrinsic and extrinsic models.

So far, a calibration of the intrinsics with a chessboard can be done through a new widget. I've tested it with the original SSL FLIR cameras and a DIN A4 7x9 chessboard. The RMS error is shown and the result is saved.
Additionally, there is a button to calibrate the extrinsics based on the four field corner markers.

If enabled in the config tree (Camera Calibrator), the model is used for field2Image and image2Field, but the code is not yet optimized, especially the image2field where several matrix inversions are done.

The UI widget also still needs more structure.

I'll continue work on this, but if anyone wants to start testing this branch, you are welcome.

@g3force g3force changed the title WIP: Chessboard calibration Camera calibration with OpenCV and checkerboard Jan 26, 2020
@g3force
Copy link
Member Author

g3force commented Jan 26, 2020

This PR is ready to be reviewed and tested.

The calibration worked well for me with the FLIR SSL cameras. Compared to the old calibration procedure, distortion and principal point are much more reasonable given enough checkerboard samples.

I did not notice an increase in processing time, but I did not have a field with many robots yet. The imaga2field and field2image functions are slightly slower with the OpenCV method, but this should not be noticeable.

@tobiasheineken
Copy link
Contributor

This PR crashes on our PC with
(vision:8215) Gtk-ERROR **: 09:42:00.671: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported

gdb tells us

Thread 1 "vision" received signal SIGTRAP, Trace/breakpoint trap.
(gdb) bt
#0  0x00007ffff1e59ea1 in () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#1 0x00007ffff1e5af3c in g_log_default_handler () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#2 0x00007fff1e5b1cd in g_logv () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
...
#14 0x00007ffff6fa75af in QApplication::QApplication(int&, char**, int) () at /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#15 0x00005555556e5284 in main(int, char**) (argc=1, argc=0x7ffffffffe0c08) at /home/robotics/ssl-vision-chess/src/app/main.cpp:85

master does not have this crash on startup.

@g3force
Copy link
Member Author

g3force commented Feb 25, 2020

can you provide some details on your system like the OS?

@tobiasheineken
Copy link
Contributor

Sure. It's a "normal" Xubuntu 18.04:

$ uname -a
Linux robolab 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$lsb_release -a
No LSB modules are available
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic
$

@g3force
Copy link
Member Author

g3force commented Feb 25, 2020

Have you run the install script? https://github.com/RoboCup-SSL/ssl-vision/blob/master/InstallPackagesUbuntu.sh

And do you have a self-compiled opencv?

@tobiasheineken
Copy link
Contributor

$ opencv_version
3.2.0
$ sudo apt install libopencv-dev
libopencv-dev ist schon die neueste Version (3.2.0+dfsg-4ubuntu0.1)
$ sudo apt install libv4l-0
libv4l-0 ist schon die neueste Version (1.14.2-1)

Sorry for German printouts. Our opencv is (probably) not self compiled, and while I didn't run this installer script today, we most certainly did so a few months ago and the packages seem to be correct.

@g3force
Copy link
Member Author

g3force commented Feb 25, 2020

I can reproduce the error message on a SSL NUC when building with QT4. Building with QT5 seems to fix the issue. You can switch by running:

cmake -DUSE_QT5=true build/
make

It might be time to make QT5 the default...

@tobiasheineken
Copy link
Contributor

This allows me to start the vision. Thanks @g3force. I'll test the PR later.

Any clue why this PR triggers a conflict with QT4?

@g3force
Copy link
Member Author

g3force commented Feb 27, 2020

It might be the additional opencv module 'calib3d' that was introduced in this PR.

@rhololkeolke
Copy link
Contributor

Are there any other blockers to merging this in once the current conflicts are fixed?

@tobiasheineken
Copy link
Contributor

@rhololkeolke I used to test this in our lab (Feb 2020) and it did not work at all. It's reasonable I did something wrong, but I never made it work. Nicolai has published a lot of commits since then, but I cannot test it due to COVID restrictions right now.

@g3force
Copy link
Member Author

g3force commented Jan 25, 2021

I improved the capturing of the chessboard samples since then, but it still needs more testing.

The main issue though is, that I'm not yet satisfied with the quality of the result. The overall calibration is not as good as with the old implementation and I could not yet find out the source for this.
I've tried other optimizers, but that did not help. I rather expect an issue in the transformation between image to field and vice versa.

@g3force g3force force-pushed the chessboard-calibration branch from f21e991 to be384f3 Compare November 28, 2021 10:06
@g3force g3force force-pushed the chessboard-calibration branch 3 times, most recently from 39c958a to c6be58f Compare December 12, 2021 15:50
@g3force g3force force-pushed the chessboard-calibration branch 2 times, most recently from a5622f2 to 5a0d09e Compare January 7, 2022 18:27
@g3force
Copy link
Member Author

g3force commented Jan 13, 2022

This branch is ready for another test round. I've added some notes on the OpenCV calibration to the Wiki: https://github.com/RoboCup-SSL/ssl-vision/wiki/camera-calibration#calibration-with-opencv-model

@g3force g3force force-pushed the chessboard-calibration branch from fb4786f to 6d92a12 Compare April 15, 2023 20:35
@g3force g3force force-pushed the chessboard-calibration branch from dd884b4 to 96c1299 Compare May 31, 2024 16:10
g3force and others added 5 commits July 4, 2024 20:56
- Use cv::calibrateCamera instead of cv::solvePnP to allow fine tuning of intrinsic model
- Visualize additional calibration points
- Use double-precision wherever possible
- Fix clang-tidy issues and format
@g3force g3force force-pushed the chessboard-calibration branch from 47f2aa7 to 52d0657 Compare July 4, 2024 18:56
@g3force g3force merged commit 2bf6a0b into master Jul 4, 2024
1 check passed
@g3force g3force deleted the chessboard-calibration branch July 4, 2024 19:04
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.

3 participants