James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 1 | #include <cmath> |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 2 | #include <regex> |
| 3 | |
| 4 | #include "absl/strings/str_format.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 5 | #include <opencv2/calib3d.hpp> |
| 6 | #include <opencv2/highgui/highgui.hpp> |
| 7 | #include <opencv2/imgproc.hpp> |
| 8 | |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 9 | #include "aos/events/shm_event_loop.h" |
| 10 | #include "aos/init.h" |
| 11 | #include "aos/network/team_number.h" |
| 12 | #include "aos/time/time.h" |
| 13 | #include "aos/util/file.h" |
| 14 | #include "frc971/vision/intrinsics_calibration_lib.h" |
| 15 | |
Jim Ostrowski | b974cca | 2024-01-28 15:07:50 -0800 | [diff] [blame] | 16 | // TODO: Would be nice to remove this, but it depends on year-by-year Constants |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 17 | DEFINE_string(base_intrinsics, "", |
| 18 | "Intrinsics to use for estimating board pose prior to solving " |
| 19 | "for the new intrinsics."); |
Jim Ostrowski | b974cca | 2024-01-28 15:07:50 -0800 | [diff] [blame] | 20 | DEFINE_string(calibration_folder, ".", "Folder to place calibration files."); |
| 21 | DEFINE_string(camera_id, "", "Camera ID in format YY-NN-- year and number."); |
| 22 | DEFINE_string(channel, "/camera", "Camera channel to use"); |
| 23 | DEFINE_string(config, "aos_config.json", "Path to the config file to use."); |
| 24 | DEFINE_string(cpu_name, "", "Pi/Orin name to calibrate."); |
| 25 | DEFINE_bool(display_undistorted, false, |
| 26 | "If true, display the undistorted image."); |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 27 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 28 | namespace frc971::vision { |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 29 | namespace { |
| 30 | |
| 31 | void Main() { |
| 32 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 33 | aos::configuration::ReadConfig(FLAGS_config); |
| 34 | |
| 35 | aos::ShmEventLoop event_loop(&config.message()); |
| 36 | |
Jim Ostrowski | b974cca | 2024-01-28 15:07:50 -0800 | [diff] [blame] | 37 | std::string hostname = FLAGS_cpu_name; |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 38 | if (hostname == "") { |
| 39 | hostname = aos::network::GetHostname(); |
Jim Ostrowski | cb8b408 | 2024-01-21 02:23:46 -0800 | [diff] [blame] | 40 | LOG(INFO) << "Using pi/orin name from hostname as " << hostname; |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 41 | } |
| 42 | CHECK(!FLAGS_base_intrinsics.empty()) |
| 43 | << "Need a base intrinsics json to use to auto-capture images when the " |
| 44 | "camera moves."; |
| 45 | std::unique_ptr<aos::ExitHandle> exit_handle = event_loop.MakeExitHandle(); |
Jim Ostrowski | b974cca | 2024-01-28 15:07:50 -0800 | [diff] [blame] | 46 | IntrinsicsCalibration extractor(&event_loop, hostname, FLAGS_channel, |
| 47 | FLAGS_camera_id, FLAGS_base_intrinsics, |
| 48 | FLAGS_display_undistorted, |
| 49 | FLAGS_calibration_folder, exit_handle.get()); |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 50 | |
| 51 | event_loop.Run(); |
| 52 | |
| 53 | extractor.MaybeCalibrate(); |
| 54 | } |
| 55 | |
| 56 | } // namespace |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 57 | } // namespace frc971::vision |
James Kuszmaul | 7e95881 | 2023-02-11 15:34:31 -0800 | [diff] [blame] | 58 | |
| 59 | int main(int argc, char **argv) { |
| 60 | aos::InitGoogle(&argc, &argv); |
| 61 | frc971::vision::Main(); |
| 62 | } |