0

I am looking at the FaceDetection example from ML Kit and I want to copy the face (perhaps using the GraphicOverlay?) of the recognized person. Is there any way to do it? I am not only interested in the face landmarks, but in the actual face itself.

I tried this (I used this method in the GraphicOverlay class and then called it in the FaceDetectionProcessor class first thing on the onSuccess method, but I get back an empty "white" jpeg when I try to save it internally):

public Bitmap getBitmapFromView(GraphicOverlay view) {
//Define a bitmap with the same size as the view
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
//Bind a canvas to it
Canvas canvas = new Canvas(returnedBitmap);
//Get the view's background
Drawable bgDrawable =view.getBackground();
if (bgDrawable!=null) {
  //has background drawable, then draw it on the canvas
  bgDrawable.draw(canvas);
}   else{
  //does not have background drawable, then draw white background on the canvas
  canvas.drawColor(Color.WHITE);
}
// draw the view on the canvas
view.draw(canvas);
//return the bitmap
return returnedBitmap;

}

recognized actual face

Panos
  • 1
  • 1
  • I answered a similar question here: https://stackoverflow.com/questions/51335588/mlkit-firebase-android-how-to-convert-firebasevisionface-to-image-object-like – gnuf Jul 15 '18 at 13:07
  • Thank you @gnuf. I would really appreciate a sample code or an example. – Panos Jul 17 '18 at 03:50
  • I cannot understand from the code given at the MLKit example where the process happens and which is the input. I thought the input was not a bitmap, but a bytebuffer. – Panos Jul 17 '18 at 04:19
  • @gnuf I am using the LivePreviewActivity, not the still images. – Panos Jul 17 '18 at 07:43
  • This is getting a bit beyond my expertise, but from looking at the ML Kit Quickstart sample (https://github.com/firebase/quickstart-android/tree/master/mlkit), the `VisionProcessorBase.java` file is where the conversion from the camera's raw preview image format into a `FirebaseVisionImage` happens. – gnuf Jul 17 '18 at 16:25
  • Obtaining a JPEG from the raw Camera preview could be done using the `android.graphics.YuvImage` class. Again, this is out of the realm of my expertise, I'm just looking things up. – gnuf Jul 17 '18 at 16:27

0 Answers0