Unfortunately openCV don't contain these classes so how can i get it in java ?
the FaceRecognizer classes are not contained in the prebuild opencv libs (it's not a java problem).
if you want those, you will have to rebuild your opencv libs with the opencv_contrib repo . you will need:
- latest src for opencv and opencv_contrib (must be same version !)
- cmake (a build tool)
- a java sdk (obviously)
- apache ant (a build tool)
- a c++ compiler (VS2017 preferred)
python (any version, for the generator)
(see readme.md for build instructions) then you can just import org.opencv.face
in the meantime, you might also try the new dnn based facerecognition, using a pretrained OpenFace network:
you'll need the pretrained facenet dnn model from here (30.1mb):
https://raw.githubusercontent.com/pya...
import org.opencv.dnn.*;
// load the pretrained network (only once !)
Net net = Dnn.readNetFromTorch("openface.nn4.small2.v1.t7");
// prepare a blob:
Mat image = Imgcodecs.imread("face1.png"); // we can use color images here !
Mat inputBlob = Dnn.blobFromImage(image, 1./255, new Size(96,96), new Scalar(), true, false);
// feed it through the network:
net.setInput(inputBlob);
Mat feature = net.forward().clone(); // a 1x128 float vector
then we can compare features from 2 images, using a simple L2 norm:
double distance = Core.norm(feature1, feature2);
(or apply your favourite ml technique here)
and here are the docs: https://docs.opencv.org/master/javado...