This is a toy project for testing OpenCV classifiers and face recognition.
It works with OpenCV 3.1 and Java and looks like this:
The application has a Swing GUI and uses OpenCV for capturing the webcam stream; the face detection/recognition is completely decoupled from the GUI because I need to use these classes for a GUIless application on a raspberry.
To test face recognition, you have to choose menu Face Recognition -> Capture new user and take at least 20 photos; then you have to press the "Save images" button adding a USERNAME in the input text and the application will save the images to file system (in the java.io.tmpdir
dir where the filename has the format USERNAME_N.jpg); now you have to close the application, copy the images to the /src/main/resources/faces
directory and restart the application (sooner or later I'll fix this behaviuor).
Now you can choose Face Recognition -> Start recognition to see face recognition in action.
OpenCV supports three different recognizers that you can choose from the menu Face Recognition -> recognizers.
In package org/opencv/demo/gui/swing/standalone there are a couple of classes that can be used as standalone classes to show how works face detection and recognition.
For installing OpenCV with Java on Ubuntu, I've followed this tutorial: http://milq.github.io/install-opencv-ubuntu-debian/ ; if you're using Mac or Windows, I'm sure it's plenty of tutorial on how to do that.
Please note that when you have to download the archive from github repository, you first have to choose the 3.1.0
tag (the download link is https://github.com/Itseez/opencv/archive/3.1.0.zip).
To enable Face Recognition, you need to:
- download the 3.1 version of the opencv_contrib: https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
- extract the archive
- open file opencv_contrib-3.1.0/modules/face/CMakeLists.txt
- append "java" to the WRAP section, so that it reads:
ocv_define_module(face opencv_core opencv_imgproc opencv_objdetect WRAP python java)
- add the switch
-D OPENCV_EXTRA_MODULES_PATH=$YOUR_OPENCV_CONTRIB_PATH/opencv_contrib-3.1.0/modules
to the compile command showed in the installation tutorial linked above - once compiled, you'll find the
opencv-310.jar
in thebuild/bin
directory: set that JAR as a library for the Java project