From 3cbae2b118bd2141bc541b9d3e2525acaea79fc7 Mon Sep 17 00:00:00 2001 From: FTC Engineering Date: Tue, 27 Oct 2020 12:35:20 -0400 Subject: [PATCH] Updated Java Sample TensorFlow Object Detection Op Mode (markdown) --- ...ple-TensorFlow-Object-Detection-Op-Mode.md | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/Java-Sample-TensorFlow-Object-Detection-Op-Mode.md b/Java-Sample-TensorFlow-Object-Detection-Op-Mode.md index d0c2248..8740825 100644 --- a/Java-Sample-TensorFlow-Object-Detection-Op-Mode.md +++ b/Java-Sample-TensorFlow-Object-Detection-Op-Mode.md @@ -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. ``` + if (opModeIsActive()) { + while (opModeIsActive()) { + if (tfod != null) { // getUpdatedRecognitions() will return null if no new information is available since // the last time that call was made. List updatedRecognitions = tfod.getUpdatedRecognitions(); if (updatedRecognitions != null) { 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()); + + // check label to see which target zone to go after. + 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"); + } + } + } - // 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()); - - // 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(); - } 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.