Ask Your Question
-1

OpenCV: How to identify a face in scalable way?

asked 2018-05-02 14:18:12 -0600

publicocean0 gravatar image

updated 2018-05-02 15:23:02 -0600

Scenario: i use a sql database for saving the face descriptor and eventually a hash for this descriptor. Database can be huge. I m searching a way gor identify a generic face present in a image(image can be from another panorama) having the face descriptor in database

img is the image variable: DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.SURF);

System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Mat img_1=Imgcodecs.imread(img);

MatOfKeyPoint kp_1 = new MatOfKeyPoint();

FeatureDetector fd = FeatureDetector.create(FeatureDetector.FAST); fd.detect(img_1, kp_1); descriptor.compute(img_1,kp_1,descriptors_1);

If i save the descriptor in db and also its hashcode.

when i want identify a face in a image... i extract the descriptor from that image and i calculate his hashcode. Then i query in database all descrioptors with same hashcode(rarely can be more than 1). Then i compare the descriptor present in db with the descriptor from image.

Can this algorithm work correctly? How to compare Mat classes? How to create a hashcode from Mat class?

edit retag flag offensive close merge delete

Comments

"Can this algorithm work correctly?" -- never.

berak gravatar imageberak ( 2018-05-02 14:24:24 -0600 )edit

Please suggest me how to do if you think it is wrong. I searched in google ... i found similar ideas about hashing SURF descriptors using spatial hashing. Maybe there is a missing step (the neural training step). Maybe i might save in db also the neural trained net for every face. And check identification for each face resulted by query.

publicocean0 gravatar imagepublicocean0 ( 2018-05-02 15:30:12 -0600 )edit

just curious, what does your "hashing" do, exactly ?

berak gravatar imageberak ( 2018-05-03 03:12:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-03 03:11:54 -0600

berak gravatar image

updated 2018-05-03 03:48:07 -0600

probably the best way to do so is using the pretrained openface dnn:

    Net net = Dnn.readNetFromTorch("openface.nn4.small2.v1.t7");
    ...
    //Convert Mat to image batch
    Mat blob = dnn::blobFromImage(img, 1./255, new Size(96,96), new Scalar(), true, false);
    net.setInput(blob);
    Mat feature = net.forward();

then compare the resulting (128 float) features using simple L2 norm:

   double dist = Core.norm(f1,f2);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-02 14:18:12 -0600

Seen: 112 times

Last updated: May 03 '18