Skip to content

Commit 0db0acf

Browse files
authored
Add support for OpenCV > v4.6.0 (#88)
1 parent 09a7a8c commit 0db0acf

File tree

17 files changed

+384
-116
lines changed

17 files changed

+384
-116
lines changed

.github/workflows/main.yml

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ on:
1717
workflow_dispatch:
1818

1919
env:
20-
MC_CALIB_PROD_DOCKER_IMG: bailool/mc-calib-prod:opencv420
21-
MC_CALIB_DEV_DOCKER_IMG: bailool/mc-calib-dev:opencv420
20+
MC_CALIB_PROD_DOCKER_IMG: bailool/mc-calib-prod:opencv4100
21+
MC_CALIB_DEV_DOCKER_IMG: bailool/mc-calib-dev:opencv4100
2222

2323
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
2424
jobs:
@@ -70,6 +70,34 @@ jobs:
7070
run-clang-tidy
7171
7272

73+
test-charuco-boards-generation:
74+
runs-on: ubuntu-latest
75+
needs:
76+
- clang-format-lint
77+
- cppcheck
78+
- clang-tidy
79+
steps:
80+
- name: Checkout
81+
uses: actions/checkout@v2
82+
83+
- name: Run charuco boards generation app
84+
uses: addnab/docker-run-action@v3
85+
with:
86+
image: ${{env.MC_CALIB_PROD_DOCKER_IMG}}
87+
options: -v ${{ github.workspace }}:/home/MC-Calib:rw
88+
run: |
89+
mkdir MC-Calib/build && cd MC-Calib/build
90+
cmake -DCMAKE_BUILD_TYPE=Release ..
91+
make -j4
92+
./apps/create_charuco_boards/generate_charuco ../tests/configs_for_end2end_tests/calib_param_synth_Scenario1.yml
93+
94+
- name: Archive results artifacts
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: charuco_boards
98+
path: ${{ github.workspace }}/build/charuco_boards
99+
100+
73101
unit-tests-with-sanitizers:
74102
if: ${{ false }} # TODO: disable for now until understand how to suppress leaks from external libraries like OpenCV
75103
runs-on: ubuntu-latest
@@ -146,7 +174,7 @@ jobs:
146174
./apps/calibrate/calibrate ../tests/configs_for_end2end_tests/calib_param_synth_Scenario1.yml
147175
148176
149-
unit-tests-in-release-mode:
177+
unit-tests-in-release-mode-opencv4100:
150178
runs-on: ubuntu-latest
151179
needs:
152180
- clang-format-lint
@@ -208,6 +236,67 @@ jobs:
208236
name: results_blender_sequences
209237
path: ${{ github.workspace }}/data/Blender_Images/Results_Blender_Sequences
210238

239+
unit-tests-in-release-mode-opencv455:
240+
runs-on: ubuntu-latest
241+
needs:
242+
- clang-format-lint
243+
- cppcheck
244+
- clang-tidy
245+
steps:
246+
- name: Checkout
247+
uses: actions/checkout@v2
248+
249+
- name: Checkout MC-Calib-data
250+
uses: actions/checkout@v4
251+
with:
252+
repository: BAILOOL/MC-Calib-data
253+
path: ${{ github.workspace }}/data
254+
lfs: 'true'
255+
256+
- name: Unzip MC-Calib-data
257+
run: tar xf ${{ github.workspace }}/data/Blender_Images.tar.gz -C ${{ github.workspace }}/data
258+
259+
- name: Run tests
260+
uses: addnab/docker-run-action@v3
261+
with:
262+
image: bailool/mc-calib-prod:opencv455
263+
options: -v ${{ github.workspace }}:/home/MC-Calib:rw
264+
run: |
265+
mkdir MC-Calib/build && cd MC-Calib/build
266+
cmake -DCMAKE_BUILD_TYPE=Release ..
267+
make -j4
268+
./tests/boost_tests_run
269+
270+
unit-tests-in-release-mode-opencv420:
271+
runs-on: ubuntu-latest
272+
needs:
273+
- clang-format-lint
274+
- cppcheck
275+
- clang-tidy
276+
steps:
277+
- name: Checkout
278+
uses: actions/checkout@v2
279+
280+
- name: Checkout MC-Calib-data
281+
uses: actions/checkout@v4
282+
with:
283+
repository: BAILOOL/MC-Calib-data
284+
path: ${{ github.workspace }}/data
285+
lfs: 'true'
286+
287+
- name: Unzip MC-Calib-data
288+
run: tar xf ${{ github.workspace }}/data/Blender_Images.tar.gz -C ${{ github.workspace }}/data
289+
290+
- name: Run tests
291+
uses: addnab/docker-run-action@v3
292+
with:
293+
image: bailool/mc-calib-prod:opencv420
294+
options: -v ${{ github.workspace }}:/home/MC-Calib:rw
295+
run: |
296+
mkdir MC-Calib/build && cd MC-Calib/build
297+
cmake -DCMAKE_BUILD_TYPE=Release ..
298+
make -j4
299+
./tests/boost_tests_run
211300
212301
code-coverage-testing:
213302
runs-on: ubuntu-latest
@@ -262,7 +351,7 @@ jobs:
262351
python-utils-linters:
263352
runs-on: ubuntu-latest
264353
needs:
265-
- unit-tests-in-release-mode
354+
- unit-tests-in-release-mode-opencv4100
266355
steps:
267356
- name: Checkout
268357
uses: actions/checkout@v2
@@ -282,7 +371,7 @@ jobs:
282371
runs-on: ubuntu-latest
283372
needs:
284373
- python-utils-linters
285-
- unit-tests-in-release-mode
374+
- unit-tests-in-release-mode-opencv4100
286375
steps:
287376
- name: Checkout
288377
uses: actions/checkout@v2

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ if(ENABLE_COVERAGE)
3434
# add coverage target
3535
add_custom_target(coverage
3636
# gather data
37-
COMMAND ${LCOV} --directory . --capture --output-file coverage.info --exclude '/usr/*'
37+
COMMAND ${LCOV} --directory . --capture --output-file coverage.info --exclude '/usr/*'
38+
--ignore-errors mismatch,negative
3839
# generate report
3940
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
4041
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
@@ -80,7 +81,7 @@ endif (DOXYGEN_FOUND)
8081

8182

8283
##########################################################################
83-
add_subdirectory(apps/create_charuco_boards)
8484
add_subdirectory(McCalib)
85+
add_subdirectory(apps/create_charuco_boards)
8586
add_subdirectory(apps/calibrate)
8687
add_subdirectory(tests)

Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:20.04 as prod
1+
FROM ubuntu:24.04 as prod
22

33
ENV DEBIAN_FRONTEND noninteractive
44
RUN apt update && apt install -y --no-install-recommends apt-utils && \
@@ -15,14 +15,14 @@ WORKDIR /home
1515
#------------------------------ #
1616
# INSTALL OPENCV 4 #
1717
#------------------------------ #
18-
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.2.0.zip && \
19-
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.2.0.zip && \
18+
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.10.0.zip && \
19+
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.10.0.zip && \
2020
unzip opencv.zip && unzip opencv_contrib.zip && \
2121
mkdir -p build && cd build && \
22-
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.2.0/modules ../opencv-4.2.0 && \
22+
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.10.0/modules ../opencv-4.10.0 && \
2323
cmake --build . --target install -- -j4 && \
2424
cd /home && rm opencv.zip && rm opencv_contrib.zip && \
25-
rm -rf opencv-4.2.0 && rm -rf opencv_contrib-4.2.0 && rm -rf build && \
25+
rm -rf opencv-4.10.0 && rm -rf opencv_contrib-4.10.0 && rm -rf build && \
2626
rm -rf /var/lib/apt/lists/*
2727

2828
#------------------------------ #
@@ -49,8 +49,8 @@ RUN git clone --branch 2.2.0 --single-branch https://github.com/ceres-solver/cer
4949

5050
# Install python requirements for python_utils scripts
5151
RUN --mount=type=bind,source=python_utils/requirements_prod.txt,target=/tmp/requirements.txt \
52-
apt update && apt install -y libgl1 && \
53-
python -m pip install --requirement /tmp/requirements.txt && \
52+
apt update && apt install -y libgl1 libglib2.0-0 && \
53+
python -m pip install --requirement /tmp/requirements.txt --break-system-packages && \
5454
rm -rf /var/lib/apt/lists/*
5555

5656
FROM prod as dev
@@ -75,5 +75,5 @@ RUN apt update && apt install -y cppcheck clang-tidy valgrind lcov && \
7575

7676
# Install python requirements for python_utils scripts
7777
RUN --mount=type=bind,source=python_utils/requirements_dev.txt,target=/tmp/requirements.txt \
78-
python -m pip install --requirement /tmp/requirements.txt && \
78+
python -m pip install --requirement /tmp/requirements.txt --break-system-packages && \
7979
rm -rf /var/lib/apt/lists/*

McCalib/include/Board.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Board final {
4444
std::map<int, std::weak_ptr<Frame>> frames_;
4545

4646
// Charuco board
47-
cv::Ptr<cv::aruco::CharucoBoard> charuco_board_; // vector of charuco boards
47+
cv::Ptr<cv::aruco::CharucoBoard> charuco_board_;
4848

4949
// Functions
5050
Board() = delete;

McCalib/include/McCalib.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,22 @@ class Calibration final {
3636
public:
3737
// Parameters
3838
unsigned int nb_camera_, nb_board_;
39+
40+
#if (defined(CV_VERSION_MAJOR) && CV_VERSION_MAJOR <= 4 && \
41+
defined(CV_VERSION_MINOR) && CV_VERSION_MINOR < 7)
3942
cv::Ptr<cv::aruco::Dictionary> dict_ = cv::aruco::getPredefinedDictionary(
4043
cv::aruco::DICT_6X6_1000); // load the dictionary that correspond to the
4144
// charuco board
4245
cv::Ptr<cv::aruco::DetectorParameters> charuco_params_ =
4346
cv::aruco::DetectorParameters::create(); // parameters for detection
47+
#else
48+
cv::aruco::Dictionary dict_ = cv::aruco::getPredefinedDictionary(
49+
cv::aruco::DICT_6X6_1000); // load the dictionary that correspond to the
50+
// charuco board
51+
cv::aruco::DetectorParameters charuco_params_ =
52+
cv::aruco::DetectorParameters(); // parameters for detection
53+
#endif
54+
4455
float min_perc_pts_;
4556

4657
// images path

McCalib/include/point_refinement.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
#include "opencv2/core/core.hpp"
1+
#include <cmath>
22
#include <iostream>
3-
#include <opencv2/opencv.hpp>
43
#include <stdio.h>
54

5+
#include "opencv2/core/core.hpp"
6+
#include <opencv2/opencv.hpp>
7+
68
namespace McCalib {
79

810
/****** ******/
911

10-
float step_threshold = 0.001;
12+
double step_threshold = 0.001;
1113

1214
/**
1315
* @struct SaddlePoint
@@ -36,7 +38,7 @@ void initSaddlePointRefinement(const int half_kernel_size,
3638
int cnt = 0;
3739
for (int y = -half_kernel_size; y <= half_kernel_size; y++)
3840
for (int x = -half_kernel_size; x <= half_kernel_size; x++) {
39-
*w = maxVal - sqrt(x * x + y * y);
41+
*w = maxVal - std::sqrt(x * x + y * y);
4042
if (*w > 0)
4143
cnt++;
4244
else
@@ -138,22 +140,23 @@ void saddleSubpixelRefinement(const cv::Mat &smooth_input,
138140
pt.det; // k3 * k1 - 2 * k5 * k2
139141
pt.x += dx;
140142
pt.y += dy;
141-
dx = fabs(dx);
142-
dy = fabs(dy);
143+
dx = std::fabs(dx);
144+
dy = std::fabs(dy);
143145
// iterations++;
144146

145147
if (it == max_iterations ||
146148
(step_threshold > dx && step_threshold > dy)) {
147149
// converged
148150
double k4mk5 = r[1] - r[0];
149-
pt.s = sqrt(r[2] * r[2] + k4mk5 * k4mk5);
150-
pt.a1 = atan2(-r[2], k4mk5) / 2.0;
151-
pt.a2 = acos((r[1] + r[0]) / pt.s) / 2.0;
151+
pt.s = std::sqrt(r[2] * r[2] + k4mk5 * k4mk5);
152+
pt.a1 = std::atan2(-r[2], k4mk5) / 2.0;
153+
pt.a2 = std::acos((r[1] + r[0]) / pt.s) / 2.0;
152154
break;
153155
} else {
154156
// check for divergence
155-
if (pt.det > 0 || fabs(pt.x - initial[idx].x) > window_half_size ||
156-
fabs(pt.y - initial[idx].y) > window_half_size) {
157+
if (pt.det > 0 ||
158+
std::fabs(pt.x - initial[idx].x) > window_half_size ||
159+
std::fabs(pt.y - initial[idx].y) > window_half_size) {
157160
pt.x = pt.y = std::numeric_limits<double>::infinity();
158161
// diverged++;
159162
break;

McCalib/include/utilities.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11

22
#include <filesystem>
3+
#include <map>
34
#include <string>
45
#include <vector>
56

7+
#include <opencv2/aruco/charuco.hpp>
8+
#include <opencv2/opencv.hpp>
9+
610
namespace McCalib {
711

812
std::filesystem::path convertStrToPath(const std::string &item_name);
913
std::vector<std::filesystem::path>
1014
convertVecStrToVecPath(const std::vector<std::string> &input);
1115

16+
#if (defined(CV_VERSION_MAJOR) && CV_VERSION_MAJOR <= 4 && \
17+
defined(CV_VERSION_MINOR) && CV_VERSION_MINOR < 7)
18+
19+
std::map<int, cv::Ptr<cv::aruco::CharucoBoard>>
20+
createCharucoBoards(const unsigned int num_board,
21+
const std::vector<int> &number_x_square_per_board,
22+
const std::vector<int> &number_y_square_per_board,
23+
const float length_square, const float length_marker,
24+
const cv::Ptr<cv::aruco::Dictionary> dict);
25+
#else
26+
std::map<int, cv::Ptr<cv::aruco::CharucoBoard>>
27+
createCharucoBoards(const unsigned int num_board,
28+
const std::vector<int> &number_x_square_per_board,
29+
const std::vector<int> &number_y_square_per_board,
30+
const float length_square, const float length_marker,
31+
const cv::aruco::Dictionary &dict);
32+
#endif
33+
34+
std::vector<cv::Mat>
35+
createCharucoBoardsImages(const unsigned int num_board,
36+
const std::vector<int> &number_x_square_per_board,
37+
const std::vector<int> &number_y_square_per_board,
38+
const float length_square, const float length_marker,
39+
const std::vector<int> &resolution_x_per_board,
40+
const std::vector<int> &resolution_y_per_board);
41+
1242
} // namespace McCalib

McCalib/src/Camera.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
#include "opencv2/core/core.hpp"
1+
#include <algorithm>
22
#include <iostream>
3+
#include <random>
4+
#include <stdio.h>
5+
6+
#include "opencv2/core/core.hpp"
37
#include <opencv2/aruco/charuco.hpp>
48
#include <opencv2/opencv.hpp>
5-
#include <stdio.h>
69

710
#include "Camera.hpp"
811
#include "OptimizationCeres.h"
@@ -169,7 +172,9 @@ void Camera::initializeCalibration() {
169172
std::srand(unsigned(std::time(0)));
170173
std::vector<int> shuffled_board_ind(indbv.size());
171174
std::iota(shuffled_board_ind.begin(), shuffled_board_ind.end(), 0);
172-
random_shuffle(shuffled_board_ind.begin(), shuffled_board_ind.end());
175+
std::random_device rd;
176+
std::mt19937 g(rd());
177+
std::shuffle(shuffled_board_ind.begin(), shuffled_board_ind.end(), g);
173178

174179
// nb of boards used for the initial estimation of intrinsic parameters
175180
//(at least 50 boards for perspective)

0 commit comments

Comments
 (0)