An implementation in java of the viola jones algorithm using a trained classifier
This requires
- Java
- Set your Java JDK to 1.8
- Using an IDE is recommended due to the complexity of configuring openCV
- IntelliJ IDEA, Download
- OpenCV 3.1, Download
- A compiled mac jar is provided here
lib/openCV/mac/opencv-310.jar
- You need to configure openCV 3.1 and add it to to the project class path.
- Configuration steps for Mac OS X can be found here
- After 'make' has successfully executed, navigate to that directory and locate the 'lib' folder
- Find 'libopencv_java310.os' and change this file extension to '.dylib'
- Add 'opencv-301.jar' to your build path. This jar file can be found in lib/openCV/mac/ in this repo
- Configure the module library to add the lib folder of the openCV you just compiled
- A compiled mac jar is provided here
- Java-json (included in repo)
- locate 'java-json.jar' and add it to your build path
There are two parts to the face detection
this can be done by
- Calling CascadeClassifier.train() test. This implementation does not yield good results
- PREFERRED Using the python trainer here (same creators)
- The python face detection on single image
- PREFERRED Using java MainUI.main() which gives you the following functionalities
Calculate Integral Image and display it
- Create 100 feature vectors from 100 images stored in
res/baseFeaturesTrainingSet/faces
. - Use cosine similarity to compare each test image feature vector Tx to input image feature vector I
- Use similarity threshold sT to determine if that comparison yields a face.
- Find the average of
faces / Sum(faces+nonFaces)
and use the final threshold ft to determine if the input image is a face
- Train a one stage classifier using the face images in
res/trainingSet/faces
and the non face images inres/trainingSet/nonFaces
and the 1000 Haar features (of the > 160k haar features in a 24x24 window) - Use that one stage classifier to determine whether the input image is a face or non face
- Import your own cascaded classifier. You can train the classifier as explained in Training Classifier section above.
- If you don't import a cascaded classifier, the default one will be used. The default is the best classifier we were able to train so far.
- You can detect faces on the loaded image
- You can directly use your webcam to detect faces