Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
Tutorial: AprilTag detection in java with ViSP

Introduction

We assume that you have already followed the previous tutorial Tutorial: First java application with ViSP. It could be also useful to follow Tutorial: AprilTag marker detection to get an overview on AprilTag detection in ViSP.

In this tutorial, you will see how to develop an application that allows to load an image and run AprilTag detection in java using ViSP library in Eclipse.

Create a new project

To create the project corresponding to this tutorial:

  • Open Eclipse and create a new Java project entering "File > New > Java Project" menu.
img-tutorial-java-eclipse-create-new-project.jpeg
  • In the "New Java Project" dialog write the name of your project (let say visp-java-apriltag). In JRE section, select the appropriate execution environment (JavaSE-17 if you install JDK 17, or JavaSE-15 if you install JDK 15 or JavaSE-11 if you install JDK 11). Then press "Finish" button.
img-java-apriltag-project.jpg
  • In the "New module-info.java" dialog that may appear, press "Don't Create" button.
img-tutorial-java-eclipse-dont-create.jpeg

Add a user library

If you followed Tutorial: Installing ViSP for Java, you should already have ViSP library set in your workspace as a user library; if not please check out Tutorial: Installing ViSP for Java. Now you should be ready to add ViSP library to your project.

  • Inside Eclipse’s Package Explorer just right-click on your project’s folder and go to "Build Path > Add Libraries...".
img-java-apriltag-import-user-library.jpg
  • Select "User Library" and click on "Next":
img-tutorial-java-eclipse-add-libraries2.jpeg
  • Check the checkbox of the ViSP library and press "Finish" button.
img-tutorial-java-eclipse-add-libraries3.jpeg

Import AprilTag application java code

  • Now import AprilTagDetection.java file in your project, pointing your mouse on src folder and with a right click entering "Import" menu.
img-java-apriltag-import.jpg
  • Select "General > File System" and press "Next" button.
img-java-apriltag-import-file.jpg
  • Browse to $VISP_WS/visp/tutorial/java/tag-detection folder, enable tag-detection check box and press "Finish" button.
img-java-apriltag-import-file-apriltag.jpg
  • Now expanding what's behind src you should see something similar to:
img-java-apriltag-project-complete.jpg

Run AprilTag detection application

We can now run this application entering"Run > Run" menu.

  • Here you should see the application appearing:
img-java-apriltag-app-empty.png

Install ViSP data set, press "Open" button, browse to $ViSP_WS/visp-images/AprilTag/benchmark/640x480 folder and select tag36_11_640x480.png image.

img-java-apriltag-app-open-image.png
  • Now press "Detect" button to run AprilTag detection and pose computation over the image.
img-java-apriltag-app-detect.png

This application allows to modify some settings:

  • using "Set tag size" button you can specify for each tag Id its size. Default size is set to 0.053 meter. For example to modify the size of tags with Id 0 to 0.1 meter, press "Set tag size" to make appear a new window in which you have to press "Add size" button to enter Tag Id 0 and the corresponding size 0.1. Then press "Validate" button.
    img-java-apriltag-app-tag-size.png
  • camera parameters which are set by default to px = py = 615.168 and u0 = 312.189, v0 = 243.437
  • tag format (default tag is 36h11)
  • pose estimation algorithm (default is homography).

To see estimated tag poses values press "Show estimated poses" button.

Just try it...

Known issues

Next tutorial

You are now ready to continue with Tutorial: Generic model-based tracking in java with ViSP.