换脸相机实时面部添加

时间:2019-04-01 06:12:26

标签: android kotlin face-detection face-recognition

当前,我们正在开发一个基于面部检测的应用程序。在实时摄像头上检测到脸部时,我们会将另一张图像放置在检测到的区域的左侧,这样看起来就像是自拍照片。

因此,当前在拍摄相机视图的屏幕快照时,在画布上绘制的面部区域显示为黑色,因此我们无法捕获相机表面的屏幕截图。

有人有开发这种应用程序的想法吗?

/ **      *在提供的画布上绘制面部注释以定位位置。      * /     @Override     公共无效抽奖(画布画布){         Face face = mFace;         if(face == null){             返回;         }

    // Draws a circle at the position of the detected face, with the face's track id below.
    float x = translateX(face.getPosition().x + face.getWidth() / 2);
    float y = translateY(face.getPosition().y + face.getHeight() / 2);

    // Draws a bounding box around the face.
    float xOffset = scaleX(face.getWidth() / 2.3f);
    float yOffset = scaleY(face.getHeight() / 2.3f);
    float left = x - xOffset;
    float top = y - yOffset;
    float right = x + xOffset;
    float bottom = y + yOffset;
    canvas.drawRect(left, top, right, bottom, mBoxPaint);

    // Bitmap to draw on the canvas
    Bitmap bitmap = BitmapFactory.decodeResource(
            resources,
            R.drawable.ic_luncher);

    sclledBitmp=getResizedBitmap(bitmap, (int)face.getWidth()-70, (int) face.getHeight()-70);

    //Finally, Draw the source bitmap on the canvas
    canvas.drawBitmap(
            sclledBitmp, // Bitmap
            right, // Left
            top, // Top
            null // Paint
    );

    canvas.drawText("Width: " + (int)face.getWidth() + " \nright:"+right, right, top, mIdPaint);

}

0 个答案:

没有答案