Skip to content
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

Upgrade to OpenCV==4.10.0 #80

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,5 @@ endif (DOXYGEN_FOUND)
##########################################################################
add_subdirectory(apps/create_charuco_boards)
add_subdirectory(McCalib)
find_library(McCalib REQUIRED)
add_subdirectory(apps/calibrate)
add_subdirectory(tests)
37 changes: 22 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM ubuntu:20.04 as prod
FROM ubuntu:24.04 as prod

ENV DEBIAN_FRONTEND noninteractive
RUN apt update && apt install -y --no-install-recommends apt-utils && \
apt upgrade -y && apt autoremove -y && \
apt install -y build-essential cmake && \
apt install -y build-essential cmake wget unzip git && \
apt install -y python-is-python3 python3-pip && \
rm -rf /var/lib/apt/lists/*

Expand All @@ -15,7 +15,14 @@ WORKDIR /home
#------------------------------ #
# INSTALL OPENCV 4 #
#------------------------------ #
RUN apt update && apt install -y libopencv-dev && \
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.10.0.zip && \
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.10.0.zip && \
unzip opencv.zip && unzip opencv_contrib.zip && \
mkdir -p build && cd build && \
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.10.0/modules ../opencv-4.10.0 && \
cmake --build . --target install && \
cd /home && rm opencv.zip && rm opencv_contrib.zip && \
rm -rf opencv-4.10.0 && rm -rf opencv_contrib-4.10.0 && rm -rf build && \
rm -rf /var/lib/apt/lists/*

#------------------------------ #
Expand All @@ -27,36 +34,36 @@ RUN apt update && apt install -y libboost-all-dev && \
#------------------------------ #
# Install Ceres #
#------------------------------ #
RUN apt update && \
apt install -y libgoogle-glog-dev libgflags-dev libatlas-base-dev libeigen3-dev libsuitesparse-dev && \
RUN apt update && apt install -y libgoogle-glog-dev libgflags-dev libatlas-base-dev libeigen3-dev libsuitesparse-dev && \
rm -rf /var/lib/apt/lists/*
RUN apt update && apt install -y git && \
/bin/bash -c "git clone https://ceres-solver.googlesource.com/ceres-solver && \
RUN git clone --branch 20240722.0 --single-branch https://github.com/abseil/abseil-cpp.git && \
cd abseil-cpp && mkdir build && cd build && \
cmake .. && cmake --build . --target install && \
cd /home && rm -rf abseil-cpp && \
rm -rf /var/lib/apt/lists/*
RUN git clone --branch 2.2.0 --single-branch https://github.com/ceres-solver/ceres-solver.git && \
cd ceres-solver && mkdir build && cd build && cmake .. && \
make && make install && \
cd /home && rm -rf ceres-solver" && \
cd /home && rm -rf ceres-solver && \
rm -rf /var/lib/apt/lists/*

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

FROM prod as dev

RUN apt update && apt install -y python3-opencv && \
rm -rf /var/lib/apt/lists/*

#------------------------------ #
# Doxygen #
#------------------------------ #
RUN apt update && apt install -y flex bison && \
/bin/bash -c "git clone https://github.com/doxygen/doxygen.git && \
git clone https://github.com/doxygen/doxygen.git && \
cd doxygen && mkdir build && cd build &&\
cmake -G 'Unix Makefiles' .. && \
make && \
make install && \
cd /home && rm -rf doxygen" && \
cd /home && rm -rf doxygen && \
rm -rf /var/lib/apt/lists/*

#------------------------------ #
Expand All @@ -67,5 +74,5 @@ RUN apt update && apt install -y cppcheck clang-tidy valgrind lcov && \

# Install python requirements for python_utils scripts
RUN --mount=type=bind,source=python_utils/requirements_dev.txt,target=/tmp/requirements.txt \
pip install --requirement /tmp/requirements.txt && \
python -m pip install --requirement /tmp/requirements.txt --break-system-packages && \
rm -rf /var/lib/apt/lists/*
6 changes: 5 additions & 1 deletion McCalib/include/Board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <opencv2/opencv.hpp>
#include <stdio.h>

namespace McCalib {

class BoardObs;
class Frame;

Expand Down Expand Up @@ -40,7 +42,7 @@ class Board final {
std::map<int, std::weak_ptr<Frame>> frames_;

// Charuco board
cv::Ptr<cv::aruco::CharucoBoard> charuco_board_; // vector of charuco boards
cv::Ptr<cv::aruco::CharucoBoard> charuco_board_;

// Functions
Board() = delete;
Expand All @@ -49,3 +51,5 @@ class Board final {
void insertNewBoard(std::shared_ptr<BoardObs> new_board);
void insertNewFrame(std::shared_ptr<Frame> new_frame);
};

} //namespace McCalib
4 changes: 4 additions & 0 deletions McCalib/include/BoardObs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <opencv2/opencv.hpp>
#include <stdio.h>

namespace McCalib {

class Camera;
class Board;

Expand Down Expand Up @@ -60,3 +62,5 @@ class BoardObs final {
cv::Mat getRotVec() const;
cv::Mat getTransVec() const;
};

} //namespace McCalib
4 changes: 4 additions & 0 deletions McCalib/include/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "Frame.hpp"
#include "Object3DObs.hpp"

namespace McCalib {

/**
* @class Camera
*
Expand Down Expand Up @@ -64,3 +66,5 @@ class Camera final {
void setIntrinsics(const cv::Mat K, const cv::Mat distortion_vector);
bool checkBorderToleranceFisheye(std::shared_ptr<BoardObs> board_obs);
};

} // namespace McCalib
4 changes: 4 additions & 0 deletions McCalib/include/CameraGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "Frame.hpp"
#include "Object3DObs.hpp"

namespace McCalib {

/**
* @class CameraGroup
*
Expand Down Expand Up @@ -63,3 +65,5 @@ class CameraGroup final {
void refineCameraGroupAndObjects(const int nb_iterations);
void refineCameraGroupAndObjectsAndIntrinsics(const int nb_iterations);
};

} // namespace McCalib
4 changes: 4 additions & 0 deletions McCalib/include/CameraGroupObs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <opencv2/opencv.hpp>
#include <stdio.h>

namespace McCalib {

class CameraGroup;

/**
Expand Down Expand Up @@ -50,3 +52,5 @@ class CameraGroupObs final {
cv::Mat getObjectTransVec(int object_id);
void updateObjObsPose();
};

} // namespace McCalib
4 changes: 4 additions & 0 deletions McCalib/include/CameraObs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <opencv2/opencv.hpp>
#include <stdio.h>

namespace McCalib {

class Camera;

/**
Expand Down Expand Up @@ -37,3 +39,5 @@ class CameraObs final {
void insertNewBoard(std::shared_ptr<BoardObs> new_board);
void insertNewObject(std::shared_ptr<Object3DObs> new_object);
};

} // namespace McCalib
4 changes: 4 additions & 0 deletions McCalib/include/Frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "CameraObs.hpp"
#include "Object3DObs.hpp"

namespace McCalib {

/**
* @class Frame
*
Expand Down Expand Up @@ -57,3 +59,5 @@ class Frame final {
insertNewCameraGroupObs(std::shared_ptr<CameraGroupObs> new_cam_group_obs,
const int camera_group_idx);
};

} // namespace McCalib
3 changes: 2 additions & 1 deletion McCalib/include/Graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/graph_traits.hpp>


/**
* @class Graph
*
Expand Down Expand Up @@ -45,4 +46,4 @@ class Graph final {

std::vector<int> getPath(const std::vector<Vertex> &p_map,
const Vertex &source, const Vertex &destination);
};
};
5 changes: 2 additions & 3 deletions McCalib/include/McCalib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ class Calibration final {
public:
// Parameters
unsigned int nb_camera_, nb_board_;
cv::Ptr<cv::aruco::Dictionary> dict_ = cv::aruco::getPredefinedDictionary(
cv::aruco::Dictionary dict_ = cv::aruco::getPredefinedDictionary(
cv::aruco::DICT_6X6_1000); // load the dictionary that correspond to the
// charuco board
cv::Ptr<cv::aruco::DetectorParameters> charuco_params_ =
cv::aruco::DetectorParameters::create(); // parameters for detection
cv::aruco::DetectorParameters charuco_params_ = cv::aruco::DetectorParameters(); // parameters for detection
float min_perc_pts_;

// images path
Expand Down
4 changes: 4 additions & 0 deletions McCalib/include/Object3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <opencv2/opencv.hpp>
#include <stdio.h>

namespace McCalib {

class Board;
class BoardObs;
class Object3DObs;
Expand Down Expand Up @@ -68,3 +70,5 @@ class Object3D final {
void refineObject(const int nb_iterations);
void updateObjectPts();
};

} // namespace McCalib
4 changes: 4 additions & 0 deletions McCalib/include/Object3DObs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <opencv2/opencv.hpp>
#include <stdio.h>

namespace McCalib {

class Camera;
class Board;
class BoardObs;
Expand Down Expand Up @@ -82,3 +84,5 @@ class Object3DObs final {
cv::Mat getRotInGroupVec() const;
cv::Mat getTransInGroupVec() const;
};

} // namespace McCalib
102 changes: 1 addition & 101 deletions McCalib/include/OptimizationCeres.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,104 +662,4 @@ struct ReprojectionError_CameraGroupAndObjectRefAndIntrinsics {
bool refine_camera;
bool refine_board;
int distortion_type;
};

/*
template <typename T>
Eigen::Matrix<T, 3, 3>
AngleAxisToRotationMatrix(const Eigen::Matrix<T, 3, 1>& rvec) {
T angle = rvec.norm();
if (angle == T(0)) {
return Eigen::Matrix<T, 3, 3>::Identity();
}

Eigen::Matrix<T, 3, 1> axis;
axis = rvec.normalized();

Eigen::Matrix<T, 3, 3> rmat;
rmat = Eigen::AngleAxis<T>(angle, axis);

return rmat;
}



// Refine handeye calibration
struct TransformationError {
TransformationError(double r1_x, double r1_y, double r1_z, double t1_x, double
t1_y, double t1_z, double r2_x, double r2_y, double r2_z, double t2_x, double
t2_y, double t2_z) : r1_x(r1_x), r1_y(r1_y), r1_z(r1_z), t1_x(t1_x), t1_y(t1_y),
t1_z(t1_z), r2_x(r2_x), r2_y(r2_y), r2_z(r2_z), t2_x(t2_x), t2_y(t2_y),
t2_z(t2_z) {}

template <typename T>
bool operator()(const T *const transform,
T *residuals) const {

// 1. convert to rotation matrix for relative 1 and 2
Eigen::Matrix<double, 3, 1> r1, r2;
r1(0,0) = r1_x; r1(1,0) = r1_y; r1(2,0) = r1_z;
r2(0,0) = r2_x; r2(1,0) = r2_y; r2(2,0) = r2_z;
Eigen::Matrix<double, 3, 3> R1 = AngleAxisToRotationMatrix(r1);
Eigen::Matrix<double, 3, 3> R2 = AngleAxisToRotationMatrix(r2);
Eigen::Matrix<double, 3,1> t1, t2;
t1(0,0) = t1_x; t1(1,0) = t1_y; t1(2,0) = t1_z;
t2(0,0) = t2_x; t2(1,0) = t2_y; t2(2,0) = t2_z;

Eigen::Matrix4d Trans1; // Your Transformation Matrix
Trans1.setIdentity(); // Set to Identity to make bottom row of Matrix
0,0,0,1 Trans1.block<3,3>(0,0) = R1; Trans1.block<3,1>(0,3) = t1;
Eigen::Matrix4d Trans2; // Your Transformation Matrix
Trans2.setIdentity(); // Set to Identity to make bottom row of Matrix
0,0,0,1 Trans2.block<3,3>(0,0) = R2; Trans2.block<3,1>(0,3) = t2;

//2. convert the transform
Eigen::Matrix<T, 3, 1> rt;
Eigen::Matrix<T, 3,1> tt;
rt(0,0) = (transform[0]); rt(1,0) = (transform[1]); rt(2,0) =
(transform[2]); Eigen::Matrix<T, 3, 3> Rt = AngleAxisToRotationMatrix(rt);
tt(0,0) = (transform[3]); tt(1,0) = (transform[4]); tt(2,0) =
(transform[5]); Eigen::Matrix<T, 4,4> Trans; // Your Transformation Matrix
Trans(0,0) = Rt(0,0); Trans(0,1) = Rt(0,1); Trans(0,2) = Rt(0,2); Trans(0,3)
= tt(0,0); Trans(1,0) = Rt(1,0); Trans(1,1) = Rt(1,1); Trans(1,2) = Rt(1,2);
Trans(1,3) = tt(1,0); Trans(2,0) = Rt(2,0); Trans(2,1) = Rt(2,1); Trans(2,2) =
Rt(2,2); Trans(2,3) = tt(2,0);

Eigen::Matrix4d Error = (Trans - Trans2*Trans*Trans1.inverse());
//r1.row(0) << r1_x, r1_y, r1_z;
//Map<Vector3f> r1; //(r11);


//AngleAxisToRotationMatrix(axis_angle, matrix);
// 2. convert the "transform" ro rotation matrix

// 2. Compute errors matrix
residuals[0] = T(Error(0,0));
residuals[1] = T(Error(1,0));
residuals[2] = T(Error(2,0));
residuals[3] = T(Error(3,0));
residuals[4] = T(Error(0,1));
residuals[5] = T(Error(1,1));
residuals[6] = T(Error(2,1));
residuals[7] = T(Error(3,1));
residuals[8] = T(Error(0,2));
residuals[9] = T(Error(1,2));
residuals[10] = T(Error(2,2));
residuals[11] = T(Error(3,2));

return true;
}

static ceres::CostFunction *Create(const double r1_x, const double r1_y, const
double r1_z, const double t1_x, const double t1_y, const double t1_z, const
double r2_x, const double r2_y, const double r2_z, const double t2_x, const
double t2_y, const double t2_z) { return (new
ceres::AutoDiffCostFunction<TransformationError, 12, 6>( new
TransformationError(r1_x, r1_y, r1_z, t1_x, t1_y, t1_z, r2_x, r2_y, r2_z, t2_x,
t2_y, t2_z)));
}
double r1_x, r1_y, r1_z;
double t1_x, t1_y, t1_z;
double r2_x, r2_y, r2_z;
double t2_x, t2_y, t2_z;
};*/
};
6 changes: 5 additions & 1 deletion McCalib/include/geometrytools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <random>
#include <stdio.h>

namespace McCalib {

cv::Mat RT2Proj(cv::Mat R, cv::Mat T);
cv::Mat RVecT2Proj(cv::Mat RVec, cv::Mat T);
cv::Mat RVecT2ProjInt(cv::Mat RVec, cv::Mat T, cv::Mat K);
Expand Down Expand Up @@ -56,4 +58,6 @@ cv::Mat convertRotationMatrixToQuaternion(cv::Mat R);
cv::Mat convertQuaternionToRotationMatrix(const std::array<double, 4> &q);
cv::Mat getAverageRotation(std::vector<double> &r1, std::vector<double> &r2,
std::vector<double> &r3,
const bool use_quaternion_averaging = true);
const bool use_quaternion_averaging = true);

} //namespace McCalib
Loading
Loading