Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 1 | #ifndef _Y2019_VISION_CONSTANTS_H_ |
| 2 | #define _Y2019_VISION_CONSTANTS_H_ |
| 3 | |
| 4 | #include <math.h> |
| 5 | #include <array> |
| 6 | #include <string> |
| 7 | |
| 8 | namespace y2019 { |
| 9 | namespace vision { |
| 10 | |
| 11 | // Position of the idealized camera in 3d space. |
| 12 | struct CameraGeometry { |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 13 | static constexpr size_t kNumParams = 4; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 14 | // In Meters from floor under imu center. |
Austin Schuh | a2464b2 | 2019-03-08 19:42:11 -0800 | [diff] [blame^] | 15 | ::std::array<double, 3> location{{0.0, 0.0, 0.0}}; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 16 | double heading = 0.0; |
| 17 | |
| 18 | void set(double *data) { |
Austin Schuh | a2464b2 | 2019-03-08 19:42:11 -0800 | [diff] [blame^] | 19 | data[0] = location[0]; |
| 20 | data[1] = location[1]; |
| 21 | data[2] = location[2]; |
| 22 | data[3] = heading; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 23 | } |
| 24 | static CameraGeometry get(const double *data) { |
| 25 | CameraGeometry out; |
| 26 | out.location[0] = data[0]; |
| 27 | out.location[1] = data[1]; |
| 28 | out.location[2] = data[2]; |
| 29 | out.heading = data[3]; |
| 30 | return out; |
| 31 | } |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 32 | |
Austin Schuh | 813d8d7 | 2019-03-03 21:11:53 -0800 | [diff] [blame] | 33 | void Dump(std::basic_ostream<char> *o) const; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | struct IntrinsicParams { |
| 37 | static constexpr size_t kNumParams = 3; |
| 38 | |
| 39 | double mount_angle = 0.819433 / 180.0 * M_PI; // 9.32615 / 180.0 * M_PI; |
| 40 | double focal_length = 666.763; // 734.328; |
| 41 | // This is a final rotation where the camera isn't straight. |
| 42 | double barrel_mount = 2.72086 / 180.0 * M_PI; |
| 43 | |
| 44 | void set(double *data) { |
| 45 | data[0] = mount_angle; |
| 46 | data[1] = focal_length; |
| 47 | data[2] = barrel_mount; |
| 48 | } |
| 49 | static IntrinsicParams get(const double *data) { |
| 50 | IntrinsicParams out; |
| 51 | out.mount_angle = data[0]; |
| 52 | out.focal_length = data[1]; |
| 53 | out.barrel_mount = data[2]; |
| 54 | return out; |
| 55 | } |
Austin Schuh | 813d8d7 | 2019-03-03 21:11:53 -0800 | [diff] [blame] | 56 | void Dump(std::basic_ostream<char> *o) const; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | // Metadata about the calibration results (Should be good enough to reproduce). |
| 60 | struct DatasetInfo { |
| 61 | int camera_id; |
| 62 | // In meters from IMU start. |
| 63 | std::array<double, 2> to_tape_measure_start; |
| 64 | // In meters, |
| 65 | std::array<double, 2> tape_measure_direction; |
| 66 | // This will multiply tape_measure_direction and thus has no units. |
| 67 | double beginning_tape_measure_reading; |
| 68 | const char *filename_prefix; |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 69 | int num_images; |
| 70 | |
Austin Schuh | 813d8d7 | 2019-03-03 21:11:53 -0800 | [diff] [blame] | 71 | void Dump(std::basic_ostream<char> *o) const; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | struct CameraCalibration { |
| 75 | IntrinsicParams intrinsics; |
| 76 | CameraGeometry geometry; |
| 77 | DatasetInfo dataset; |
| 78 | }; |
| 79 | |
| 80 | const CameraCalibration *GetCamera(int camera_id); |
| 81 | |
James Kuszmaul | e2c71ea | 2019-03-04 08:14:21 -0800 | [diff] [blame] | 82 | // Serial number of the teensy for each robot. |
| 83 | constexpr uint32_t CodeBotTeensyId() { return 0xffff322e; } |
| 84 | |
| 85 | // Get the IDs of the cameras in each port for a particular teensy board. |
| 86 | // inlined so that we don't have to deal with including it in the autogenerated |
| 87 | // constants.cc. |
| 88 | inline std::array<int, 5> CameraSerialNumbers(uint32_t processor_id) { |
| 89 | switch (processor_id) { |
| 90 | case CodeBotTeensyId(): |
| 91 | return {{0, 0, 0, 16, 19}}; |
| 92 | default: |
| 93 | return {{0, 0, 0, 0, 0}}; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Rewrites constants.cc, adding camera calibration constants for the camera_id |
| 98 | // specified. If camera_id is less than zero, just rewrites the file without |
| 99 | // changing anything. |
| 100 | void DumpCameraConstants(const char *fname, int camera_id, |
| 101 | const CameraCalibration &value); |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 102 | |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 103 | } // namespace vision |
| 104 | } // namespace y2019 |
| 105 | |
| 106 | #endif // _Y2019_VISION_CONSTANTS_H_ |