Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 1 | #include <cmath> |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 2 | #include <opencv2/calib3d.hpp> |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 3 | #include <opencv2/highgui/highgui.hpp> |
| 4 | #include <opencv2/imgproc.hpp> |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 5 | #include <regex> |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 6 | |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 7 | #include "Eigen/Dense" |
| 8 | #include "Eigen/Geometry" |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 9 | #include "absl/strings/str_format.h" |
| 10 | #include "aos/events/shm_event_loop.h" |
| 11 | #include "aos/init.h" |
| 12 | #include "aos/network/team_number.h" |
| 13 | #include "aos/time/time.h" |
| 14 | #include "aos/util/file.h" |
Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 15 | #include "frc971/vision/charuco_lib.h" |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 16 | |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 17 | DEFINE_string(calibration_folder, ".", "Folder to place calibration files."); |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 18 | DEFINE_string(camera_id, "", "Camera ID in format YY-NN-- year and number."); |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame] | 19 | DEFINE_string(config, "aos_config.json", "Path to the config file to use."); |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 20 | DEFINE_bool(display_undistorted, false, |
| 21 | "If true, display the undistorted image."); |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 22 | DEFINE_string(pi, "", "Pi name to calibrate."); |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 23 | |
| 24 | namespace frc971 { |
| 25 | namespace vision { |
| 26 | |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 27 | class Calibration { |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 28 | public: |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 29 | Calibration(aos::ShmEventLoop *event_loop, std::string_view pi, |
| 30 | std::string_view camera_id) |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 31 | : event_loop_(event_loop), |
| 32 | pi_(pi), |
| 33 | pi_number_(aos::network::ParsePiNumber(pi)), |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 34 | camera_id_(camera_id), |
Yash Chainani | 460c9fb | 2022-02-12 18:14:50 -0800 | [diff] [blame] | 35 | prev_H_camera_board_(Eigen::Affine3d()), |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 36 | prev_image_H_camera_board_(Eigen::Affine3d()), |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 37 | charuco_extractor_( |
Milind Upadhyay | c6e42ee | 2022-12-27 00:02:11 -0800 | [diff] [blame] | 38 | event_loop, pi, TargetType::kCharuco, "/camera", |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 39 | [this](cv::Mat rgb_image, |
| 40 | const aos::monotonic_clock::time_point eof, |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 41 | std::vector<cv::Vec4i> charuco_ids, |
| 42 | std::vector<std::vector<cv::Point2f>> charuco_corners, |
| 43 | bool valid, std::vector<Eigen::Vector3d> rvecs_eigen, |
| 44 | std::vector<Eigen::Vector3d> tvecs_eigen) { |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 45 | HandleCharuco(rgb_image, eof, charuco_ids, charuco_corners, valid, |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 46 | rvecs_eigen, tvecs_eigen); |
| 47 | }), |
| 48 | image_callback_( |
| 49 | event_loop, |
| 50 | absl::StrCat( |
| 51 | "/pi", std::to_string(aos::network::ParsePiNumber(pi).value()), |
| 52 | "/camera"), |
| 53 | [this](cv::Mat rgb_image, |
| 54 | const aos::monotonic_clock::time_point eof) { |
| 55 | charuco_extractor_.HandleImage(rgb_image, eof); |
milind-u | 0cb5311 | 2023-02-03 20:32:55 -0800 | [diff] [blame^] | 56 | }, |
| 57 | std::chrono::milliseconds(5)) { |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 58 | CHECK(pi_number_) << ": Invalid pi number " << pi |
| 59 | << ", failed to parse pi number"; |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 60 | std::regex re{"^[0-9][0-9]-[0-9][0-9]"}; |
| 61 | CHECK(std::regex_match(camera_id_, re)) |
| 62 | << ": Invalid camera_id '" << camera_id_ |
| 63 | << "', should be of form YY-NN"; |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Austin Schuh | ea7b014 | 2021-10-08 22:04:53 -0700 | [diff] [blame] | 66 | void HandleCharuco(cv::Mat rgb_image, |
| 67 | const aos::monotonic_clock::time_point /*eof*/, |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 68 | std::vector<cv::Vec4i> charuco_ids, |
| 69 | std::vector<std::vector<cv::Point2f>> charuco_corners, |
| 70 | bool valid, std::vector<Eigen::Vector3d> rvecs_eigen, |
| 71 | std::vector<Eigen::Vector3d> tvecs_eigen) { |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 72 | // Reduce resolution displayed on remote viewer to prevent lag |
| 73 | cv::resize(rgb_image, rgb_image, |
| 74 | cv::Size(rgb_image.cols / 2, rgb_image.rows / 2)); |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 75 | cv::imshow("Display", rgb_image); |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 76 | |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 77 | if (FLAGS_display_undistorted) { |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 78 | const cv::Size image_size(rgb_image.cols, rgb_image.rows); |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 79 | cv::Mat undistorted_rgb_image(image_size, CV_8UC3); |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 80 | cv::undistort(rgb_image, undistorted_rgb_image, |
| 81 | charuco_extractor_.camera_matrix(), |
| 82 | charuco_extractor_.dist_coeffs()); |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 83 | |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 84 | cv::imshow("Display undist", undistorted_rgb_image); |
| 85 | } |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 86 | |
Jim Ostrowski | 634b265 | 2022-03-04 02:10:53 -0800 | [diff] [blame] | 87 | int keystroke = cv::waitKey(1); |
| 88 | |
| 89 | // If we haven't got a valid pose estimate, don't use these points |
| 90 | if (!valid) { |
| 91 | return; |
| 92 | } |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 93 | CHECK(tvecs_eigen.size() == 1) |
| 94 | << "Charuco board should only return one translational pose"; |
| 95 | CHECK(rvecs_eigen.size() == 1) |
| 96 | << "Charuco board should only return one rotational pose"; |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 97 | // Calibration calculates rotation and translation delta from last image |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 98 | // stored to automatically capture next image |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 99 | |
Yash Chainani | 460c9fb | 2022-02-12 18:14:50 -0800 | [diff] [blame] | 100 | Eigen::Affine3d H_board_camera = |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 101 | Eigen::Translation3d(tvecs_eigen[0]) * |
| 102 | Eigen::AngleAxisd(rvecs_eigen[0].norm(), |
| 103 | rvecs_eigen[0] / rvecs_eigen[0].norm()); |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 104 | Eigen::Affine3d H_camera_board_ = H_board_camera.inverse(); |
Yash Chainani | 460c9fb | 2022-02-12 18:14:50 -0800 | [diff] [blame] | 105 | Eigen::Affine3d H_delta = H_board_camera * prev_H_camera_board_; |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 106 | |
Yash Chainani | 460c9fb | 2022-02-12 18:14:50 -0800 | [diff] [blame] | 107 | Eigen::AngleAxisd delta_r = Eigen::AngleAxisd(H_delta.rotation()); |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 108 | |
Yash Chainani | 460c9fb | 2022-02-12 18:14:50 -0800 | [diff] [blame] | 109 | Eigen::Vector3d delta_t = H_delta.translation(); |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 110 | |
| 111 | double r_norm = std::abs(delta_r.angle()); |
| 112 | double t_norm = delta_t.norm(); |
| 113 | |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 114 | bool store_image = false; |
Jim Ostrowski | 634b265 | 2022-03-04 02:10:53 -0800 | [diff] [blame] | 115 | double percent_motion = |
| 116 | std::max<double>(r_norm / kDeltaRThreshold, t_norm / kDeltaTThreshold); |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 117 | LOG(INFO) << "Captured: " << all_charuco_ids_.size() << " points; Moved " |
| 118 | << percent_motion << "% of what's needed"; |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 119 | // Verify that camera has moved enough from last stored image |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 120 | if (r_norm > kDeltaRThreshold || t_norm > kDeltaTThreshold) { |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 121 | // frame_ refers to deltas between current and last captured image |
| 122 | Eigen::Affine3d frame_H_delta = |
| 123 | H_board_camera * prev_image_H_camera_board_; |
| 124 | |
| 125 | Eigen::AngleAxisd frame_delta_r = |
| 126 | Eigen::AngleAxisd(frame_H_delta.rotation()); |
| 127 | |
| 128 | Eigen::Vector3d frame_delta_t = frame_H_delta.translation(); |
| 129 | |
| 130 | double frame_r_norm = std::abs(frame_delta_r.angle()); |
| 131 | double frame_t_norm = frame_delta_t.norm(); |
| 132 | |
| 133 | // Make sure camera has stopped moving before storing image |
| 134 | store_image = |
| 135 | frame_r_norm < kFrameDeltaRLimit && frame_t_norm < kFrameDeltaTLimit; |
Jim Ostrowski | 634b265 | 2022-03-04 02:10:53 -0800 | [diff] [blame] | 136 | double percent_stop = std::max<double>(frame_r_norm / kFrameDeltaRLimit, |
| 137 | frame_t_norm / kFrameDeltaTLimit); |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 138 | LOG(INFO) << "Captured: " << all_charuco_ids_.size() |
| 139 | << "points; Moved enough (" << percent_motion |
| 140 | << "%); Need to stop (last motion was " << percent_stop |
| 141 | << "% of limit; needs to be < 1 to capture)"; |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 142 | } |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 143 | prev_image_H_camera_board_ = H_camera_board_; |
| 144 | |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 145 | if (store_image) { |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 146 | if (valid) { |
Yash Chainani | 460c9fb | 2022-02-12 18:14:50 -0800 | [diff] [blame] | 147 | prev_H_camera_board_ = H_camera_board_; |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 148 | |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 149 | // Unpack the Charuco ids from Vec4i |
| 150 | std::vector<int> charuco_ids_int; |
| 151 | for (cv::Vec4i charuco_id : charuco_ids) { |
| 152 | charuco_ids_int.emplace_back(charuco_id[0]); |
| 153 | } |
| 154 | all_charuco_ids_.emplace_back(std::move(charuco_ids_int)); |
| 155 | all_charuco_corners_.emplace_back(std::move(charuco_corners[0])); |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 156 | |
| 157 | if (r_norm > kDeltaRThreshold) { |
| 158 | LOG(INFO) << "Triggered by rotation delta = " << r_norm << " > " |
| 159 | << kDeltaRThreshold; |
| 160 | } |
| 161 | if (t_norm > kDeltaTThreshold) { |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 162 | LOG(INFO) << "Triggered by translation delta = " << t_norm << " > " |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 163 | << kDeltaTThreshold; |
| 164 | } |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 165 | } |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 166 | |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 167 | } else if ((keystroke & 0xFF) == static_cast<int>('q')) { |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 168 | event_loop_->Exit(); |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 169 | } |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | void MaybeCalibrate() { |
Jim Ostrowski | 634b265 | 2022-03-04 02:10:53 -0800 | [diff] [blame] | 173 | // TODO: This number should depend on coarse vs. fine pattern |
| 174 | // Maybe just on total # of ids found, not just images |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 175 | if (all_charuco_ids_.size() >= 50) { |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 176 | LOG(INFO) << "Beginning calibration on " << all_charuco_ids_.size() |
| 177 | << " images"; |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 178 | cv::Mat cameraMatrix, distCoeffs; |
| 179 | std::vector<cv::Mat> rvecs, tvecs; |
| 180 | cv::Mat stdDeviationsIntrinsics, stdDeviationsExtrinsics, perViewErrors; |
| 181 | |
| 182 | // Set calibration flags (same as in calibrateCamera() function) |
| 183 | int calibration_flags = 0; |
| 184 | cv::Size img_size(640, 480); |
| 185 | const double reprojection_error = cv::aruco::calibrateCameraCharuco( |
| 186 | all_charuco_corners_, all_charuco_ids_, charuco_extractor_.board(), |
| 187 | img_size, cameraMatrix, distCoeffs, rvecs, tvecs, |
| 188 | stdDeviationsIntrinsics, stdDeviationsExtrinsics, perViewErrors, |
| 189 | calibration_flags); |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 190 | CHECK_LE(reprojection_error, 1.0) |
| 191 | << ": Reproduction error is bad-- greater than 1 pixel."; |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 192 | LOG(INFO) << "Reprojection Error is " << reprojection_error; |
| 193 | |
| 194 | flatbuffers::FlatBufferBuilder fbb; |
| 195 | flatbuffers::Offset<flatbuffers::String> name_offset = |
| 196 | fbb.CreateString(absl::StrFormat("pi%d", pi_number_.value())); |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 197 | flatbuffers::Offset<flatbuffers::String> camera_id_offset = |
| 198 | fbb.CreateString(camera_id_); |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 199 | flatbuffers::Offset<flatbuffers::Vector<float>> intrinsics_offset = |
| 200 | fbb.CreateVector<float>(9u, [&cameraMatrix](size_t i) { |
| 201 | return static_cast<float>( |
| 202 | reinterpret_cast<double *>(cameraMatrix.data)[i]); |
| 203 | }); |
| 204 | |
| 205 | flatbuffers::Offset<flatbuffers::Vector<float>> |
| 206 | distortion_coefficients_offset = |
| 207 | fbb.CreateVector<float>(5u, [&distCoeffs](size_t i) { |
| 208 | return static_cast<float>( |
| 209 | reinterpret_cast<double *>(distCoeffs.data)[i]); |
| 210 | }); |
| 211 | |
| 212 | sift::CameraCalibration::Builder camera_calibration_builder(fbb); |
| 213 | std::optional<uint16_t> team_number = |
| 214 | aos::network::team_number_internal::ParsePiTeamNumber(pi_); |
| 215 | CHECK(team_number) << ": Invalid pi hostname " << pi_ |
| 216 | << ", failed to parse team number"; |
| 217 | |
| 218 | const aos::realtime_clock::time_point realtime_now = |
| 219 | aos::realtime_clock::now(); |
| 220 | camera_calibration_builder.add_node_name(name_offset); |
| 221 | camera_calibration_builder.add_team_number(team_number.value()); |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 222 | camera_calibration_builder.add_camera_id(camera_id_offset); |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 223 | camera_calibration_builder.add_calibration_timestamp( |
| 224 | realtime_now.time_since_epoch().count()); |
| 225 | camera_calibration_builder.add_intrinsics(intrinsics_offset); |
| 226 | camera_calibration_builder.add_dist_coeffs( |
| 227 | distortion_coefficients_offset); |
| 228 | fbb.Finish(camera_calibration_builder.Finish()); |
| 229 | |
| 230 | aos::FlatbufferDetachedBuffer<sift::CameraCalibration> camera_calibration( |
| 231 | fbb.Release()); |
| 232 | std::stringstream time_ss; |
| 233 | time_ss << realtime_now; |
| 234 | |
| 235 | const std::string calibration_filename = |
| 236 | FLAGS_calibration_folder + |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 237 | absl::StrFormat("/calibration_pi-%d-%d_cam-%s_%s.json", |
| 238 | team_number.value(), pi_number_.value(), camera_id_, |
| 239 | time_ss.str()); |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 240 | |
| 241 | LOG(INFO) << calibration_filename << " -> " |
| 242 | << aos::FlatbufferToJson(camera_calibration, |
| 243 | {.multi_line = true}); |
| 244 | |
| 245 | aos::util::WriteStringToFileOrDie( |
| 246 | calibration_filename, |
| 247 | aos::FlatbufferToJson(camera_calibration, {.multi_line = true})); |
| 248 | } else { |
| 249 | LOG(INFO) << "Skipping calibration due to not enough images."; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | private: |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 254 | static constexpr double kDeltaRThreshold = M_PI / 6.0; |
| 255 | static constexpr double kDeltaTThreshold = 0.3; |
| 256 | |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 257 | static constexpr double kFrameDeltaRLimit = M_PI / 60; |
| 258 | static constexpr double kFrameDeltaTLimit = 0.01; |
| 259 | |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 260 | aos::ShmEventLoop *event_loop_; |
| 261 | std::string pi_; |
| 262 | const std::optional<uint16_t> pi_number_; |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 263 | const std::string camera_id_; |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 264 | |
| 265 | std::vector<std::vector<int>> all_charuco_ids_; |
| 266 | std::vector<std::vector<cv::Point2f>> all_charuco_corners_; |
| 267 | |
Yash Chainani | 460c9fb | 2022-02-12 18:14:50 -0800 | [diff] [blame] | 268 | Eigen::Affine3d H_camera_board_; |
| 269 | Eigen::Affine3d prev_H_camera_board_; |
Yash Chainani | 24fc2bd | 2022-02-14 12:43:29 -0800 | [diff] [blame] | 270 | Eigen::Affine3d prev_image_H_camera_board_; |
Yash Chainani | 5c005da | 2022-01-22 16:51:11 -0800 | [diff] [blame] | 271 | |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 272 | CharucoExtractor charuco_extractor_; |
Jim Ostrowski | b3cab97 | 2022-12-03 15:47:00 -0800 | [diff] [blame] | 273 | ImageCallback image_callback_; |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | namespace { |
| 277 | |
| 278 | void Main() { |
| 279 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 280 | aos::configuration::ReadConfig(FLAGS_config); |
| 281 | |
| 282 | aos::ShmEventLoop event_loop(&config.message()); |
| 283 | |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 284 | std::string hostname = FLAGS_pi; |
| 285 | if (hostname == "") { |
| 286 | hostname = aos::network::GetHostname(); |
| 287 | LOG(INFO) << "Using pi name from hostname as " << hostname; |
| 288 | } |
| 289 | Calibration extractor(&event_loop, hostname, FLAGS_camera_id); |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 290 | |
| 291 | event_loop.Run(); |
| 292 | |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 293 | extractor.MaybeCalibrate(); |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | } // namespace |
| 297 | } // namespace vision |
| 298 | } // namespace frc971 |
| 299 | |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 300 | int main(int argc, char **argv) { |
| 301 | aos::InitGoogle(&argc, &argv); |
Austin Schuh | 25837f2 | 2021-06-27 15:49:14 -0700 | [diff] [blame] | 302 | frc971::vision::Main(); |
Austin Schuh | c1f118e | 2020-04-11 15:50:08 -0700 | [diff] [blame] | 303 | } |