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

feature/improving-class-constructors #3

Merged
merged 4 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions src/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
#include "Frame.hpp"
#include "logger.h"

Board::Board() {}

/**
* @brief Initialize parameters of the board
* @brief Initialize Board object
*
* @param config_path path to the configuration file
* @param board_idx index of the board
*/
void Board::initParams(const std::string config_path, const int board_idx) {
Board::Board(const std::string config_path, const int board_idx) {
std::vector<int> number_x_square_per_board, number_y_square_per_board;
std::vector<double> square_size_per_board;
std::vector<int> boards_index;
Expand Down
6 changes: 3 additions & 3 deletions src/Board.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Frame;
* - frames where these 3D boards are observed
*/

class Board {
class Board final {
public:
// Parameters
int nb_x_square_, nb_y_square_, res_x_, res_y_;
Expand All @@ -43,9 +43,9 @@ class Board {
cv::Ptr<cv::aruco::CharucoBoard> charuco_board_; // vector of charuco boards

// Functions
Board();
Board() = delete;
~Board(){};
void initParams(const std::string config, const int board_idx);
Board(const std::string config, const int board_idx);
void insertNewBoard(std::shared_ptr<BoardObs> new_board);
void insertNewFrame(std::shared_ptr<Frame> new_frame);
};
24 changes: 8 additions & 16 deletions src/BoardObs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#include "geometrytools.hpp"
#include "logger.h"

BoardObs::BoardObs() {}

/**
* @brief Initialize the board observation
* @brief Initialize the board observation object
*
* @param camera_id camera index of the camera observing the board
* @param frame_id frame in which the board is visible
Expand All @@ -22,19 +20,13 @@ BoardObs::BoardObs() {}
* @param cam camera observing the board
* @param board_3d 3D board corresponding to the observation
*/
void BoardObs::init(const int camera_id, const int frame_id, const int board_id,
const std::vector<cv::Point2f> pts_2d,
const std::vector<int> charuco_id,
std::shared_ptr<Camera> cam,
std::shared_ptr<Board> board_3d) {
frame_id_ = frame_id;
camera_id_ = camera_id;
board_id_ = board_id;
pts_2d_ = pts_2d;
charuco_id_ = charuco_id;
cam_ = cam;
board_3d_ = board_3d;
}
BoardObs::BoardObs(const int camera_id, const int frame_id, const int board_id,
const std::vector<cv::Point2f> pts_2d,
const std::vector<int> charuco_id,
std::shared_ptr<Camera> cam, std::shared_ptr<Board> board_3d)
: frame_id_(frame_id), camera_id_(camera_id), board_id_(board_id),
pts_2d_(pts_2d), charuco_id_(charuco_id), cam_(cam),
board_3d_(board_3d){};

/**
* @brief Get pose vector of the observed board
Expand Down
12 changes: 6 additions & 6 deletions src/BoardObs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Board;
* camera observing the board.
*
*/
class BoardObs {
class BoardObs final {
public:
// Indexing
int frame_id_;
Expand All @@ -45,12 +45,12 @@ class BoardObs {
bool valid_ = true;

// Functions
BoardObs();
BoardObs() = delete;
~BoardObs() { delete[] pose_; };
void init(const int camera_id, const int frame_id, const int board_id,
const std::vector<cv::Point2f> pts_2d,
const std::vector<int> charuco_id, std::shared_ptr<Camera> cam,
std::shared_ptr<Board> board_3d);
BoardObs(const int camera_id, const int frame_id, const int board_id,
const std::vector<cv::Point2f> pts_2d,
const std::vector<int> charuco_id, std::shared_ptr<Camera> cam,
std::shared_ptr<Board> board_3d);
void getPoseVec(cv::Mat &R, cv::Mat &T) const;
cv::Mat getPoseMat() const;
void setPoseMat(const cv::Mat Pose);
Expand Down
52 changes: 20 additions & 32 deletions src/Calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
#include "logger.h"
#include "point_refinement.h"

Calibration::Calibration() {}

/**
* @brief Initialize the number of cameras and the 3D Boards
*
* @param config_path path to the configuration file
*/
void Calibration::initialization(const std::string config_path) {
Calibration::Calibration(const std::string config_path) {
cv::FileStorage fs; // cv::FileStorage to read calibration params from file
int distortion_model;
std::vector<int> distortion_per_camera;
Expand Down Expand Up @@ -87,9 +85,8 @@ void Calibration::initialization(const std::string config_path) {

// Initialize Cameras
for (int i = 0; i < nb_camera_; i++) {
std::shared_ptr<Camera> new_cam = std::make_shared<Camera>();
new_cam->cam_idx_ = i;
new_cam->distortion_model_ = distortion_per_camera[i];
std::shared_ptr<Camera> new_cam =
std::make_shared<Camera>(i, distortion_per_camera[i]);
cams_[i] = new_cam;
}

Expand Down Expand Up @@ -117,9 +114,8 @@ void Calibration::initialization(const std::string config_path) {
// Initialize the 3D boards
for (int i = 0; i < nb_board_; i++) {
// Initialize board
std::shared_ptr<Board> new_board = std::make_shared<Board>();
std::shared_ptr<Board> new_board = std::make_shared<Board>(config_path, i);
boards_3d_[i] = new_board;
boards_3d_[i]->initParams(config_path, i);
LOG_DEBUG << "Here1";
// Prepare the 3D pts of the boards
for (int y = 0; y < boards_3d_[i]->nb_y_square_ - 1; y++) {
Expand Down Expand Up @@ -435,9 +431,9 @@ void Calibration::insertNewBoard(const int cam_idx, const int frame_idx,
const std::vector<cv::Point2f> pts_2d,
const std::vector<int> charuco_idx,
const std::string frame_path) {
std::shared_ptr<BoardObs> new_board = std::make_shared<BoardObs>();
new_board->init(cam_idx, frame_idx, board_idx, pts_2d, charuco_idx,
cams_[cam_idx], boards_3d_[board_idx]);
std::shared_ptr<BoardObs> new_board = std::make_shared<BoardObs>(
cam_idx, frame_idx, board_idx, pts_2d, charuco_idx, cams_[cam_idx],
boards_3d_[board_idx]);

// Add new board in the board list
board_observations_[board_observations_.size()] = new_board;
Expand All @@ -457,9 +453,7 @@ void Calibration::insertNewBoard(const int cam_idx, const int frame_idx,
frames_[frame_idx]->frame_path_[cam_idx] = frame_path;
} else {
std::shared_ptr<Frame> newFrame =
std::make_shared<Frame>(); // declare new frame in heap
newFrame->frame_idx_ = frame_idx;
newFrame->frame_path_[cam_idx] = frame_path;
std::make_shared<Frame>(frame_idx, cam_idx, frame_path);
frames_[frame_idx] = newFrame; // Initialize the Frame if key does not exist
frames_[frame_idx]->insertNewBoard(new_board);
cams_[cam_idx]->insertNewFrame(newFrame);
Expand All @@ -475,10 +469,9 @@ void Calibration::insertNewBoard(const int cam_idx, const int frame_idx,
// insert in list
cams_obs_[cam_frame_idx]->insertNewBoard(new_board);
} else {
std::shared_ptr<CameraObs> new_cam_obs = std::make_shared<CameraObs>();
;
std::shared_ptr<CameraObs> new_cam_obs =
std::make_shared<CameraObs>(new_board);
cams_obs_[cam_frame_idx] = new_cam_obs;
cams_obs_[cam_frame_idx]->insertNewBoard(new_board); // add the observation
frames_[frame_idx]->insertNewCamObs(new_cam_obs);
}
}
Expand Down Expand Up @@ -731,9 +724,8 @@ void Calibration::init3DObjects() {

// Declare a new 3D object
std::shared_ptr<Object3D> newObject3D =
std::make_shared<Object3D>(); // declare new object 3D in heap
newObject3D->initializeObject3D(connect_comp[i].size(), ref_board_id, i,
boards_3d_[ref_board_id]->color_);
std::make_shared<Object3D>(connect_comp[i].size(), ref_board_id, i,
boards_3d_[ref_board_id]->color_);
int pts_count = 0;

// Compute the shortest path between the reference and the other board
Expand Down Expand Up @@ -804,8 +796,8 @@ void Calibration::init3DObjectObs(const int object_idx) {

// Declare the 3D object observed in this camera observation
// Keep in mind that a single object can be observed in one image
std::shared_ptr<Object3DObs> object_obs = std::make_shared<Object3DObs>();
object_obs->initializeObject(object_3d_[object_idx], object_idx);
std::shared_ptr<Object3DObs> object_obs =
std::make_shared<Object3DObs>(object_3d_[object_idx], object_idx);

// Check the boards observing this camera
std::map<int, std::weak_ptr<BoardObs>> current_board_obs =
Expand Down Expand Up @@ -1048,8 +1040,7 @@ void Calibration::initCameraGroup() {

// Declare a new camera group
std::shared_ptr<CameraGroup> new_camera_group =
std::make_shared<CameraGroup>();
new_camera_group->initializeCameraGroup(id_ref_cam, i);
std::make_shared<CameraGroup>(id_ref_cam, i);

// Compute the shortest path between the reference and the other cams
for (int j = 0; j < connect_comp[i].size(); j++) {
Expand Down Expand Up @@ -1096,8 +1087,8 @@ void Calibration::initCameraGroupObs(const int camera_group_idx) {
it_frame != frames_.end(); ++it_frame) {
int current_frame_id = it_frame->second->frame_idx_;
std::shared_ptr<CameraGroupObs> new_cam_group_obs =
std::make_shared<CameraGroupObs>(); // declare a new observation
new_cam_group_obs->insertCameraGroup(cam_group_[camera_group_idx]);
std::make_shared<CameraGroupObs>(
cam_group_[camera_group_idx]); // declare a new observation

std::map<int, std::weak_ptr<Object3DObs>> current_object_obs =
it_frame->second->object_observations_;
Expand Down Expand Up @@ -1563,8 +1554,7 @@ void Calibration::mergeCameraGroup() {

// initialize the camera group
std::shared_ptr<CameraGroup> new_camera_group =
std::make_shared<CameraGroup>();
new_camera_group->initializeCameraGroup(id_ref_cam, i);
std::make_shared<CameraGroup>(id_ref_cam, i);
// Iterate through the camera groups and add all the cameras individually in
// the new group
for (std::map<int, std::shared_ptr<CameraGroup>>::iterator it_group =
Expand Down Expand Up @@ -1829,10 +1819,8 @@ void Calibration::mergeObjects() {
object_pose_to_ref[current_object_id] = transform;
}
// initialize the object
std::shared_ptr<Object3D> newObject3D =
std::make_shared<Object3D>(); // declare new object 3D in heap
newObject3D->initializeObject3D(nb_board_in_obj, ref_board_id, i,
boards_3d_[ref_board_id]->color_);
std::shared_ptr<Object3D> newObject3D = std::make_shared<Object3D>(
nb_board_in_obj, ref_board_id, i, boards_3d_[ref_board_id]->color_);
int pts_count = 0;
// Iterate through the objects and add all of them individually in the new
// object
Expand Down
6 changes: 3 additions & 3 deletions src/Calibration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* Centralization of all the data to perform the calibration.
*/
class Calibration {
class Calibration final {
public:
// Parameters
int nb_camera_, nb_board_;
Expand Down Expand Up @@ -133,9 +133,9 @@ class Calibration {
void merge3DObjects();

// Functions
Calibration();
Calibration() = delete;
~Calibration(){};
void initialization(
Calibration(
const std::string config_path); // initialize the charuco pattern, nb
// of cameras, nb of boards etc.
void boardExtraction();
Expand Down
3 changes: 2 additions & 1 deletion src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "OptimizationCeres.h"
#include "logger.h"

Camera::Camera() {}
Camera::Camera(const int cam_idx, const int distortion_model)
: cam_idx_(cam_idx), distortion_model_(distortion_model){};

/**
* @brief Get camera matrix (K)
Expand Down
5 changes: 3 additions & 2 deletions src/Camera.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* - boards observation
* - object observation
*/
class Camera {
class Camera final {
public:
// datastructure for this camera
std::map<int, std::weak_ptr<BoardObs>>
Expand All @@ -44,7 +44,8 @@ class Camera {
int cam_idx_;

// Functions
Camera();
Camera() = delete;
Camera(const int cam_idx, const int distortion_model);
~Camera() { delete[] intrinsics_; };
void insertNewBoard(std::shared_ptr<BoardObs> newBoard);
void insertNewFrame(std::shared_ptr<Frame> newFrame);
Expand Down
11 changes: 3 additions & 8 deletions src/CameraGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@
#include "CameraGroup.hpp"
#include "logger.h"

CameraGroup::CameraGroup() {}

/**
* @brief Initialize the camera group
* @brief Initialize the camera group object
*
* Set the index of the reference camera and the index of the camera group.
*
* @param id_ref_cam index of the reference camera
* @param cam_group_idx index of the camera group
*/
void CameraGroup::initializeCameraGroup(const int id_ref_cam,
const int cam_group_idx) {
id_ref_cam_ = id_ref_cam;
cam_group_idx_ = cam_group_idx;
}
CameraGroup::CameraGroup(const int id_ref_cam, const int cam_group_idx)
: id_ref_cam_(id_ref_cam), cam_group_idx_(cam_group_idx){};

/**
* @brief Insert a new camera in the group
Expand Down
6 changes: 3 additions & 3 deletions src/CameraGroup.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* - object observation
* - reference camera in the group
*/
class CameraGroup {
class CameraGroup final {
public:
// datastructure for this camera group
std::map<int, std::weak_ptr<Object3DObs>>
Expand All @@ -44,9 +44,9 @@ class CameraGroup {
int cam_group_idx_;

// Functions
CameraGroup();
CameraGroup() = delete;
~CameraGroup();
void initializeCameraGroup(const int id_ref_cam, const int cam_group_idx);
CameraGroup(const int id_ref_cam, const int cam_group_idx);
void insertCamera(std::shared_ptr<Camera> new_camera);
void insertNewObjectObservation(
std::shared_ptr<Object3DObs> new_object_observation);
Expand Down
5 changes: 1 addition & 4 deletions src/CameraGroupObs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

#include "CameraGroupObs.hpp"

CameraGroupObs::CameraGroupObs() {}

/**
* @brief Associate this observation with its respective camera group
*
* @param new_cam_group camera group to be added
*/
void CameraGroupObs::insertCameraGroup(
std::shared_ptr<CameraGroup> new_cam_group) {
CameraGroupObs::CameraGroupObs(std::shared_ptr<CameraGroup> new_cam_group) {
cam_group_ = new_cam_group;
cam_group_idx_ = new_cam_group->cam_group_idx_;
}
Expand Down
6 changes: 3 additions & 3 deletions src/CameraGroupObs.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CameraGroup;
* - 3D object observations from this camera group observation
* - camera group corresponding to this observation
*/
class CameraGroupObs {
class CameraGroupObs final {
public:
// Objects
std::vector<int> object_idx_; // index of the visible 3d objects
Expand All @@ -32,9 +32,9 @@ class CameraGroupObs {
std::weak_ptr<CameraGroup> cam_group_;

// Functions
CameraGroupObs();
CameraGroupObs() = delete;
~CameraGroupObs();
void insertCameraGroup(std::shared_ptr<CameraGroup> new_cam_group);
CameraGroupObs(std::shared_ptr<CameraGroup> new_cam_group);
void
insertObjectObservation(std::shared_ptr<Object3DObs> new_object_observation);
void computeObjectsPose();
Expand Down
4 changes: 3 additions & 1 deletion src/CameraObs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

#include "CameraObs.hpp"

CameraObs::CameraObs() {}
CameraObs::CameraObs(std::shared_ptr<BoardObs> new_board) {
insertNewBoard(new_board);
}

/**
* @brief Insert new board observation in the camera observation
Expand Down
Loading