Skip to content

How To Make an Applet

Samuel Audet edited this page Mar 15, 2015 · 1 revision

How to use JavaCV in an applet

Created May 28, 2012 by samuel.audet

Introduction

To produce an applet, such as the FaceApplet sample, or a standalone application in a JAR file, please follow the instructions found in the next section. (Please accept the warning dialog that pops up on the FaceApplet page. This is the excepted behavior with a self-signed applet. If you get an error, you may also have to lower the security level of your Java installation.)

If all goes well, after locating a camera on your system, the applet should start capturing images and detecting faces. Please note that the binaries were designed to run on Linux (x86 or x86_64), Mac OS X (x86_64 only), and Windows (x86 or x86_64) where an implementation of Java SE 6 or newer has been installed (OpenJDK, Sun JDK, IBM JDK, Java SE for Mac OS X, etc.)

The source code of this applet can be found in the distribution package or source repository of JavaCV inside the samples directory.

Details

The following instructions explain how to build the FaceApplet sample with JavaCV 0.10 and OpenCV 2.4.10. For more detailed explanations concerning applets in general, please refer to Lesson: Java Applets, part of The Java Tutorials.

  1. Download and extract the binary packages of JavaCV and OpenCV
  2. Inside the samples directory containing FaceApplet.java, unzip all the files found inside the JAR files javacpp.jar, javacv.jar, and opencv*.jar, for example:
```bash
$ jar xvf /path/to/javacpp.jar
$ jar xvf /path/to/javacv.jar
$ jar xvf /path/to/opencv.jar
$ jar xvf /path/to/opencv-linux-x86.jar
$ jar xvf /path/to/opencv-linux-x86_64.jar
$ jar xvf /path/to/opencv-macosx-x86_64.jar
$ jar xvf /path/to/opencv-windows-x86.jar
$ jar xvf /path/to/opencv-windows-x86_64.jar
```
  1. Copy haarcascade_frontalface_alt.xml from OpenCV into the same directory
  2. Compile FaceApplet.java, for example:
```bash
$ javac -source 1.6 -target 1.6 FaceApplet.java
```
  1. Create a text file named manifest.txt with the following content:
```bash
Permissions: all-permissions
Codebase: *
Application-Name: FaceApplet
```
  1. Create a new JAR file with manifest.txt, FaceApplet.class, haarcascade_frontalface_alt.xml, and all of the previously extracted files, for example:
```bash
$ jar cvfm FaceApplet.jar manifest.txt FaceApplet.class haarcascade_frontalface_alt.xml org/
```
  1. Finally, because JavaCV runs native code, we need to sign the JAR file with a certificate, for example:
```bash
$ jarsigner -keystore /path/to/<keystore> FaceApplet.jar <alias>
```

And we should then be able to run the applet with the provided FaceApplet.html and FaceApplet.jnlp files. JNLP offers a lot more flexibility than one might surmise from the instructions above, so please make sure to read up on Java applets to harness their full potential!