Ask Your Question
0

How to recognized face which are already detected by application?

asked 2018-03-19 00:21:52 -0500

sandiplovv gravatar image

updated 2018-03-19 00:23:09 -0500

Hello Members, I have used OpenCV, JavaFX to detect and save the face image in local folder. Now I want to recognized face if already saved in local system. I need a some guidance and some sample code or links so I can move further.

image description

this is face croped and saved in local systm

Thank You...! Sandip D.

edit retag flag offensive close merge delete

Comments

1

what is your use-case for it ? are you trying to recognize a single person ? are you trying to build a database for several ? explain, what your app should do.

in the meantime, read a bit here

berak gravatar imageberak ( 2018-03-19 03:03:14 -0500 )edit

Hello @berak, I did not used any database, cropped image save in local folder of project. I want to compare face with cropped images

sandiplovv gravatar imagesandiplovv ( 2018-03-19 03:17:04 -0500 )edit

here my code for cropping face from webcam

Rect rectCrop = null;
    int i =1;
    for (Rect rect : facesArray) {
        Imgproc.rectangle(frame, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                new Scalar(0, 255, 0));
        rectCrop = new Rect(rect.x, rect.y, rect.width, rect.height);

        Mat image_roi = new Mat(frame,rectCrop);
         Imgcodecs.imwrite("./face"+ i +".jpg",image_roi);
         i++;
    }
sandiplovv gravatar imagesandiplovv ( 2018-03-19 03:17:24 -0500 )edit

are you trying to recognize a single person (like, is that me?), or many (like who of 3 possible ones is it) ?

berak gravatar imageberak ( 2018-03-19 03:30:23 -0500 )edit

@berak trying to multiple ... but this time single person also OK. But main aim is to trying to multiple faces

sandiplovv gravatar imagesandiplovv ( 2018-03-19 04:04:03 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2018-03-19 04:36:04 -0500

berak gravatar image

updated 2018-03-19 04:46:38 -0500

you could try to use opencv's face recognition classes for multiple persons, or the MACE Filter there for a single person, but maybe you want to try out opencv's new dnn methods:

the concept here is to run (color !) images through a pretrained cnn, and obtain a 1x128 "feature" vector, which can easily be compared using the L2 norm, to find out, if it's the same.

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

static Mat processFace(Net net, Mat img) {
    Mat blob = Dnn.blobFromImage(img, 1./255, new Size(96,96), Scalar.all(0), true, false);
    net.setInput(blob);
    return net.forward().clone();
}

public static void main(String[] args) {
    // Load the native library.
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    Net net  = Dnn.readNetFromTorch("openface.nn4.small2.v1.t7");

    Mat img1 = Imgcodecs.imread("../img/face1.png");
    Mat img2 = Imgcodecs.imread("../img/face2.jpg");

    Mat feature1 = processFace(net, img1);
    Mat feature2 = processFace(net, img2);
    double distance = Core.norm(feature1, feature2);
    System.out.println("distance: " + distance);
}
edit flag offensive delete link more

Comments

i got confused in packeges

sandiplovv gravatar imagesandiplovv ( 2018-03-19 04:45:22 -0500 )edit

which means ?

oh, probably import org.opencv.dnn.*;

this also assumes, you're using opencv341

and the facerecognizer/mace classes need to be build with the opencv_contrib repo

berak gravatar imageberak ( 2018-03-19 04:49:26 -0500 )edit

i am using OpenCV3.1 &&

<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.10</version>
    </dependency>

    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>javacv-platform</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco.javacpp-presets</groupId>
        <artifactId>tesseract-platform</artifactId>
        <version>3.04.01-1.3</version>
    </dependency>
sandiplovv gravatar imagesandiplovv ( 2018-03-19 04:57:03 -0500 )edit

maybe this is a good reason to update ? like it is now, you can't use any of the proposed methods above.

in the meantime, you can try to compare the images directly, like norm(a,b). it will give you a good feel, for what you're doing later. (and will already have like 75% accuracy)

berak gravatar imageberak ( 2018-03-19 04:59:55 -0500 )edit

means I have to update CV version to 3.4

sandiplovv gravatar imagesandiplovv ( 2018-03-19 05:04:00 -0500 )edit

oh, and don't use those bytedeco wrappers(we cannot help you with any of that), but opencv's please

berak gravatar imageberak ( 2018-03-19 05:06:16 -0500 )edit

OK.. Now I am using purely openCV 3.4 but following error occurs

OpenCV(3.4.1) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\dnn\src\torch\THDiskFile.cpp:496: error: (-2) cannot open <openface.nn4.small2.v1.t7> in mode r  in function TH::THDiskFile_new
sandiplovv gravatar imagesandiplovv ( 2018-03-19 05:21:21 -0500 )edit

can you check the path again, also the size of the file (download problem ? happens often !) ?

berak gravatar imageberak ( 2018-03-19 05:46:45 -0500 )edit

which path, i gave .dll file path

sandiplovv gravatar imagesandiplovv ( 2018-03-19 05:59:52 -0500 )edit

the path to the torch model, openface.nn4.small2.v1.t7 . it should be ~30mb.

berak gravatar imageberak ( 2018-03-19 06:04:41 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-03-19 00:21:52 -0500

Seen: 201 times

Last updated: Mar 19