blob: db9a4f25bd41ddac728367f3967beac284f811bb [file] [log] [blame]
Maxwell Hendersonfebee252023-01-28 16:53:52 -08001#include "y2023/vision/aprilrobotics.h"
2
Austin Schuh99f7c6a2024-06-25 22:07:44 -07003#include "absl/flags/flag.h"
Jim Ostrowski49be8232023-03-23 01:00:14 -07004#include <opencv2/highgui.hpp>
5
milind-ua30a4a12023-03-24 20:49:41 -07006#include "y2023/vision/vision_util.h"
7
Austin Schuh99f7c6a2024-06-25 22:07:44 -07008ABSL_FLAG(
9 bool, debug, false,
Maxwell Hendersonfebee252023-01-28 16:53:52 -080010 "If true, dump a ton of debug and crash on the first valid detection.");
11
Austin Schuh99f7c6a2024-06-25 22:07:44 -070012ABSL_FLAG(double, min_decision_margin, 50.0,
13 "Minimum decision margin (confidence) for an apriltag detection");
14ABSL_FLAG(int32_t, pixel_border, 10,
15 "Size of image border within which to reject detected corners");
16ABSL_FLAG(
17 double, max_expected_distortion, 0.314,
milind-u60e7fe52023-02-26 16:13:50 -080018 "Maximum expected value for unscaled distortion factors. Will scale "
19 "distortion factors so that this value (and a higher distortion) maps to "
20 "1.0.");
Austin Schuh99f7c6a2024-06-25 22:07:44 -070021ABSL_FLAG(uint64_t, pose_estimation_iterations, 50,
22 "Number of iterations for apriltag pose estimation.");
milind-uf2a4e322023-02-01 19:33:10 -080023
Stephan Pleinesf63bde82024-01-13 15:59:33 -080024namespace y2023::vision {
Maxwell Hendersonfebee252023-01-28 16:53:52 -080025
Austin Schuhd2667932023-02-04 16:22:39 -080026namespace chrono = std::chrono;
27
Jim Ostrowskicb8b4082024-01-21 02:23:46 -080028// Set max age on image for processing at 20 ms. For 60Hz, we should be
29// processing at least every 16.7ms
30constexpr aos::monotonic_clock::duration kMaxImageAge =
31 std::chrono::milliseconds(20);
32
Maxwell Hendersonfebee252023-01-28 16:53:52 -080033AprilRoboticsDetector::AprilRoboticsDetector(aos::EventLoop *event_loop,
milind-ua30a4a12023-03-24 20:49:41 -070034 std::string_view channel_name,
35 bool flip_image)
James Kuszmauld67f6d22023-02-05 17:37:25 -080036 : calibration_data_(event_loop),
milind-uf5b3b4b2023-02-26 14:50:38 -080037 image_size_(0, 0),
milind-ua30a4a12023-03-24 20:49:41 -070038 flip_image_(flip_image),
39 node_name_(event_loop->node()->name()->string_view()),
Maxwell Hendersonfebee252023-01-28 16:53:52 -080040 ftrace_(),
milind-ufbc5c812023-04-06 21:24:29 -070041 image_callback_(
42 event_loop, channel_name,
Jim Ostrowskicb8b4082024-01-21 02:23:46 -080043 [this](cv::Mat image_color_mat,
44 const aos::monotonic_clock::time_point eof) {
milind-ufbc5c812023-04-06 21:24:29 -070045 HandleImage(image_color_mat, eof);
46 },
Jim Ostrowskicb8b4082024-01-21 02:23:46 -080047 kMaxImageAge),
Maxwell Hendersonfebee252023-01-28 16:53:52 -080048 target_map_sender_(
Yash Chainani728ae222023-02-04 19:48:12 -080049 event_loop->MakeSender<frc971::vision::TargetMap>("/camera")),
milind-u7aa29e22023-02-23 20:22:01 -080050 image_annotations_sender_(
milind-u99b1a762023-03-12 16:48:32 -070051 event_loop->MakeSender<foxglove::ImageAnnotations>("/camera")),
52 rejections_(0) {
Maxwell Hendersonfebee252023-01-28 16:53:52 -080053 tag_family_ = tag16h5_create();
54 tag_detector_ = apriltag_detector_create();
55
56 apriltag_detector_add_family_bits(tag_detector_, tag_family_, 1);
57 tag_detector_->nthreads = 6;
58 tag_detector_->wp = workerpool_create(tag_detector_->nthreads);
59 tag_detector_->qtp.min_white_black_diff = 5;
Austin Schuh99f7c6a2024-06-25 22:07:44 -070060 tag_detector_->debug = absl::GetFlag(FLAGS_debug);
Maxwell Hendersonfebee252023-01-28 16:53:52 -080061
62 std::string hostname = aos::network::GetHostname();
63
64 // Check team string is valid
James Kuszmauld67f6d22023-02-05 17:37:25 -080065 calibration_ = FindCameraCalibration(
66 calibration_data_.constants(), event_loop->node()->name()->string_view());
milind-uf2a4e322023-02-01 19:33:10 -080067
68 extrinsics_ = CameraExtrinsics(calibration_);
Maxwell Hendersonfebee252023-01-28 16:53:52 -080069 intrinsics_ = CameraIntrinsics(calibration_);
milind-uf2a4e322023-02-01 19:33:10 -080070 // Create an undistort projection matrix using the intrinsics
71 projection_matrix_ = cv::Mat::zeros(3, 4, CV_64F);
72 intrinsics_.rowRange(0, 3).colRange(0, 3).copyTo(
73 projection_matrix_.rowRange(0, 3).colRange(0, 3));
74
75 dist_coeffs_ = CameraDistCoeffs(calibration_);
Maxwell Hendersonfebee252023-01-28 16:53:52 -080076
77 image_callback_.set_format(frc971::vision::ImageCallback::Format::GRAYSCALE);
78}
79
80AprilRoboticsDetector::~AprilRoboticsDetector() {
81 apriltag_detector_destroy(tag_detector_);
82 free(tag_family_);
83}
84
85void AprilRoboticsDetector::SetWorkerpoolAffinities() {
86 for (int i = 0; i < tag_detector_->wp->nthreads; i++) {
87 cpu_set_t affinity;
88 CPU_ZERO(&affinity);
89 CPU_SET(i, &affinity);
90 pthread_setaffinity_np(tag_detector_->wp->threads[i], sizeof(affinity),
91 &affinity);
92 struct sched_param param;
93 param.sched_priority = 20;
94 int res = pthread_setschedparam(tag_detector_->wp->threads[i], SCHED_FIFO,
95 &param);
96 PCHECK(res == 0) << "Failed to set priority of threadpool threads";
97 }
98}
99
milind-uf2a4e322023-02-01 19:33:10 -0800100void AprilRoboticsDetector::HandleImage(cv::Mat image_grayscale,
milind-u09fb1252023-01-28 19:21:41 -0800101 aos::monotonic_clock::time_point eof) {
milind-uf5b3b4b2023-02-26 14:50:38 -0800102 image_size_ = image_grayscale.size();
103
milind-u99b1a762023-03-12 16:48:32 -0700104 DetectionResult result = DetectTags(image_grayscale, eof);
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800105
106 auto builder = target_map_sender_.MakeBuilder();
107 std::vector<flatbuffers::Offset<frc971::vision::TargetPoseFbs>> target_poses;
milind-ude9045f2023-03-25 18:17:12 -0700108 for (auto &detection : result.detections) {
109 auto *fbb = builder.fbb();
110 auto pose = BuildTargetPose(detection, fbb);
111 DestroyPose(&detection.pose);
112 target_poses.emplace_back(pose);
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800113 }
114 const auto target_poses_offset = builder.fbb()->CreateVector(target_poses);
115 auto target_map_builder = builder.MakeBuilder<frc971::vision::TargetMap>();
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800116 target_map_builder.add_target_poses(target_poses_offset);
milind-u09fb1252023-01-28 19:21:41 -0800117 target_map_builder.add_monotonic_timestamp_ns(eof.time_since_epoch().count());
milind-u99b1a762023-03-12 16:48:32 -0700118 target_map_builder.add_rejections(result.rejections);
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800119 builder.CheckOk(builder.Send(target_map_builder.Finish()));
120}
121
122flatbuffers::Offset<frc971::vision::TargetPoseFbs>
milind-ufc8ab702023-02-26 14:14:39 -0800123AprilRoboticsDetector::BuildTargetPose(const Detection &detection,
milind-u681c4712023-02-23 21:22:50 -0800124 flatbuffers::FlatBufferBuilder *fbb) {
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800125 const auto T =
milind-ufc8ab702023-02-26 14:14:39 -0800126 Eigen::Translation3d(detection.pose.t->data[0], detection.pose.t->data[1],
127 detection.pose.t->data[2]);
milind-u3f5f83c2023-01-29 15:23:51 -0800128 const auto position_offset =
129 frc971::vision::CreatePosition(*fbb, T.x(), T.y(), T.z());
130
milind-u633c4c02023-02-25 22:51:45 -0800131 // Aprilrobotics stores the rotation matrix in row-major order
132 const auto orientation = Eigen::Quaterniond(
milind-ufc8ab702023-02-26 14:14:39 -0800133 Eigen::Matrix<double, 3, 3, Eigen::RowMajor>(detection.pose.R->data));
milind-u3f5f83c2023-01-29 15:23:51 -0800134 const auto orientation_offset = frc971::vision::CreateQuaternion(
135 *fbb, orientation.w(), orientation.x(), orientation.y(), orientation.z());
136
milind-u681c4712023-02-23 21:22:50 -0800137 return frc971::vision::CreateTargetPoseFbs(
milind-ufc8ab702023-02-26 14:14:39 -0800138 *fbb, detection.det.id, position_offset, orientation_offset,
milind-uf5b3b4b2023-02-26 14:50:38 -0800139 detection.det.decision_margin, detection.pose_error,
milind-ude9045f2023-03-25 18:17:12 -0700140 detection.distortion_factor, detection.pose_error_ratio);
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800141}
142
milind-uf2a4e322023-02-01 19:33:10 -0800143void AprilRoboticsDetector::UndistortDetection(
144 apriltag_detection_t *det) const {
145 // 4 corners
146 constexpr size_t kRows = 4;
147 // 2d points
148 constexpr size_t kCols = 2;
149
150 cv::Mat distorted_points(kRows, kCols, CV_64F, det->p);
151 cv::Mat undistorted_points = cv::Mat::zeros(kRows, kCols, CV_64F);
152
153 // Undistort the april tag points
154 cv::undistortPoints(distorted_points, undistorted_points, intrinsics_,
155 dist_coeffs_, cv::noArray(), projection_matrix_);
156
157 // Copy the undistorted points into det
158 for (size_t i = 0; i < kRows; i++) {
159 for (size_t j = 0; j < kCols; j++) {
160 det->p[i][j] = undistorted_points.at<double>(i, j);
161 }
162 }
163}
164
milind-uf5b3b4b2023-02-26 14:50:38 -0800165double AprilRoboticsDetector::ComputeDistortionFactor(
166 const std::vector<cv::Point2f> &orig_corners,
167 const std::vector<cv::Point2f> &corners) {
168 CHECK_EQ(orig_corners.size(), 4ul);
169 CHECK_EQ(corners.size(), 4ul);
170
171 double avg_distance = 0.0;
172 for (size_t i = 0; i < corners.size(); i++) {
173 avg_distance += cv::norm(orig_corners[i] - corners[i]);
174 }
175 avg_distance /= corners.size();
176
milind-u8773c232023-03-11 14:59:06 -0800177 // Normalize avg_distance by dividing by the image diagonal,
178 // and then the maximum expected distortion
milind-uf5b3b4b2023-02-26 14:50:38 -0800179 double distortion_factor =
180 avg_distance /
milind-u8773c232023-03-11 14:59:06 -0800181 cv::norm(cv::Point2d(image_size_.width, image_size_.height));
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700182 return std::min(
183 distortion_factor / absl::GetFlag(FLAGS_max_expected_distortion), 1.0);
milind-uf5b3b4b2023-02-26 14:50:38 -0800184}
185
Jim Ostrowski5e2c5e62023-02-26 12:52:56 -0800186std::vector<cv::Point2f> AprilRoboticsDetector::MakeCornerVector(
187 const apriltag_detection_t *det) {
188 std::vector<cv::Point2f> corner_points;
189 corner_points.emplace_back(det->p[0][0], det->p[0][1]);
190 corner_points.emplace_back(det->p[1][0], det->p[1][1]);
191 corner_points.emplace_back(det->p[2][0], det->p[2][1]);
192 corner_points.emplace_back(det->p[3][0], det->p[3][1]);
193
194 return corner_points;
195}
196
milind-ude9045f2023-03-25 18:17:12 -0700197void AprilRoboticsDetector::DestroyPose(apriltag_pose_t *pose) const {
198 matd_destroy(pose->R);
199 matd_destroy(pose->t);
200}
201
milind-u99b1a762023-03-12 16:48:32 -0700202AprilRoboticsDetector::DetectionResult AprilRoboticsDetector::DetectTags(
milind-ufc8ab702023-02-26 14:14:39 -0800203 cv::Mat image, aos::monotonic_clock::time_point eof) {
Jim Ostrowski49be8232023-03-23 01:00:14 -0700204 cv::Mat color_image;
205 cvtColor(image, color_image, cv::COLOR_GRAY2RGB);
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800206 const aos::monotonic_clock::time_point start_time =
207 aos::monotonic_clock::now();
208
209 image_u8_t im = {
milind-u09fb1252023-01-28 19:21:41 -0800210 .width = image.cols,
211 .height = image.rows,
212 .stride = image.cols,
213 .buf = image.data,
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800214 };
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700215 const uint32_t min_x = absl::GetFlag(FLAGS_pixel_border);
216 const uint32_t max_x = image.cols - absl::GetFlag(FLAGS_pixel_border);
217 const uint32_t min_y = absl::GetFlag(FLAGS_pixel_border);
218 const uint32_t max_y = image.rows - absl::GetFlag(FLAGS_pixel_border);
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800219
220 ftrace_.FormatMessage("Starting detect\n");
221 zarray_t *detections = apriltag_detector_detect(tag_detector_, &im);
222 ftrace_.FormatMessage("Done detecting\n");
223
milind-ufc8ab702023-02-26 14:14:39 -0800224 std::vector<Detection> results;
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800225
milind-u7aa29e22023-02-23 20:22:01 -0800226 auto builder = image_annotations_sender_.MakeBuilder();
Jim Ostrowski5e2c5e62023-02-26 12:52:56 -0800227 std::vector<flatbuffers::Offset<foxglove::PointsAnnotation>> foxglove_corners;
Yash Chainani728ae222023-02-04 19:48:12 -0800228
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800229 for (int i = 0; i < zarray_size(detections); i++) {
230 apriltag_detection_t *det;
231 zarray_get(detections, i, &det);
232
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700233 if (det->decision_margin > absl::GetFlag(FLAGS_min_decision_margin)) {
Jim Ostrowski437b1fb2023-02-26 10:12:01 -0800234 if (det->p[0][0] < min_x || det->p[0][0] > max_x ||
235 det->p[1][0] < min_x || det->p[1][0] > max_x ||
236 det->p[2][0] < min_x || det->p[2][0] > max_x ||
Jim Ostrowski0197d6b2023-03-04 12:41:13 -0800237 det->p[3][0] < min_x || det->p[3][0] > max_x ||
238 det->p[0][1] < min_y || det->p[0][1] > max_y ||
239 det->p[1][1] < min_y || det->p[1][1] > max_y ||
240 det->p[2][1] < min_y || det->p[2][1] > max_y ||
241 det->p[3][1] < min_y || det->p[3][1] > max_y) {
Jim Ostrowski437b1fb2023-02-26 10:12:01 -0800242 VLOG(1) << "Rejecting detection because corner is outside pixel border";
Jim Ostrowski5e2c5e62023-02-26 12:52:56 -0800243 // Send rejected corner points in red
244 std::vector<cv::Point2f> rejected_corner_points = MakeCornerVector(det);
245 foxglove_corners.push_back(frc971::vision::BuildPointsAnnotation(
246 builder.fbb(), eof, rejected_corner_points,
247 std::vector<double>{1.0, 0.0, 0.0, 0.5}));
Jim Ostrowski437b1fb2023-02-26 10:12:01 -0800248 continue;
249 }
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800250 VLOG(1) << "Found tag number " << det->id << " hamming: " << det->hamming
251 << " margin: " << det->decision_margin;
252
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800253 // First create an apriltag_detection_info_t struct using your known
254 // parameters.
255 apriltag_detection_info_t info;
256 info.det = det;
257 info.tagsize = 0.1524;
milind-uf2a4e322023-02-01 19:33:10 -0800258
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800259 info.fx = intrinsics_.at<double>(0, 0);
260 info.fy = intrinsics_.at<double>(1, 1);
261 info.cx = intrinsics_.at<double>(0, 2);
262 info.cy = intrinsics_.at<double>(1, 2);
263
Jim Ostrowski5e2c5e62023-02-26 12:52:56 -0800264 // Send original corner points in green
265 std::vector<cv::Point2f> orig_corner_points = MakeCornerVector(det);
266 foxglove_corners.push_back(frc971::vision::BuildPointsAnnotation(
267 builder.fbb(), eof, orig_corner_points,
268 std::vector<double>{0.0, 1.0, 0.0, 0.5}));
Jim Ostrowskid2b5c912023-02-26 00:59:35 -0800269
milind-ueccac3c2023-02-25 20:54:47 -0800270 UndistortDetection(det);
271
milind-uf5b3b4b2023-02-26 14:50:38 -0800272 const aos::monotonic_clock::time_point before_pose_estimation =
273 aos::monotonic_clock::now();
274
milind-ude9045f2023-03-25 18:17:12 -0700275 apriltag_pose_t pose_1;
276 apriltag_pose_t pose_2;
277 double pose_error_1;
278 double pose_error_2;
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700279 estimate_tag_pose_orthogonal_iteration(
280 &info, &pose_error_1, &pose_1, &pose_error_2, &pose_2,
281 absl::GetFlag(FLAGS_pose_estimation_iterations));
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800282
283 const aos::monotonic_clock::time_point after_pose_estimation =
284 aos::monotonic_clock::now();
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800285 VLOG(1) << "Took "
Austin Schuhd2667932023-02-04 16:22:39 -0800286 << chrono::duration<double>(after_pose_estimation -
287 before_pose_estimation)
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800288 .count()
289 << " seconds for pose estimation";
milind-ude9045f2023-03-25 18:17:12 -0700290 VLOG(1) << "Pose err 1: " << pose_error_1;
291 VLOG(1) << "Pose err 2: " << pose_error_2;
Yash Chainani728ae222023-02-04 19:48:12 -0800292
Jim Ostrowski5e2c5e62023-02-26 12:52:56 -0800293 // Send undistorted corner points in pink
294 std::vector<cv::Point2f> corner_points = MakeCornerVector(det);
295 foxglove_corners.push_back(frc971::vision::BuildPointsAnnotation(
296 builder.fbb(), eof, corner_points,
297 std::vector<double>{1.0, 0.75, 0.8, 1.0}));
milind-uf5b3b4b2023-02-26 14:50:38 -0800298
299 double distortion_factor =
300 ComputeDistortionFactor(orig_corner_points, corner_points);
301
milind-ude9045f2023-03-25 18:17:12 -0700302 // We get two estimates for poses.
303 // Choose the one with the lower estimation error
304 bool use_pose_1 = (pose_error_1 < pose_error_2);
305 auto best_pose = (use_pose_1 ? pose_1 : pose_2);
306 auto secondary_pose = (use_pose_1 ? pose_2 : pose_1);
307 double best_pose_error = (use_pose_1 ? pose_error_1 : pose_error_2);
308 double secondary_pose_error = (use_pose_1 ? pose_error_2 : pose_error_1);
309
310 CHECK_NE(best_pose_error, std::numeric_limits<double>::infinity())
311 << "Got no valid pose estimations, this should not be possible.";
312 double pose_error_ratio = best_pose_error / secondary_pose_error;
313
314 // Destroy the secondary pose if we got one
315 if (secondary_pose_error != std::numeric_limits<double>::infinity()) {
316 DestroyPose(&secondary_pose);
317 }
318
milind-uf5b3b4b2023-02-26 14:50:38 -0800319 results.emplace_back(Detection{.det = *det,
milind-ude9045f2023-03-25 18:17:12 -0700320 .pose = best_pose,
321 .pose_error = best_pose_error,
322 .distortion_factor = distortion_factor,
323 .pose_error_ratio = pose_error_ratio});
324
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700325 if (absl::GetFlag(FLAGS_visualize)) {
Jim Ostrowski49be8232023-03-23 01:00:14 -0700326 // Draw raw (distorted) corner points in green
327 cv::line(color_image, orig_corner_points[0], orig_corner_points[1],
328 cv::Scalar(0, 255, 0), 2);
329 cv::line(color_image, orig_corner_points[1], orig_corner_points[2],
330 cv::Scalar(0, 255, 0), 2);
331 cv::line(color_image, orig_corner_points[2], orig_corner_points[3],
332 cv::Scalar(0, 255, 0), 2);
333 cv::line(color_image, orig_corner_points[3], orig_corner_points[0],
334 cv::Scalar(0, 255, 0), 2);
335
336 // Draw undistorted corner points in red
337 cv::line(color_image, corner_points[0], corner_points[1],
338 cv::Scalar(0, 0, 255), 2);
339 cv::line(color_image, corner_points[2], corner_points[1],
340 cv::Scalar(0, 0, 255), 2);
341 cv::line(color_image, corner_points[2], corner_points[3],
342 cv::Scalar(0, 0, 255), 2);
343 cv::line(color_image, corner_points[0], corner_points[3],
344 cv::Scalar(0, 0, 255), 2);
345 }
346
347 VLOG(1) << "Found tag number " << det->id << " hamming: " << det->hamming
348 << " margin: " << det->decision_margin;
349
milind-u99b1a762023-03-12 16:48:32 -0700350 } else {
351 rejections_++;
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800352 }
353 }
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700354 if (absl::GetFlag(FLAGS_visualize)) {
Jim Ostrowski49be8232023-03-23 01:00:14 -0700355 // Display the result
356 // Rotate by 180 degrees to make it upright
milind-ua30a4a12023-03-24 20:49:41 -0700357 if (flip_image_) {
358 cv::rotate(color_image, color_image, 1);
359 }
360 cv::imshow(absl::StrCat("AprilRoboticsDetector Image ", node_name_),
361 color_image);
Jim Ostrowski49be8232023-03-23 01:00:14 -0700362 }
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800363
Jim Ostrowski5e2c5e62023-02-26 12:52:56 -0800364 const auto corners_offset = builder.fbb()->CreateVector(foxglove_corners);
Yash Chainani10b7b022023-02-22 14:34:04 -0800365 foxglove::ImageAnnotations::Builder annotation_builder(*builder.fbb());
Jim Ostrowski5e2c5e62023-02-26 12:52:56 -0800366 annotation_builder.add_points(corners_offset);
367 builder.CheckOk(builder.Send(annotation_builder.Finish()));
Yash Chainani728ae222023-02-04 19:48:12 -0800368
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800369 apriltag_detections_destroy(detections);
370
371 const aos::monotonic_clock::time_point end_time = aos::monotonic_clock::now();
372
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700373 if (absl::GetFlag(FLAGS_debug)) {
milind-uf3ab8ba2023-02-04 17:56:16 -0800374 timeprofile_display(tag_detector_->tp);
375 }
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800376
Austin Schuhd2667932023-02-04 16:22:39 -0800377 VLOG(1) << "Took " << chrono::duration<double>(end_time - start_time).count()
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800378 << " seconds to detect overall";
379
milind-u99b1a762023-03-12 16:48:32 -0700380 return {.detections = results, .rejections = rejections_};
Maxwell Hendersonfebee252023-01-28 16:53:52 -0800381}
382
Stephan Pleinesf63bde82024-01-13 15:59:33 -0800383} // namespace y2023::vision