From cf88f32d895aad14af3e294b27fdeade7801863e Mon Sep 17 00:00:00 2001 From: Bakin Denis Date: Sun, 10 Mar 2024 00:28:42 +0300 Subject: [PATCH] fix: codestyle --- packages/camera/include/params.h | 6 ++++-- packages/camera/src/params.cpp | 20 +++++++++++--------- packages/camera/test/test.cpp | 17 +++++++++-------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/camera/include/params.h b/packages/camera/include/params.h index 47424ce..8cfc9e4 100644 --- a/packages/camera/include/params.h +++ b/packages/camera/include/params.h @@ -17,9 +17,11 @@ struct CameraIntrinsicParameters { void storeYaml(const std::string& yaml_path) const; static CameraIntrinsicParameters loadFromYaml(const std::string& yaml_path, int camera_id = 0); static bool saveStereoCalibration( - const std::string& yaml_path, cv::Mat& R, cv::Mat& T, cv::Size& image_size); + const std::string& yaml_path, cv::Mat& rotation_vectors, cv::Mat& translation_vectors, + cv::Size& image_size); static void loadStereoCalibration( - const std::string& yaml_path, cv::Mat& R, cv::Mat& T, cv::Size& image_size); + const std::string& yaml_path, cv::Mat& rotation_vectors, cv::Mat& translation_vectors, + cv::Size& image_size); int camera_id = 0; cv::Size image_size{}; diff --git a/packages/camera/src/params.cpp b/packages/camera/src/params.cpp index cc2929a..b72a812 100644 --- a/packages/camera/src/params.cpp +++ b/packages/camera/src/params.cpp @@ -57,7 +57,8 @@ void CameraIntrinsicParameters::storeYaml(const std::string& yaml_path) const { output_file.close(); } bool CameraIntrinsicParameters::saveStereoCalibration( - const std::string& yaml_path, cv::Mat& R, cv::Mat& T, cv::Size& image_size) { + const std::string& yaml_path, cv::Mat& rotation_vectors, cv::Mat& translation_vectors, + cv::Size& image_size) { YAML::Node config; std::ifstream param_file(yaml_path); if (param_file) { @@ -76,7 +77,7 @@ bool CameraIntrinsicParameters::saveStereoCalibration( extrinsics["rotation"].SetStyle(YAML::EmitterStyle::Flow); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { - extrinsics["rotation"].push_back(R.at(i, j)); + extrinsics["rotation"].push_back(rotation_vectors.at(i, j)); } } @@ -84,7 +85,7 @@ bool CameraIntrinsicParameters::saveStereoCalibration( extrinsics["translation"].SetStyle(YAML::EmitterStyle::Flow); for (int i = 0; i < 3; ++i) { - extrinsics["translation"].push_back(T.at(i, 0)); + extrinsics["translation"].push_back(translation_vectors.at(i, 0)); } std::ofstream output_file(yaml_path); @@ -132,15 +133,16 @@ CameraIntrinsicParameters CameraIntrinsicParameters::loadFromYaml( } void CameraIntrinsicParameters::loadStereoCalibration( - const std::string& yaml_path, cv::Mat& R, cv::Mat& T, cv::Size& image_size) { + const std::string& yaml_path, cv::Mat& rotation_vectors, cv::Mat& translation_vectors, + cv::Size& image_size) { const YAML::Node extrinsics = YAML::LoadFile(yaml_path)["stereo_calibration"]; const auto yaml_image_size = extrinsics["image_size"].as>(); image_size = cv::Size(yaml_image_size[0], yaml_image_size[1]); const auto yaml_camera_matrix = extrinsics["rotation"].as>(); - R = cv::Mat(yaml_camera_matrix, true); - R = R.reshape(0, {3, 3}); + rotation_vectors = cv::Mat(yaml_camera_matrix, true); + rotation_vectors = rotation_vectors.reshape(0, {3, 3}); const auto coefs = extrinsics["translation"].as>(); for (size_t i = 0; i < coefs.size(); ++i) { @@ -148,10 +150,10 @@ void CameraIntrinsicParameters::loadStereoCalibration( } printf("\n"); - T = cv::Mat(coefs, true); - T = T.reshape(0, {3, 1}); + translation_vectors = cv::Mat(coefs, true); + translation_vectors = translation_vectors.reshape(0, {3, 1}); for (size_t i = 0; i < coefs.size(); ++i) { - printf("%f ", T.at(i, 0)); + printf("%f ", translation_vectors.at(i, 0)); } printf("\n"); } diff --git a/packages/camera/test/test.cpp b/packages/camera/test/test.cpp index 518ebc4..1771702 100644 --- a/packages/camera/test/test.cpp +++ b/packages/camera/test/test.cpp @@ -85,12 +85,12 @@ TEST(camera, ParamsMultipleReadWrite) { TEST(camera, ParamsStereoCalibWrite) { // create test params const std::string path_to_yaml = "test_params.yaml"; - cv::Mat R_check = (cv::Mat_(3, 3) << 1., 0., 0., 0., 1., 0., 0., 0., 1.); - cv::Mat T_check = (cv::Mat_(3, 1) << 1., 2., 3.); + cv::Mat rotation_check = (cv::Mat_(3, 3) << 1., 0., 0., 0., 1., 0., 0., 0., 1.); + cv::Mat translation_check = (cv::Mat_(3, 1) << 1., 2., 3.); cv::Size image_size_check(1920, 1080); handy::CameraIntrinsicParameters::saveStereoCalibration( - path_to_yaml, R_check, T_check, image_size_check); + path_to_yaml, rotation_check, translation_check, image_size_check); // check for file to exist std::ifstream test_file(path_to_yaml); @@ -98,20 +98,21 @@ TEST(camera, ParamsStereoCalibWrite) { test_file.close(); // loading and checking all params for the first ID - cv::Mat R; - cv::Mat T; + cv::Mat rotation; + cv::Mat translation; cv::Size image_size; - handy::CameraIntrinsicParameters::loadStereoCalibration(path_to_yaml, R, T, image_size); + handy::CameraIntrinsicParameters::loadStereoCalibration( + path_to_yaml, rotation, translation, image_size); EXPECT_EQ(image_size, image_size_check); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; j++) { - EXPECT_EQ(R_check.at(i, j), R.at(i, j)); + EXPECT_EQ(rotation_check.at(i, j), rotation.at(i, j)); } } for (int i = 0; i < 3; ++i) { - EXPECT_EQ(T_check.at(i, 0), T.at(i, 0)); + EXPECT_EQ(translation_check.at(i, 0), translation.at(i, 0)); } }