Populate classId and confidence level for object detection in Java simulation (#2372)

## Description

compute confidence level based on target area in total image size and
populate classId and confidence level in Java (while building the
PhotonTrackedTarget)

## Changes
- Add new VisionTargetSim constructor for object detection
- If class ID specified but confidence = -1, estimate based on total
area

---------

Co-authored-by: Matt Morley <matthew.morley.ca@gmail.com>
This commit is contained in:
Stéphane Dalton
2026-03-18 23:42:37 -04:00
committed by GitHub
parent 846528ce9c
commit 12446a6c44
9 changed files with 321 additions and 30 deletions

View File

@@ -1,4 +1,5 @@
import math
from typing import overload
from wpimath.geometry import Pose3d, Translation3d
@@ -8,19 +9,78 @@ from ..estimation.targetModel import TargetModel
class VisionTargetSim:
"""Describes a vision target located somewhere on the field that your vision system can detect."""
def __init__(self, pose: Pose3d, model: TargetModel, id: int = -1):
"""Describes a fiducial tag located somewhere on the field that your vision system can detect.
@overload
def __init__(self, pose: Pose3d, model: TargetModel) -> None:
"""
Describes a retro-reflective/colored shape vision target located somewhere on the field that
your vision system can detect.
:param pose: Pose3d of the target in field-relative coordinates
:param model: TargetModel which describes the shape of the target
"""
...
@overload
def __init__(self, pose: Pose3d, model: TargetModel, id: int) -> None:
"""
Describes a fiducial tag located somewhere on the field that your vision system can detect.
:param pose: Pose3d of the tag in field-relative coordinates
:param model: TargetModel which describes the shape of the target(tag)
:param model: TargetModel which describes the geometry of the target (tag)
:param id: The ID of this fiducial tag
"""
...
@overload
def __init__(
self, pose: Pose3d, model: TargetModel, objDetClassId: int, objDetConf: float
) -> None:
"""
Describes an object-detection vision target located somewhere on the field that your vision
system can detect.
:param pose: Pose3d of the target in field-relative coordinates
:param model: TargetModel which describes the shape of the target
:param objDetClassId: The object detection class ID, or -1 to exclude from object detection
:param objDetConf: The object detection confidence, or -1.0 to compute from target area
in the camera's field of view
"""
...
def __init__(
self,
pose: Pose3d,
model: TargetModel,
*args,
**kwargs,
):
if kwargs:
raise TypeError(
f"VisionTargetSim does not accept keyword arguments: {list(kwargs.keys())}"
)
self.pose: Pose3d = pose
self.model: TargetModel = model
self.fiducialId: int = id
self.objDetClassId: int = -1
self.objDetConf: float = -1.0
if len(args) == 0:
# VisionTargetSim(pose, model)
self.fiducialId: int = -1
self.objDetClassId: int = -1
self.objDetConf: float = -1.0
elif len(args) == 1:
# VisionTargetSim(pose, model, id)
self.fiducialId = args[0]
self.objDetClassId = -1
self.objDetConf = -1.0
elif len(args) == 2:
# VisionTargetSim(pose, model, objDetClassId, objDetConf)
self.fiducialId = -1
self.objDetClassId = args[0]
self.objDetConf = args[1]
else:
raise ValueError(
f"VisionTargetSim takes 2-4 arguments, got {2 + len(args)}"
)
def __lt__(self, right) -> bool:
return self.pose.translation().norm() < right.pose.translation().norm()