Skip to content

Apriltag ml experimental#2

Open
DoctorFogarty wants to merge 50 commits intomainfrom
apriltag-ml-experimental
Open

Apriltag ml experimental#2
DoctorFogarty wants to merge 50 commits intomainfrom
apriltag-ml-experimental

Conversation

@DoctorFogarty
Copy link
Owner

Added AI Assisted April Tag Detection

Includes Homography Transforms

Includes an experimental method for scaling the ROI so performance doesn't drop like a rock when the tag is in near vs far field frame of the camera.

Tries to keep reference frame correct to full frame image

Merge checklist:

  • Pull Request title is short, imperative summary of proposed changes
  • The description documents the what and why
  • If this PR changes behavior or adds a feature, user documentation is updated
  • If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly
  • If this PR touches configuration, this is backwards compatible with settings back to v2025.3.2
  • If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated
  • If this PR addresses a bug, a regression test for it is added

DoctorFogarty and others added 30 commits January 18, 2026 19:11
Setup Basic Tests
Included Roboflow model
tflite yolov8n trained
*
* @return Optional containing the AprilTag model if found
*/
public Optional<Model> getDefaultAprilTagModel() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this ok? this seems potentially cursed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifically looking for "apriltag". Would this cause issues if an object detection model with "apriltag" (dumb, but you know...) in the name was used?

Would it be better to use getModelByName and specify the name? I assume that's how object ones work

v-model="currentPipelineSettings.atrCornerRefinementEnabled"
:switch-cols="interactiveCols"
label="ATR Corner Refinement"
tooltip="Enables adaptive tag resizing corner refinement for improved accuracy when tags are scaled"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More like "... for improved speed when ML detected tags are large"?

v-model="currentPipelineSettings.mlRoiExpansionFactor"
:slider-cols="interactiveCols"
label="ROI Expansion"
tooltip="Factor to expand detected regions for traditional decoding (1.0-2.0). Larger values help with edge cases"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"... at the cost of speed"? Maybe no room for that and maybe it's obvious

:disabled="isTagPipeline"
<pv-slider
v-model="useCameraSettingsStore().currentPipelineSettings.outputMaximumTargets"
label="Maximum Targets"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Maximum ML-detected Tags" is more clear maybe. obviously this was copy-pasted from object detection where more general language is needed

v-model="currentPipelineSettings.mlNmsThreshold"
:slider-cols="interactiveCols"
label="NMS Threshold"
tooltip="Non-maximum suppression threshold for overlapping detections (0-1)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have no idea what this is. just leaving a comment here, no suggested fix rn

targetModel: TargetModel.InfiniteRechargeHighGoalOuter,
ledMode: true,
outputShowMultipleTargets: false,
outputMaximumTargets: 20,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gonna suggest this goes to 127, but maybe the PV/Wave stuff already addresses this

}

// === STAGE 4: POSE ESTIMATION happens in AprilTagPoseEstimatorPipe ===
return deduplicateByTagId(allDetections);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not check this on line R232? Then, if the detection in the second duplicate ROI is worse than the first one, you skip doing STAGE3 FINE REFINEMENT .

int tagId = det.getId();
AprilTagDetection existing = bestByTagId.get(tagId);

if (existing == null || det.getDecisionMargin() > existing.getDecisionMargin()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably accept the one with minimum Hamming distance before looking at DecisionMargin, in case the minimum Hamming setting is larger than 0.

getDecisionMargin is a good measure of accuracy only for very small tags.
https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/apriltag/AprilTagDetection.html#getDecisionMargin()

To be fair, there is no obvious better way to get a fast estimate of quality as far as I can tell. Given that this is operating on the same image, the quality is likely the same unless the corners of the real tag are eclipsed by the ROI.

* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably shouldn't be removed?


pipe.release();
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine but i didn't manually verify that any of these are right. The tests are useful as far as i can tell


pipeline.release();
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good, didn't manually review tests, just descriptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants