blob: 16a53a70dc380881a99d34250354da1c58c1c4d3 [file] [log] [blame]
James Kuszmaul7e958812023-02-11 15:34:31 -08001#include <cmath>
James Kuszmaul7e958812023-02-11 15:34:31 -08002#include <regex>
3
4#include "absl/strings/str_format.h"
Philipp Schrader790cb542023-07-05 21:06:52 -07005#include <opencv2/calib3d.hpp>
6#include <opencv2/highgui/highgui.hpp>
7#include <opencv2/imgproc.hpp>
8
James Kuszmaul7e958812023-02-11 15:34:31 -08009#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 Ostrowskib974cca2024-01-28 15:07:50 -080016// TODO: Would be nice to remove this, but it depends on year-by-year Constants
James Kuszmaul7e958812023-02-11 15:34:31 -080017DEFINE_string(base_intrinsics, "",
18 "Intrinsics to use for estimating board pose prior to solving "
19 "for the new intrinsics.");
Jim Ostrowskib974cca2024-01-28 15:07:50 -080020DEFINE_string(calibration_folder, ".", "Folder to place calibration files.");
21DEFINE_string(camera_id, "", "Camera ID in format YY-NN-- year and number.");
22DEFINE_string(channel, "/camera", "Camera channel to use");
23DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
24DEFINE_string(cpu_name, "", "Pi/Orin name to calibrate.");
25DEFINE_bool(display_undistorted, false,
26 "If true, display the undistorted image.");
James Kuszmaul7e958812023-02-11 15:34:31 -080027
Stephan Pleinesf63bde82024-01-13 15:59:33 -080028namespace frc971::vision {
James Kuszmaul7e958812023-02-11 15:34:31 -080029namespace {
30
31void Main() {
32 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
33 aos::configuration::ReadConfig(FLAGS_config);
34
35 aos::ShmEventLoop event_loop(&config.message());
36
Jim Ostrowskib974cca2024-01-28 15:07:50 -080037 std::string hostname = FLAGS_cpu_name;
James Kuszmaul7e958812023-02-11 15:34:31 -080038 if (hostname == "") {
39 hostname = aos::network::GetHostname();
Jim Ostrowskicb8b4082024-01-21 02:23:46 -080040 LOG(INFO) << "Using pi/orin name from hostname as " << hostname;
James Kuszmaul7e958812023-02-11 15:34:31 -080041 }
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 Ostrowskib974cca2024-01-28 15:07:50 -080046 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 Kuszmaul7e958812023-02-11 15:34:31 -080050
51 event_loop.Run();
52
53 extractor.MaybeCalibrate();
54}
55
56} // namespace
Stephan Pleinesf63bde82024-01-13 15:59:33 -080057} // namespace frc971::vision
James Kuszmaul7e958812023-02-11 15:34:31 -080058
59int main(int argc, char **argv) {
60 aos::InitGoogle(&argc, &argv);
61 frc971::vision::Main();
62}