blob: b4d3825356a49f5670ce50e0563467b68948bad3 [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
Stephan Pleinesf63bde82024-01-13 15:59:33 -080026namespace frc971::vision {
James Kuszmaul7e958812023-02-11 15:34:31 -080027namespace {
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
Stephan Pleinesf63bde82024-01-13 15:59:33 -080054} // namespace frc971::vision
James Kuszmaul7e958812023-02-11 15:34:31 -080055
56int main(int argc, char **argv) {
57 aos::InitGoogle(&argc, &argv);
58 frc971::vision::Main();
59}