Jar Files does not contains org.opencv.face package bu documentation file contains it. I want to use this package.How? (opencv 4.5.3, Windows 10)
the face package is from the opencv_contrib repo, which is not included in the prebuilt packages.
if you wanted face recognition, we could help with using opencv’s dnn , else you will have to bite the apple and rebuild from src:
to generate the (desktop) java bindings, you’ll need a few tools:
- cmake
- a c++ compiler
- (any version of) python
- apache ant
1 Like
Yes, I want face recognition, how can i face recognition with using opencv’s dnn package?
the idea is still similar to the LBPH recognizer, – we derive “features” from the images, and compare those, not the actual images.
- read the facenet paper
- download the pretrained dnn model
then try something like this:
import org.opencv.core.*;
import org.opencv.dnn.*;
import org.opencv.imgcodecs.*;
import org.opencv.imgproc.*;
public class FaceRecognition {
public static Mat process(Net net, Mat img) {
Mat inputBlob = Dnn.blobFromImage(img, 1./255, new Size(96,96), new Scalar(0,0,0), true, false);
net.setInput(inputBlob);
return net.forward().clone();
}
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Net net = Dnn.readNetFromTorch("c:/data/mdl/openface.nn4.small2.v1.t7");
Mat feature1 = process(net, Imgcodecs.imread("C:/data/faces/lfw40_crop/Abdullah_Gul_0004.jpg")); // your data here !
Mat feature2 = process(net, Imgcodecs.imread("C:/data/faces/lfw40_crop/Abdullah_Gul_0007.jpg")); // your data here !
double dist = Core.norm(feature1, feature2);
if (dist < 0.6)
System.out.println("SAME !");
}
}
2 Likes