Как конвертировать FirebaseVisionFace в Bitmap отсюда? - PullRequest
0 голосов
/ 27 июня 2019

Я реализовал Firebase ML kit, можете ли вы, ребята, помочь мне, как я могу создать растровое изображение из этой информации и показать его в виде изображения?Пожалуйста, помогите мне, как я могу создать растровое изображение на этом этапе и сохранить его в памяти устройства?Я попробовал этот код, помогите мне пойти глубже.

       public void onSuccess(List<FirebaseVisionFace> faces) {
                            // Task completed successfully
                            // ...
                            Log.d("Success: ", "success");
                            for (FirebaseVisionFace face : faces) {
                                Rect bounds = face.getBoundingBox();
                                float rotY = face.getHeadEulerAngleY();  // Head is rotated to the right rotY degrees
                                float rotZ = face.getHeadEulerAngleZ();  // Head is tilted sideways rotZ degrees
                                Log.d("rotY: ", ""+rotY);
                                Log.d("rotZ: ", ""+rotZ);
                                // If landmark detection was enabled (mouth, ears, eyes, cheeks, and
                                // nose available):
                                FirebaseVisionFaceLandmark leftEar = face.getLandmark(FirebaseVisionFaceLandmark.LEFT_EAR);
                                if (leftEar != null) {
                                    FirebaseVisionPoint leftEarPos = leftEar.getPosition();
                                }

                                // If contour detection was enabled:
                                List<FirebaseVisionPoint> leftEyeContour =
                                        face.getContour(FirebaseVisionFaceContour.LEFT_EYE).getPoints();
                                List<FirebaseVisionPoint> upperLipBottomContour =
                                        face.getContour(FirebaseVisionFaceContour.UPPER_LIP_BOTTOM).getPoints();

                                // If classification was enabled:
                                if (face.getSmilingProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
                                    float smileProb = face.getSmilingProbability();
                                }
                                if (face.getRightEyeOpenProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
                                    float rightEyeOpenProb = face.getRightEyeOpenProbability();
                                }

                                // If face tracking was enabled:
                                if (face.getTrackingId() != FirebaseVisionFace.INVALID_ID) {
                                    int id = face.getTrackingId();
                                }

                            }
                        }

1 Ответ

0 голосов
/ 29 июня 2019

Вы можете сделать следующее:

    // bitmap is the image you already detected faces

    Paint myRectPain = new Paint();
    myRectPain.setStrokeWidth(10);
    myRectPain.setColor(Color.RED);
    myRectPain.setStyle(Paint.Style.STROKE);

    Bitmap tempBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),Bitmap.Config.RGB_565);

    Canvas tempCanvas = new Canvas(tempBitmap);
    tempCanvas.drawBitmap(bitmap,0,0,null);

    for (FirebaseVisionFace face: faces) {
        Rect bound = face.getBoundingBox();
        tempCanvas.drawRect(bound,myRectPain);
    }

    // imgView is an ImageView

    imgView.setImageDrawable(new BitmapDrawable(getResources(),tempBitmap));
...