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>

该文介绍了在Android应用中处理相机权限的方法,包括静态配置uses-permission和uses-feature标签,以及使用RxPermissions进行动态权限管理。同时,文章提及了OpenCV用于人脸识别的lbpcascade_frontalface.xml模型文件的使用,并展示了包含JavaCameraView的XML布局代码。
1165

被折叠的 条评论
为什么被折叠?



