James (Peilun) Li | a70e575 | 2024-09-18 20:43:00 -0700 | [diff] [blame] | 1 | #include "y2024_bot3/vision/vision_util.h" |
| 2 | |
| 3 | #include "absl/log/check.h" |
| 4 | #include "absl/log/log.h" |
| 5 | |
| 6 | namespace y2024_bot3::vision { |
| 7 | |
| 8 | // Store a list of ordered cameras as you progress around the robot/box of orins |
| 9 | std::vector<CameraNode> CreateNodeList() { |
| 10 | std::vector<CameraNode> list; |
| 11 | |
| 12 | list.push_back({.node_name = "imu", .camera_number = 0}); |
| 13 | list.push_back({.node_name = "imu", .camera_number = 1}); |
| 14 | list.push_back({.node_name = "orin1", .camera_number = 1}); |
| 15 | list.push_back({.node_name = "orin1", .camera_number = 0}); |
| 16 | |
| 17 | return list; |
| 18 | } |
| 19 | |
| 20 | // From the node_list, create a numbering scheme from 0 to 3 |
| 21 | std::map<std::string, int> CreateOrderingMap( |
| 22 | std::vector<CameraNode> &node_list) { |
| 23 | std::map<std::string, int> map; |
| 24 | |
| 25 | for (uint i = 0; i < node_list.size(); i++) { |
| 26 | map.insert({node_list.at(i).camera_name(), i}); |
| 27 | } |
| 28 | |
| 29 | return map; |
| 30 | } |
| 31 | |
| 32 | const frc971::vision::calibration::CameraCalibration *FindCameraCalibration( |
| 33 | const y2024_bot3::Constants &calibration_data, std::string_view node_name, |
| 34 | int camera_number) { |
| 35 | CHECK(calibration_data.has_cameras()); |
| 36 | for (const y2024_bot3::CameraConfiguration *candidate : |
| 37 | *calibration_data.cameras()) { |
| 38 | CHECK(candidate->has_calibration()); |
| 39 | if (candidate->calibration()->node_name()->string_view() != node_name || |
| 40 | candidate->calibration()->camera_number() != camera_number) { |
| 41 | continue; |
| 42 | } |
| 43 | return candidate->calibration(); |
| 44 | } |
| 45 | LOG(FATAL) << ": Failed to find camera calibration for " << node_name |
| 46 | << " and camera number " << camera_number; |
| 47 | } |
| 48 | |
| 49 | } // namespace y2024_bot3::vision |