Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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). you will have to rebuild your opencv libs with the opencv_contrib repo (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:

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); feature = net.forward(); // a 1x128 float vector

then we can compare features from 2 images, using a simpleL2 norm:

double dist = Core.norm(feature1, feature2);

(or apply your favourite ml technique here)

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). 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 !)
  • 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/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7

import org.opencv.dnn.*;

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); feature = net.forward(); // a 1x128 float vector

vector

then we can compare features from 2 images, using a simpleL2 norm:

double dist = Core.norm(feature1, feature2);

feature2);

(or apply your favourite ml technique here)

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 !)
  • 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/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7

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);
feature = net.forward(); // a 1x128 float vector

then we can compare features from 2 images, using a simpleL2 norm:

double dist = Core.norm(feature1, feature2);

(or apply your favourite ml technique here)

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 !)
  • 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/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7

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(); // a 1x128 float vector

then we can compare features from 2 images, using a simpleL2 norm:

double dist = Core.norm(feature1, feature2);

(or apply your favourite ml technique here)

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 !)
  • 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/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7

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(); // a 1x128 float vector

then we can compare features from 2 images, using a simpleL2 simple L2 norm:

double dist = Core.norm(feature1, feature2);

(or apply your favourite ml technique here)

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/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7

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(); // a 1x128 float vector

then we can compare features from 2 images, using a simple L2 norm:

double dist = Core.norm(feature1, feature2);

(or apply your favourite ml technique here)

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/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7

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(); // a 1x128 float vector

then we can compare features from 2 images, using a simple L2 norm:

double dist = Core.norm(feature1, feature2);

(or apply your favourite ml technique here)

and here are the docs: https://docs.opencv.org/master/javadoc/index.html

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/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7

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(); // a 1x128 float vector

then we can compare features from 2 images, using a simple L2 norm:

double dist distance = Core.norm(feature1, feature2);

(or apply your favourite ml technique here)

and here are the docs: https://docs.opencv.org/master/javadoc/index.html

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/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7

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(); 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/javadoc/index.html