OnBot Java (OBJ)
This Tutorial is outdated due to the TensorFlow updates for the VisionPortal. We are working on updating this tutorial, please bear with us as we update it. For more information on TensorFlow for Java, see the VisionPortal TensorFlow Processor Initialization.
It is assumed that you already know how to use OnBot Java. If not, be sure to check out the OnBot Java Guide document before proceeding.
In On Bot Java, there are three sample Opmodes to choose from. Each has its own use case. Depending on your use case choose one (or more) of the following.
This opmode is designed to use the robot controller’s internal camera, if it has one, for the input for TFOD.
This opmode is designed to be able to switch between two different webcams for the input for TFOD.
This opmode is designed to use an external webcam as its input for TFOD
Click the “Add Files” button in the top left corner.
In the bottom half of the popup click the drop down below “Sample”. Then select the opmode that you chose earlier in Step 1. Then in the “File Name” text box enter the desired name of your opmode. Then click the blue “OK” button.
The next step is to upload the TFOD model that you created using FTC-ML. To do this go to the ribbon on the top of your windows and select “Manage”.
If you’re using SDK 7.0 or older, select the “Upload TensorFlow Lite Model File” button and select the model (.tflite). Then click upload.
If you’re using SDK 7.1 and newer, in the same location you’ll find a TensorFlow Lite Model File Manager link. Click on that link to take you to the model file manager, and upload your model. Here you can also view other models already uploaded, rename, and delete models.
Then navigate back to the “OnBotJava” page. You will now have to modify the name of the model that the opmode uses. To do this change the
TFOD_MODEL_ASSETvariable such that
“FreightFrenzy_BCDM.tflite”is replaced with the name and fully qualified path for the file that you uploaded earlier. The fully qualified path to where the tflite models live can be seen in the example below:
private static final String TFOD_MODEL_ASSET =
On some older models of phones, the upload path may be
different. On some phones, like the Motorola G2 phone, the model
path should instead be set to
private static final String TFOD_MODEL_ASSET = "/storage/emulated/0/FIRST/tflitemodels/myCustomFreightFrenzyModel.tflite";
Change from “loadModelFromAsset” to “loadModelFromFile” in the line below in your opmode.
Modify the labels of the model such that it matches those of your model. You need at least one label. The order should be alphabetical and be composed of the labels in the datset(s) used to make the model.
You will now need to acquire a Vuforia License Key. To do this follow the instructions provided in the opmode. They will be found above the line shown below. The final step will be to replace
" -- YOUR NEW VUFORIA KEY GOES HERE --- "with your actual key.
(optional) You may find it necessary to adjust the zoom. By default it is set to 2.5 but feel free to adjust this to your needs. Note that this is digital zoom not optical zoom. This means that in essence you are simply telling TFOD to ignore outer sections of the image.
If you are using
ConceptTensorFlowObjectDetectionSwitchableCamerasyou will also need to update the device name of the camera. Simply change the device name to correspond with your config. In the image below the name of the webcam is
And you are all set to test. After clicking the build button just open the opmode as you would any other opmode and select initialize and play. Have fun testing.