36 const std::vector<PhotonTrackedTarget>& visTags,
37 const frc::AprilTagFieldLayout& layout) {
38 std::vector<frc::AprilTag> retVal{};
39 for (
const auto& tag : visTags) {
40 int id = tag.GetFiducialId();
41 auto maybePose = layout.GetTagPose(
id);
43 retVal.emplace_back(frc::AprilTag{id, maybePose.value()});
52 const Eigen::Matrix<double, 3, 3>& cameraMatrix,
53 const Eigen::Matrix<double, 8, 1>& distCoeffs,
54 const std::vector<PhotonTrackedTarget>& visTags,
55 const frc::AprilTagFieldLayout& layout,
const TargetModel& tagModel) {
56 if (visTags.size() == 0) {
60 std::vector<photon::TargetCorner> corners{};
61 std::vector<frc::AprilTag> knownTags{};
63 for (
const auto& tgt : visTags) {
64 int id = tgt.GetFiducialId();
65 auto maybePose = layout.GetTagPose(
id);
67 knownTags.emplace_back(frc::AprilTag{id, maybePose.value()});
68 auto currentCorners = tgt.GetDetectedCorners();
69 corners.insert(corners.end(), currentCorners.begin(),
70 currentCorners.end());
73 if (knownTags.size() == 0 || corners.size() == 0 || corners.size() % 4 != 0) {
79 if (knownTags.size() == 1) {
85 frc::Pose3d bestPose =
86 knownTags[0].pose.TransformBy(camToTag->best.Inverse());
87 frc::Pose3d altPose{};
88 if (camToTag->ambiguity != 0) {
89 altPose = knownTags[0].pose.TransformBy(camToTag->alt.Inverse());
93 result.
best = frc::Transform3d{o, bestPose};
94 result.alt = frc::Transform3d{o, altPose};
95 result.ambiguity = camToTag->ambiguity;
96 result.bestReprojErr = camToTag->bestReprojErr;
97 result.altReprojErr = camToTag->altReprojErr;
100 std::vector<frc::Translation3d> objectTrls{};
101 for (
const auto& tag : knownTags) {
103 objectTrls.insert(objectTrls.end(), verts.begin(), verts.end());
109 ret->best = ret->best.Inverse();
110 ret->alt = ret->alt.Inverse();