Real-Time Facial Recognition on Android

Asked

Viewed 1,228 times

1

Good morning!

I’m creating a real-time facial recognition app. The app should compare the video image to a recorded image.

In virtually all the researches I did the most suitable to be used was the Opencv.

I implemented with this tutorial, the library containing version 3.1.0 of Opencv.

I’m reading all the API information. However, I’m not finding a method for facial recognition, where I can use onDraw and draw a square on the face and much less how to use facial recognition and compare with another face.

Has anyone used this API? Recommends using this or another tool?

Below the source:

Showcameraactivity

public class ShowCameraActivity  extends AppCompatActivity implements CvCameraViewListener2 {

private static final String TAG = "OCVSample::Activity";
private CameraBridgeViewBase mOpenCvCameraView;
private boolean              mIsJavaCamera = true;
private MenuItem             mItemSwitchCamera = null;
Mat mRgba;
Mat mRgbaF;
Mat mRgbaT;

public ShowCameraActivity() {
    Log.i(TAG, "Instantiated new " + this.getClass());
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.show_camera);
    mOpenCvCameraView = (JavaCameraView) findViewById(R.id.show_camera_activity_java_surface_view);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener(this);
}

@Override
public void onCameraViewStarted(int width, int height) {

    mRgba = new Mat(height, width, CvType.CV_8UC4);
    mRgbaF = new Mat(height, width, CvType.CV_8UC4);
    mRgbaT = new Mat(width, width, CvType.CV_8UC4);
}

@Override
public void onCameraViewStopped() {
    mRgba.release();
}

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();
    Core.transpose(mRgba, mRgbaT);
    Imgproc.resize(mRgbaT, mRgbaF, mRgbaF.size(), 0,0, 0);
    return mRgba;
}

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");
                mOpenCvCameraView.enableView();
            } break;
            default:
            {
                super.onManagerConnected(status);
            } break;
        }
    }
};

@Override
public void onPause()
{
    super.onPause();
    if (mOpenCvCameraView != null)
        mOpenCvCameraView.disableView();
}

@Override
public void onResume()
{
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mLoaderCallback);
    } else {
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}

show_camera.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">

<org.opencv.android.JavaCameraView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone"
    android:id="@+id/show_camera_activity_java_surface_view"
    opencv:show_fps="false"
    opencv:camera_id="back" />

Inserted in the Manifest.xml

<uses-permission android:name="android.permission.CAMERA"/>
<supports-screens android:resizeable="true"
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:anyDensity="true" />

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>

PS: The doubt Facial Recognition 2014 indicated as a response the use of tutorial where the link is down. I also read about the Facedetection very good, by the way. But most of the methods are discontinued and even implementing the updating methods, I’m not able to validate the image with some photo.

Thank you very much!

  • What do you mean, "validate the image with some photo"?

  • The app must " compare the video image with a recorded image" for real-time facial recognition. I need to analyze a video face and compare it to another image (blob, .jpg, .png, etc.). Will have several photos recorded, the app needs to analyze whose face is based on this database.

  • In your image bank you need to have the image information. Type: distance between the eyes, distance from the eyes to the nose, width of the mouth, distance from the nose to mouth, etc. Your software should be able to extract this same information from the face that is in the video and select in the database. In fact, he doesn’t even use the image from the database.

  • http://www.faceplusplus.com/demo-detect/

  • Okay, is there an API that I can treat the image of the bank face, treat the image in real time and compare it?

  • https://cloud.google.com/vision/? utm_source=google&utm_medium=cpc&utm_Campaign=2016-Q1-cloud-Latam-ML-skws-freetrial

  • Reginaldo, I thought the API was pretty cool. But I uploaded a photo of myself and it brought several oriental faces to compare to mine. (Even though no eastern lineage =D ).

  • kkkkk. So you need to fine tune these results. You need to have enough information in your database to bring only the correct face or information that there is no record in the database.

  • Hello. Your question is very wide because face detection and face recognition are related but distinct subjects. In addition, this site is not a forum, but a site of questions and objective answers. So don’t ask the question as "someone recommends it", but post your specific difficulty (you can open more than one question if you have more than one difficulty). About face recognition, I suggest this article from Opencv: http://docs.opencv.org/2.4/modules/contrib/doc/facerec/facerec_tutorial.html

  • P.S.: And, yes, I strongly recommend the use of Opencv. It is the best library for this intention, and has much material on the Internet. :)

  • You will notice in the article that usually you use methods based on texture or directly on the pixel value of the image. In the comments they suggested geometric methods (measuring distances from facial marks), but the problem with this is that detecting these marks robustly is still an open problem. Opencv has a good face detector (http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html) but there are reasonable face tag detectors (suggested reading on this subject: http://www.learnopencv.com/facial-landmarkrk-detection/), if you want to try it anyway.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.