Android使用OpenCV – 4.8.0进行人脸识别(一)
·
WeChat_20230718173530
1、处理权限问题
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.front.autofocus"
android:required="true" />

2、动态权限处理
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.0.5'
implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.3@aar'

3、open_cv人脸识别模型文件(复制图示第2步lbpcascade frontalface.xml到项目raw文件夹下,注意raw若无,请自己新建)

4、页面布局如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FAFFFFFF"
android:orientation="vertical">
<org.opencv.android.JavaCameraView
android:id="@+id/by"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000" />
</LinearLayout>

更多推荐



所有评论(0)