Updated Java Sample TensorFlow Object Detection Op Mode (markdown)

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

@ -190,37 +190,45 @@ 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.
int i = 0;
for (Recognition recognition : updatedRecognitions) {
telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
telemetry.addData(String.format(" left,top (%d)", i), "%.03f , %.03f",
recognition.getLeft(), recognition.getTop());
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f",
recognition.getRight(), recognition.getBottom());
// step through the list of recognitions and display boundary info. // check label to see which target zone to go after.
int i = 0; if (recognition.getLabel().equals("Single")) {
for (Recognition recognition : updatedRecognitions) { telemetry.addData("Target Zone", "B");
telemetry.addData(String.format("label (%d)", i), recognition.getLabel()); } else if (recognition.getLabel().equals("Quad")) {
telemetry.addData(String.format(" left,top (%d)", i), "%.03f , %.03f", telemetry.addData("Target Zone", "C");
recognition.getLeft(), recognition.getTop()); } else {
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f", telemetry.addData("Target Zone", "UNKNOWN");
recognition.getRight(), recognition.getBottom()); }
}
// display target zone based on this object.
if(recognition.getLabel().equals("Single")) {
telemetry.addData("Target Zone", "B");
} else if ((recognition.getLabel().equals("Quad"))) {
telemetry.addData("Target Zone", "C");
} else {
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();
} }
}
}
}
``` ```
Also, when an object is detected, check its label to see which target zone is associated with that object. If the label reads "Single" then send a telemetry message to indicate target zone B. If the label reads "Quad" then send a telemetry message to indicate target zone C. If the label is neither "Single" or "Quad" send a telemetry message indicating that the target zone is unknown. Also, when an object is detected, check its label to see which target zone is associated with that object. If the label reads "Single" then send a telemetry message to indicate target zone B. If the label reads "Quad" then send a telemetry message to indicate target zone C. If the label is neither "Single" or "Quad" send a telemetry message indicating that the target zone is unknown.