blob: 452dd741949f9ff418b593411b1ecd43df107989 [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
16DEFINE_string(calibration_folder, ".", "Folder to place calibration files.");
17DEFINE_string(camera_id, "", "Camera ID in format YY-NN-- year and number.");
18DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
19DEFINE_bool(display_undistorted, false,
20 "If true, display the undistorted image.");
21DEFINE_string(pi, "", "Pi name to calibrate.");
22DEFINE_string(base_intrinsics, "",
23 "Intrinsics to use for estimating board pose prior to solving "
24 "for the new intrinsics.");
25
26namespace frc971 {
27namespace vision {
28namespace {
29
30void Main() {
31 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
32 aos::configuration::ReadConfig(FLAGS_config);
33
34 aos::ShmEventLoop event_loop(&config.message());
35
36 std::string hostname = FLAGS_pi;
37 if (hostname == "") {
38 hostname = aos::network::GetHostname();
39 LOG(INFO) << "Using pi name from hostname as " << hostname;
40 }
41 CHECK(!FLAGS_base_intrinsics.empty())
42 << "Need a base intrinsics json to use to auto-capture images when the "
43 "camera moves.";
44 std::unique_ptr<aos::ExitHandle> exit_handle = event_loop.MakeExitHandle();
45 IntrinsicsCalibration extractor(
46 &event_loop, hostname, FLAGS_camera_id, FLAGS_base_intrinsics,
47 FLAGS_display_undistorted, FLAGS_calibration_folder, exit_handle.get());
48
49 event_loop.Run();
50
51 extractor.MaybeCalibrate();
52}
53
54} // namespace
55} // namespace vision
56} // namespace frc971
57
58int main(int argc, char **argv) {
59 aos::InitGoogle(&argc, &argv);
60 frc971::vision::Main();
61}