mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
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:
@@ -525,6 +525,16 @@ public class PhotonCameraSim implements AutoCloseable {
|
||||
.get();
|
||||
}
|
||||
|
||||
// If object detection (user classId valid) but conf wasn't provided, estimate
|
||||
int classId = tgt.objDetClassId;
|
||||
float conf = tgt.objDetConf;
|
||||
if (classId >= 0 && 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 = (float) MathUtil.clamp(Math.sqrt(areaPercent / 100.0) * 2.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
detectableTgts.add(
|
||||
new PhotonTrackedTarget(
|
||||
-Math.toDegrees(centerRot.getZ()),
|
||||
@@ -532,8 +542,8 @@ public class PhotonCameraSim implements AutoCloseable {
|
||||
areaPercent,
|
||||
Math.toDegrees(centerRot.getX()),
|
||||
tgt.fiducialID,
|
||||
-1,
|
||||
-1,
|
||||
classId,
|
||||
conf,
|
||||
pnpSim.best,
|
||||
pnpSim.alt,
|
||||
pnpSim.ambiguity,
|
||||
|
||||
@@ -36,16 +36,21 @@ public class VisionTargetSim {
|
||||
|
||||
public final int fiducialID;
|
||||
|
||||
/** The object detection class ID, or -1 if not applicable. */
|
||||
public final int objDetClassId;
|
||||
|
||||
/** The object detection confidence, or -1 if not applicable. */
|
||||
public final float objDetConf;
|
||||
|
||||
/**
|
||||
* Describes a vision target located somewhere on the field that your vision system can detect.
|
||||
* Describes a retro-reflective/colored shape vision target 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 geometry of the target
|
||||
*/
|
||||
public VisionTargetSim(Pose3d pose, TargetModel model) {
|
||||
this.pose = pose;
|
||||
this.model = model;
|
||||
this.fiducialID = -1;
|
||||
this(pose, model, -1, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,9 +61,33 @@ public class VisionTargetSim {
|
||||
* @param id The ID of this fiducial tag
|
||||
*/
|
||||
public VisionTargetSim(Pose3d pose, TargetModel model, int id) {
|
||||
this(pose, model, id, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes an object-detection vision target located somewhere on the field that your vision
|
||||
* system can detect. Class ID is the (zero-indexed) index of the object's class ID in the list of
|
||||
* all classes. Confidence can be specified, or pass -1 to estimate confidence based on 2 *
|
||||
* sqrt(target area / total image area)
|
||||
*
|
||||
* @param pose Pose3d of the target in field-relative coordinates
|
||||
* @param model TargetModel which describes the geometry of the target
|
||||
* @param objDetClassId The object detection class ID, if -1 it will not be detected by object
|
||||
* detection
|
||||
* @param objDetConf The object detection confidence, or -1 in which case the simulation will
|
||||
* compute a confidence based on the area of the target in the camera's field of view
|
||||
*/
|
||||
public VisionTargetSim(Pose3d pose, TargetModel model, int objDetClassId, float objDetConf) {
|
||||
this(pose, model, -1, objDetClassId, objDetConf);
|
||||
}
|
||||
|
||||
private VisionTargetSim(
|
||||
Pose3d pose, TargetModel model, int id, int objDetClassId, float objDetConf) {
|
||||
this.pose = pose;
|
||||
this.model = model;
|
||||
this.fiducialID = id;
|
||||
this.objDetClassId = objDetClassId;
|
||||
this.objDetConf = objDetConf;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +126,11 @@ public class VisionTargetSim {
|
||||
return model;
|
||||
}
|
||||
|
||||
/** This target's vertices offset from its field pose. */
|
||||
/**
|
||||
* This target's vertices offset from its field pose.
|
||||
*
|
||||
* @return A vector of Translation3d representing the vertices of the target
|
||||
*/
|
||||
public List<Translation3d> getFieldVertices() {
|
||||
return model.getFieldVertices(pose);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user