Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FaceRecognizerSF alignCrop method on the android is not work right #285

Open
tangzhezhi opened this issue Jan 20, 2025 · 3 comments
Open

Comments

@tangzhezhi
Copy link

FaceRecognizerSF alignCrop method on the android is not work right.

FaceRecognizerSF alignCrop work right on the ubuntu when i compile in c++ but it not work on the android,

i test the opencv4.9.0 and opencv4.11.0 , it all not work right .

the android result not the same with result of the ubuntu .

the android result is not align person's face .

code like this :

faceRecognizerSF.alignCrop(image, faces.row(max_face_index) , aligned_face);

@fengyuentau
Copy link
Member

I guess you missed Mat.clone().

See #187 (comment) and #195.

@tangzhezhi
Copy link
Author

tangzhezhi commented Jan 23, 2025

I guess you missed Mat.clone().

See #187 (comment) and #195.

thanks for your answer, but it's not work. the image.jpg picture's face is not align , but the same code work in ubuntu C++ env.

C++ code:
cv::Mat alignCrop(const cv::Mat &orig_image, const cv::Mat &face_image)
{
// Align and crop detected face from original image
cv::Mat target_aligned;
_recognizer->alignCrop(orig_image, face_image, target_aligned);
// Extract features from cropped detected face
return target_aligned.clone();
}

my android code is the simple as follow :

        Mat image_align = mBgrScaled.clone();
        Mat mFaces_align = mFaces.clone();
        Imgproc.cvtColor(image_align, image_align, Imgproc.COLOR_BGR2RGBA);
        Imgproc.cvtColor(mFaces_align, mFaces_align, Imgproc.COLOR_BGR2RGBA);
        Mat face_area = new Mat(image_align, rect);

        Mat aligned_face = new Mat();

        faceRecognizerSF.alignCrop(image_align, mFaces.row(max_face_index), aligned_face);
        Mat result_face = aligned_face.clone();

        boolean success = Imgcodecs.imwrite("/storage/emulated/0/Android/data/org.tang.ai.ndkopencv/files/image.jpg", result_face);
        if (success) {
            Log.i(TAG, "image save successfully!");
        }

        Bitmap resultBitmap = Bitmap.createBitmap(result_face.cols(), result_face.rows(), Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(aligned_face.clone(), resultBitmap);
        ImageView imageView = findViewById(R.id.imageView);
        imageView.setImageBitmap(resultBitmap);

        mFaces_align.release();
        face_area.release();
        aligned_face.release();
        image_align.release();
        result_face.release();

and android's result is the same the ndk compile. i compile opencv with cmake in android arm64-v8a mode

Image

the image picture is dealed to 112x112 size , it's meaning the faceRecognizerSF.alignCrop worked, but the face is not align,
so I am feeling very strange 。

Image

@fengyuentau
Copy link
Member

Did you try printing facial landmarks on the face? Your provided face image is quite blurry and I guess that facial landmarks may not be accurate enough for alignment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants