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

@@ -368,6 +368,15 @@ class PhotonCameraSim:
noisyTargetCorners,
)
# Compute object detection confidence if this is an obj det target
classId = tgt.objDetClassId
conf = tgt.objDetConf
if classId >= 0 and conf < 0:
# Simulate confidence using sqrt-scaled area for a more realistic
# curve. Raw areaPercent/100 is tiny for most targets; sqrt scaling
# gives reasonable values even for small-but-visible objects.
conf = max(0.0, min(1.0, math.sqrt(areaPercent / 100.0) * 2.0))
smallVec: list[TargetCorner] = []
for corner in minAreaRectPts:
smallVec.append(TargetCorner(corner[0], corner[1]))
@@ -381,6 +390,8 @@ class PhotonCameraSim:
area=areaPercent,
skew=math.degrees(centerRot.X()),
fiducialId=tgt.fiducialId,
objDetectId=classId,
objDetectConf=conf,
detectedCorners=cornersFloat,
minAreaRectCorners=smallVec,
bestCameraToTarget=pnpSim.best if pnpSim else Transform3d(),