基于虹软人脸识别增值版Android SDK V3.1,封装人脸识别方法。
增值版Android SDK V3.1文档
虹软人脸识别4.0封装-支持口罩识别
效果展示
限制识别区域
不限制识别区域
引入
仅支持AndroidX
### Gradle:
最新版本
//必选,默认仅支持armeabi-v7a
implementation 'com.shencoder:arc-face:1.0.1'
//可选,支持arm64-v8a
implementation 'com.shencoder:arc-face-arm64-v8a:1.0.1'
如果Gradle出现implementation失败的情况,可以在Project的build.gradle里面添加如下:
allprojects {
repositories {
//...
maven { url 'https://dl.bintray.com/shencoder/android-lib' }
}
}
项目内依赖CameraView用于摄像头预览,默认使用TextureView用于实现预览镜像。
使用事例
布局示例
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.shencoder.arcface.view.FaceCameraView
android:id="@+id/faceCameraView"
android:layout_width="match_parent"
android:layout_height="450dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
代码示例
基本使用
val faceCameraView: FaceCameraView = findViewById(R.id.faceCameraView)
val configuration = FaceConfiguration.Builder(this, object : OnRecognizeCallback {
/**
* 检测到的人脸数量
* <p>运行在子线程</p>
*
* @param num 人脸数量
* @param faceIds faceId
*/
override fun detectFaceNum(num: Int, faceIds: List<Int>) {
}
/**
* 有人,仅在有变化时调用一次
* <p>运行在子线程</p>
*/
override fun someone() {
}
/**
* 无人,仅在有变化时调用一次
* <p>运行在子线程</p>
*/
override fun nobody() {
}
/**
* 如果不想自动比对的话,可以通过此接口返回识别到的人脸特征码,仅在[FaceConfiguration.enableCompareFace] 为false时才会回调
* <p>运行在子线程</p>
*
* @param faceId 人脸Id
* @param feature 人脸特征码
* @param recognizeInfo 识别到的其他信息,包含活体值、年龄、性别、人脸角度等信息
* @param camera 预览数据
* @param width 预览数据宽度
* @param height 预览数据高度
*/
override fun onGetFaceFeature(
faceId: Int,
feature: ByteArray,
recognizeInfo: RecognizeInfo,
nv21: ByteArray,
width: Int,
height: Int
) {
Log.