Ask Your Question


asked 2018-05-30 12:21:04 -0500

WaleedJubeh gravatar image

updated 2018-05-30 12:43:27 -0500

hello ...

before show my issue this is my system information

OpenCV => 3.4.1

Operating System / Platform => Windows 10 64 Bit

Compiler => java netbeans 8.2


i'm trying to make live face recognition so i do face detection after that i start to make trainer . Trainer use FaceRecognizer class or one of its sub-classes to train and predict . Unfortunately openCV don't contain these classes so how can i get it in java ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-05-30 12:46:00 -0500

berak gravatar image

updated 2018-05-30 15:13:15 -0500

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 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):

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:
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:

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-05-30 12:21:04 -0500

Seen: 396 times

Last updated: May 30 '18