简体   繁体   中英

Get detected face bitmap

I'm experimenting with the following Google sample: https://github.com/googlesamples/android-vision/tree/master/visionSamples/FaceTracker

The sample is using the Play Service new Face detection APIs, and draws a square on detected faces on the camera video stream.

I'm trying to figure out if it is possible to save the frames that has detected faces in them, from following the code it seems that the face detector's processor is a good place to perform the 'saving' but it only supplies the detection meta data and not the actual frame.

Your guidance will be appreciated.

Yes it is possible. I answered to question about getting frames from CameraSource here . Most trickiest parts are to access CameraSource frames and to convert Frame datatype to Bitmap. Then having frames as Bitmaps you can pass them to you FaceGraphic class and in method draw() save those Bitmaps, because draw() is called only when faces are detected.

You can get it in the following way:

    Bitmap source = ((BitmapDrawable) yourImageView.getDrawable()).getBitmap();
    // detect faces
    Bitmap faceBitmap = createBitmap(source, 
                                     face.getPosition().x, 
                                     face.getPosition().y, 
                                     face.getWidth(), 
                                     face.getHeight());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM