WPILibC++ 2024.3.2
AprilTagPoseEstimator.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <span>
8
9#include <units/length.h>
10#include <wpi/SymbolExports.h>
11
14
15namespace frc {
16
18
19/** Pose estimators for AprilTag tags. */
21 public:
22 /** Configuration for the pose estimator. */
23 struct Config {
24 bool operator==(const Config&) const = default;
25
26 /** The tag size. */
27 units::meter_t tagSize;
28
29 /** Camera horizontal focal length, in pixels. */
30 double fx;
31
32 /** Camera vertical focal length, in pixels. */
33 double fy;
34
35 /** Camera horizontal focal center, in pixels. */
36 double cx;
37
38 /** Camera vertical focal center, in pixels. */
39 double cy;
40 };
41
42 /**
43 * Creates estimator.
44 *
45 * @param config Configuration
46 */
47 explicit AprilTagPoseEstimator(const Config& config) : m_config{config} {}
48
49 /**
50 * Sets estimator configuration.
51 *
52 * @param config Configuration
53 */
54 void SetConfig(const Config& config) { m_config = config; }
55
56 /**
57 * Gets estimator configuration.
58 *
59 * @return Configuration
60 */
61 const Config& GetConfig() const { return m_config; }
62
63 /**
64 * Estimates the pose of the tag using the homography method described in [1].
65 *
66 * @param detection Tag detection
67 * @return Pose estimate
68 */
70
71 /**
72 * Estimates the pose of the tag using the homography method described in [1].
73 *
74 * @param homography Homography 3x3 matrix data
75 * @return Pose estimate
76 */
77 Transform3d EstimateHomography(std::span<const double, 9> homography) const;
78
79 /**
80 * Estimates the pose of the tag. This returns one or two possible poses for
81 * the tag, along with the object-space error of each.
82 *
83 * This uses the homography method described in [1] for the initial estimate.
84 * Then Orthogonal Iteration [2] is used to refine this estimate. Then [3] is
85 * used to find a potential second local minima and Orthogonal Iteration is
86 * used to refine this second estimate.
87 *
88 * [1]: E. Olson, “Apriltag: A robust and flexible visual fiducial system,” in
89 * 2011 IEEE International Conference on Robotics and Automation,
90 * May 2011, pp. 3400–3407.
91 * [2]: Lu, G. D. Hager and E. Mjolsness, "Fast and globally convergent pose
92 * estimation from video images," in IEEE Transactions on Pattern
93 * Analysis and Machine Intelligence, vol. 22, no. 6, pp. 610-622, June 2000.
94 * doi: 10.1109/34.862199
95 * [3]: Schweighofer and A. Pinz, "Robust Pose Estimation from a Planar
96 * Target," in IEEE Transactions on Pattern Analysis and Machine Intelligence,
97 * vol. 28, no. 12, pp. 2024-2030, Dec. 2006. doi: 10.1109/TPAMI.2006.252
98 *
99 * @param detection Tag detection
100 * @param nIters Number of iterations
101 * @return Initial and (possibly) second pose estimates
102 */
104 const AprilTagDetection& detection, int nIters) const;
105
106 /**
107 * Estimates the pose of the tag. This returns one or two possible poses for
108 * the tag, along with the object-space error of each.
109 *
110 * @param homography Homography 3x3 matrix data
111 * @param corners Corner point array (X and Y for each corner in order)
112 * @param nIters Number of iterations
113 * @return Initial and (possibly) second pose estimates
114 */
116 std::span<const double, 9> homography, std::span<const double, 8> corners,
117 int nIters) const;
118
119 /**
120 * Estimates tag pose. This method is an easier to use interface to
121 * EstimatePoseOrthogonalIteration(), running 50 iterations and returning the
122 * pose with the lower object-space error.
123 *
124 * @param detection Tag detection
125 * @return Pose estimate
126 */
127 Transform3d Estimate(const AprilTagDetection& detection) const;
128
129 /**
130 * Estimates tag pose. This method is an easier to use interface to
131 * EstimatePoseOrthogonalIteration(), running 50 iterations and returning the
132 * pose with the lower object-space error.
133 *
134 * @param homography Homography 3x3 matrix data
135 * @param corners Corner point array (X and Y for each corner in order)
136 * @return Pose estimate
137 */
138 Transform3d Estimate(std::span<const double, 9> homography,
139 std::span<const double, 8> corners) const;
140
141 private:
142 Config m_config;
143};
144
145} // namespace frc
#define WPILIB_DLLEXPORT
Definition: SymbolExports.h:36
A detection of an AprilTag tag.
Definition: AprilTagDetection.h:20
Pose estimators for AprilTag tags.
Definition: AprilTagPoseEstimator.h:20
Transform3d Estimate(const AprilTagDetection &detection) const
Estimates tag pose.
AprilTagPoseEstimator(const Config &config)
Creates estimator.
Definition: AprilTagPoseEstimator.h:47
Transform3d EstimateHomography(std::span< const double, 9 > homography) const
Estimates the pose of the tag using the homography method described in [1].
Transform3d EstimateHomography(const AprilTagDetection &detection) const
Estimates the pose of the tag using the homography method described in [1].
const Config & GetConfig() const
Gets estimator configuration.
Definition: AprilTagPoseEstimator.h:61
void SetConfig(const Config &config)
Sets estimator configuration.
Definition: AprilTagPoseEstimator.h:54
AprilTagPoseEstimate EstimateOrthogonalIteration(const AprilTagDetection &detection, int nIters) const
Estimates the pose of the tag.
Transform3d Estimate(std::span< const double, 9 > homography, std::span< const double, 8 > corners) const
Estimates tag pose.
AprilTagPoseEstimate EstimateOrthogonalIteration(std::span< const double, 9 > homography, std::span< const double, 8 > corners, int nIters) const
Estimates the pose of the tag.
Represents a transformation for a Pose3d in the pose's frame.
Definition: Transform3d.h:18
Definition: AprilTagPoseEstimator.h:15
A pair of AprilTag pose estimates.
Definition: AprilTagPoseEstimate.h:14
Configuration for the pose estimator.
Definition: AprilTagPoseEstimator.h:23
bool operator==(const Config &) const =default
double cy
Camera vertical focal center, in pixels.
Definition: AprilTagPoseEstimator.h:39
double cx
Camera horizontal focal center, in pixels.
Definition: AprilTagPoseEstimator.h:36
units::meter_t tagSize
The tag size.
Definition: AprilTagPoseEstimator.h:27
double fx
Camera horizontal focal length, in pixels.
Definition: AprilTagPoseEstimator.h:30
double fy
Camera vertical focal length, in pixels.
Definition: AprilTagPoseEstimator.h:33