Updated Java Sample TensorFlow Object Detection Op Mode (markdown)

FTC Engineering
2020-10-27 12:35:20 -04:00
parent 0d3f39ec2d
commit 3cbae2b118

@ -190,12 +190,20 @@ If the list is not empty, then the op mode iterates through the list and calls a
Let's modify the sample Blocks Op Mode so it will indicate which target zone the robot should drive to. Using the Blocks editor, add a conditional clause for an empty list (i.e., no targets detected) so that a telemetry message indicating that zone A should be targeted by the robot. Let's modify the sample Blocks Op Mode so it will indicate which target zone the robot should drive to. Using the Blocks editor, add a conditional clause for an empty list (i.e., no targets detected) so that a telemetry message indicating that zone A should be targeted by the robot.
``` ```
if (opModeIsActive()) {
while (opModeIsActive()) {
if (tfod != null) {
// getUpdatedRecognitions() will return null if no new information is available since // getUpdatedRecognitions() will return null if no new information is available since
// the last time that call was made. // the last time that call was made.
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions(); List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
if (updatedRecognitions != null) { if (updatedRecognitions != null) {
telemetry.addData("# Object Detected", updatedRecognitions.size()); telemetry.addData("# Object Detected", updatedRecognitions.size());
if (updatedRecognitions.size() == 0 ) {
// empty list. no objects recognized.
telemetry.addData("TFOD", "No items detected.");
telemetry.addData("Target Zone", "A");
} else {
// list is not empty.
// step through the list of recognitions and display boundary info. // step through the list of recognitions and display boundary info.
int i = 0; int i = 0;
for (Recognition recognition : updatedRecognitions) { for (Recognition recognition : updatedRecognitions) {
@ -205,21 +213,21 @@ Let's modify the sample Blocks Op Mode so it will indicate which target zone the
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f", telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f",
recognition.getRight(), recognition.getBottom()); recognition.getRight(), recognition.getBottom());
// display target zone based on this object. // check label to see which target zone to go after.
if (recognition.getLabel().equals("Single")) { if (recognition.getLabel().equals("Single")) {
telemetry.addData("Target Zone", "B"); telemetry.addData("Target Zone", "B");
} else if ((recognition.getLabel().equals("Quad"))) { } else if (recognition.getLabel().equals("Quad")) {
telemetry.addData("Target Zone", "C"); telemetry.addData("Target Zone", "C");
} else { } else {
telemetry.addData("Target Zone", "UNKNOWN"); telemetry.addData("Target Zone", "UNKNOWN");
} }
} }
}
telemetry.update(); telemetry.update();
} else { }
// updatedRecognitions is null (no objects recognized). }
telemetry.addData("TFOD", "No items detected."); }
telemetry.addData("Target Zone", "A");
telemetry.update();
} }
``` ```