blob: 224a37c6eb05c3cd7fc928423f00d1b1ceb79005 [file] [log] [blame]
James Kuszmaul7e958812023-02-11 15:34:31 -08001#include <cmath>
2#include <opencv2/calib3d.hpp>
3#include <opencv2/highgui/highgui.hpp>
4#include <opencv2/imgproc.hpp>
5#include <regex>
6
7#include "absl/strings/str_format.h"
8#include "aos/events/shm_event_loop.h"
9#include "aos/init.h"
10#include "aos/network/team_number.h"
11#include "aos/time/time.h"
12#include "aos/util/file.h"
13#include "frc971/vision/intrinsics_calibration_lib.h"
14
15DEFINE_string(calibration_folder, ".", "Folder to place calibration files.");
16DEFINE_string(camera_id, "", "Camera ID in format YY-NN-- year and number.");
17DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
18DEFINE_bool(display_undistorted, false,
19 "If true, display the undistorted image.");
20DEFINE_string(pi, "", "Pi name to calibrate.");
21DEFINE_string(base_intrinsics, "",
22 "Intrinsics to use for estimating board pose prior to solving "
23 "for the new intrinsics.");
24
25namespace frc971 {
26namespace vision {
27namespace {
28
29void Main() {
30 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
31 aos::configuration::ReadConfig(FLAGS_config);
32
33 aos::ShmEventLoop event_loop(&config.message());
34
35 std::string hostname = FLAGS_pi;
36 if (hostname == "") {
37 hostname = aos::network::GetHostname();
38 LOG(INFO) << "Using pi name from hostname as " << hostname;
39 }
40 CHECK(!FLAGS_base_intrinsics.empty())
41 << "Need a base intrinsics json to use to auto-capture images when the "
42 "camera moves.";
43 std::unique_ptr<aos::ExitHandle> exit_handle = event_loop.MakeExitHandle();
44 IntrinsicsCalibration extractor(
45 &event_loop, hostname, FLAGS_camera_id, FLAGS_base_intrinsics,
46 FLAGS_display_undistorted, FLAGS_calibration_folder, exit_handle.get());
47
48 event_loop.Run();
49
50 extractor.MaybeCalibrate();
51}
52
53} // namespace
54} // namespace vision
55} // namespace frc971
56
57int main(int argc, char **argv) {
58 aos::InitGoogle(&argc, &argv);
59 frc971::vision::Main();
60}