Android人脸识别绘制人脸框自定义View显示
生活随笔
收集整理的這篇文章主要介紹了
Android人脸识别绘制人脸框自定义View显示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
創建一個自定義的View,它將繪制人臉框,并重寫 onDraw 方法以繪制矩形。 下面是一個示例代碼:
public class FaceBoundsView extends View {private List<Rect> faceBounds;private Paint rectPaint;public FaceBoundsView(Context context) {super(context);init();}public FaceBoundsView(Context context, AttributeSet attrs) {super(context, attrs);init();}public FaceBoundsView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init();}private void init() {rectPaint = new Paint();rectPaint.setColor(Color.GREEN);rectPaint.setStyle(Paint.Style.STROKE);rectPaint.setStrokeWidth(5);}public void setFaceBounds(List<Rect> faceBounds) {this.faceBounds = faceBounds;invalidate();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);if (faceBounds != null) {for (Rect rect : faceBounds) {canvas.drawRect(rect, rectPaint);}}} }在Activity或Fragment中,您可以按如下方式使用此視圖:
FaceBoundsView faceBoundsView = findViewById(R.id.face_bounds_view); faceBoundsView.setFaceBounds(faceBounds);在布局中,您可以按如下方式添加此視圖
<com.example.FaceBoundsViewandroid:id="@+id/face_bounds_view"android:layout_width="match_parent"android:layout_height="match_parent"/>總結
以上是生活随笔為你收集整理的Android人脸识别绘制人脸框自定义View显示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity资源导入自动生成AssetBu
- 下一篇: 病毒木马查杀实战第010篇:QQ盗号木马