调整了人脸识别界面
@@ -33,17 +33,21 @@
|
|||||||
android:name=".activity.LoginByPwdActivity"
|
android:name=".activity.LoginByPwdActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleTask">
|
android:launchMode="singleTask">
|
||||||
<intent-filter>
|
<!-- <intent-filter>-->
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<!-- <action android:name="android.intent.action.MAIN" />-->
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
|
||||||
</intent-filter>
|
<!-- </intent-filter>-->
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.LoginByFaceActivity"
|
android:name=".activity.LoginByFaceActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleTask">
|
android:launchMode="singleTask">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.MainActivity"
|
android:name=".activity.MainActivity"
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
// 确保内容延伸到导航栏区域
|
// 确保内容延伸到导航栏区域
|
||||||
// WindowCompat.setDecorFitsSystemWindows(window, false)
|
// WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
|
||||||
|
//保持亮屏
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
|
||||||
binding = inflateViewBinding()
|
binding = inflateViewBinding()
|
||||||
headerBinding = inflateTitleBinding()
|
headerBinding = inflateTitleBinding()
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
|
viewModel.activeEngine()
|
||||||
// viewModel.activeEngine()
|
|
||||||
initArcViewModel()
|
initArcViewModel()
|
||||||
initArcView()
|
initArcView()
|
||||||
openRectInfoDraw = true
|
openRectInfoDraw = true
|
||||||
@@ -156,6 +155,10 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
Timber.i("recognizeUserId observe userId = $userId")
|
Timber.i("recognizeUserId observe userId = $userId")
|
||||||
viewModel.getUserInfoById(memberId = userId?.toInt() ?: 0)
|
viewModel.getUserInfoById(memberId = userId?.toInt() ?: 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
recognizeViewModel.drawRectInfoText.observe(this, Observer { info ->
|
||||||
|
Timber.i("drawRectInfoText observe info = $info")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initArcView() {
|
private fun initArcView() {
|
||||||
@@ -250,8 +253,10 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
val layoutParams = adjustPreviewViewSize(
|
val layoutParams = adjustPreviewViewSize(
|
||||||
binding.dualCameraTexturePreviewRgb,
|
binding.dualCameraTexturePreviewRgb,
|
||||||
binding.dualCameraTexturePreviewRgb, binding.dualCameraFaceRectView,
|
binding.dualCameraTexturePreviewRgb, binding.dualCameraFaceRectView,
|
||||||
previewSizeRgb, displayOrientation, 1.0f
|
previewSizeRgb, displayOrientation, 1f
|
||||||
)
|
)
|
||||||
|
Timber.d("initRgbCamera previewSizeRgb = ${previewSizeRgb.width}-${previewSizeRgb.height}")
|
||||||
|
Timber.d("initRgbCamera layoutParams = ${layoutParams.width}-${layoutParams.height}")
|
||||||
rgbFaceRectTransformer = FaceRectTransformer(
|
rgbFaceRectTransformer = FaceRectTransformer(
|
||||||
previewSizeRgb.width,
|
previewSizeRgb.width,
|
||||||
previewSizeRgb.height,
|
previewSizeRgb.height,
|
||||||
@@ -269,7 +274,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.Q)
|
@RequiresApi(api = Build.VERSION_CODES.Q)
|
||||||
override fun onPreview(nv21: ByteArray?, camera: Camera?) {
|
override fun onPreview(nv21: ByteArray?, camera: Camera?) {
|
||||||
if (!isRecognition) {
|
if (!isRecognition) {
|
||||||
@@ -322,7 +326,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
rgbCameraHelper!!.start()
|
rgbCameraHelper!!.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绘制RGB、IR画面的实时人脸信息
|
* 绘制RGB、IR画面的实时人脸信息
|
||||||
*
|
*
|
||||||
@@ -337,7 +340,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
)
|
)
|
||||||
// 识别成功
|
// 识别成功
|
||||||
binding.dualCameraFaceRectView.drawRealtimeFaceInfo(rgbDrawInfoList)
|
binding.dualCameraFaceRectView.drawRealtimeFaceInfo(rgbDrawInfoList)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Intent
|
|||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.sw.plate.utils.ToastUtils
|
import com.sw.plate.utils.ToastUtils
|
||||||
|
import com.sw.plate.utils.arcface.face.Test
|
||||||
import com.sw.platecabinet.databinding.ActivityLoginByPwdBinding
|
import com.sw.platecabinet.databinding.ActivityLoginByPwdBinding
|
||||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||||
import com.sw.platecabinet.viewmodel.UserViewModel
|
import com.sw.platecabinet.viewmodel.UserViewModel
|
||||||
@@ -28,6 +29,11 @@ class LoginByPwdActivity : BaseActivity<ActivityLoginByPwdBinding>() {
|
|||||||
val pwd = binding.etPwd.text.toString()
|
val pwd = binding.etPwd.text.toString()
|
||||||
if (phone.isEmpty() || pwd.isEmpty()) {
|
if (phone.isEmpty() || pwd.isEmpty()) {
|
||||||
ToastUtils.showToast("手机或校验码不能为空")
|
ToastUtils.showToast("手机或校验码不能为空")
|
||||||
|
val test = Test()
|
||||||
|
for (i in 1..1000) {
|
||||||
|
test.test1()
|
||||||
|
}
|
||||||
|
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
viewModel.loginWithPwd(phone = phone, password = pwd)
|
viewModel.loginWithPwd(phone = phone, password = pwd)
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ import com.sw.platecabinet.model.request.LoginParam
|
|||||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||||
import com.sw.platecabinet.model.response.UserFaceModel
|
import com.sw.platecabinet.model.response.UserFaceModel
|
||||||
import com.sw.platecabinet.utils.ThreadUtils
|
import com.sw.platecabinet.utils.ThreadUtils
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class UserViewModel : BaseViewModel() {
|
class UserViewModel : BaseViewModel() {
|
||||||
@@ -55,8 +57,10 @@ class UserViewModel : BaseViewModel() {
|
|||||||
val faceEntity = list.map {
|
val faceEntity = list.map {
|
||||||
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureString))
|
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureString))
|
||||||
}
|
}
|
||||||
faceApi.updateFaceData(index, faceEntity)
|
withContext(Dispatchers.Default) {
|
||||||
activeEngine()
|
faceApi.updateFaceData(index, faceEntity)
|
||||||
|
activeEngine()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 477 B |
|
After Width: | Height: | Size: 467 B |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 927 B |
|
After Width: | Height: | Size: 2.4 KiB |
@@ -2,7 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#14141E"
|
android:background="@drawable/bg"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
@@ -33,11 +33,11 @@
|
|||||||
android:gravity="center_vertical">
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="32dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="32dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="24dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginEnd="55dp"
|
android:layout_marginEnd="55dp"
|
||||||
android:src="@mipmap/ic_phone" />
|
android:src="@drawable/ic_phone" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/et_phone"
|
android:id="@+id/et_phone"
|
||||||
@@ -73,11 +73,11 @@
|
|||||||
android:gravity="center_vertical">
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="32dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="32dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="24dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginEnd="55dp"
|
android:layout_marginEnd="55dp"
|
||||||
android:src="@mipmap/ic_password" />
|
android:src="@drawable/ic_pwd" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/et_pwd"
|
android:id="@+id/et_pwd"
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
android:id="@+id/main"
|
android:id="@+id/main"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#14141E"
|
|
||||||
android:fitsSystemWindows="false"
|
android:fitsSystemWindows="false"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
android:background="@drawable/bg"
|
||||||
tools:context=".activity.LoginByFaceActivity">
|
tools:context=".activity.LoginByFaceActivity">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
@@ -28,59 +28,60 @@
|
|||||||
android:textColor="#fff0c8b4"
|
android:textColor="#fff0c8b4"
|
||||||
android:textSize="36sp" />
|
android:textSize="36sp" />
|
||||||
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="380dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="380dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="119dp"
|
android:layout_marginTop="129dp"
|
||||||
android:padding="10dp"
|
android:gravity="center_vertical"
|
||||||
android:visibility="visible">
|
android:visibility="visible">
|
||||||
|
|
||||||
<!-- <androidx.camera.view.PreviewView-->
|
<FrameLayout
|
||||||
<!-- android:id="@+id/previewView"-->
|
android:layout_width="380dp"
|
||||||
<!-- android:layout_margin="10dp"-->
|
android:layout_height="wrap_content"
|
||||||
<!-- android:layout_width="match_parent"-->
|
android:layout_gravity="center"
|
||||||
<!-- android:layout_height="match_parent" />-->
|
android:paddingTop="1dp">
|
||||||
|
|
||||||
<TextureView
|
<TextureView
|
||||||
android:id="@+id/dual_camera_texture_preview_rgb"
|
android:id="@+id/dual_camera_texture_preview_rgb"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="380dp"
|
||||||
android:layout_height="match_parent"
|
android:visibility="visible"
|
||||||
android:layout_margin="10dp" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<com.sw.plate.utils.arcface.FaceRectView
|
|
||||||
android:id="@+id/dual_camera_face_rect_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
|
|
||||||
<View
|
<com.sw.plate.utils.arcface.FaceRectView
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/dual_camera_face_rect_view"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_margin="0dp"
|
android:layout_height="380dp" />
|
||||||
android:background="@drawable/circle_dashed_border" />
|
</FrameLayout>
|
||||||
|
|
||||||
<View
|
<ImageView
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="@mipmap/bg_face" />
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/ll_to_pwd"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="120dp"
|
|
||||||
android:background="@drawable/btn_outline_887872"
|
|
||||||
android:gravity="center"
|
|
||||||
android:paddingHorizontal="45dp"
|
|
||||||
android:paddingVertical="18dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="密码登录"
|
android:background="@drawable/bg_face" />
|
||||||
android:textColor="#ff887872"
|
|
||||||
android:textSize="24sp" />
|
|
||||||
</LinearLayout>
|
<LinearLayout
|
||||||
|
android:id="@+id/ll_to_pwd"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="208dp"
|
||||||
|
android:layout_marginTop="500dp"
|
||||||
|
android:background="@drawable/btn_outline_887872"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingHorizontal="45dp"
|
||||||
|
android:paddingVertical="18dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="密码登录"
|
||||||
|
android:textColor="#ff887872"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:background="#14141E"
|
android:background="@drawable/bg"
|
||||||
tools:context=".activity.MainActivity">
|
tools:context=".activity.MainActivity">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
|
|||||||
@@ -28,10 +28,10 @@
|
|||||||
tools:text="1-12" />
|
tools:text="1-12" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="280dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="24dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="22dp"
|
android:layout_marginTop="22dp"
|
||||||
android:src="@mipmap/ic_bind_img" />
|
android:src="@drawable/ic_bind_img" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
tools:context=".fragment.PlateCabinetFullFragment">
|
tools:context=".fragment.PlateCabinetFullFragment">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="48dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="48dp"
|
android:layout_height="wrap_content"
|
||||||
android:src="@mipmap/ic_full" />
|
android:src="@drawable/ic_full" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -28,9 +28,9 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="60dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="60dp"
|
android:layout_height="wrap_content"
|
||||||
android:src="@mipmap/ic_plate_open" />
|
android:src="@drawable/ic_plate_open" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="280dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="24dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="80dp"
|
android:layout_marginTop="80dp"
|
||||||
android:src="@mipmap/ic_unbind_img" />
|
android:src="@drawable/ic_unbind_img" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 9.9 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 610 B |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 10 KiB |
@@ -10,4 +10,6 @@
|
|||||||
<color name="bind_F0C8B4">#F0C8B4</color>
|
<color name="bind_F0C8B4">#F0C8B4</color>
|
||||||
<color name="unbind_F0C8B4">#F0C8B4</color>
|
<color name="unbind_F0C8B4">#F0C8B4</color>
|
||||||
<color name="unbind_32283C">#32283C</color>
|
<color name="unbind_32283C">#32283C</color>
|
||||||
|
|
||||||
|
<color name="divColor">#4c91ceff</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -4,4 +4,5 @@
|
|||||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||||
|
|
||||||
<string name="specific_engine_init_failed">%s 初始化失败,错误码:%d\n错误码常量名:%s</string>
|
<string name="specific_engine_init_failed">%s 初始化失败,错误码:%d\n错误码常量名:%s</string>
|
||||||
|
<string name="permission_denied">权限被拒绝!</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.sw.plate.utils.arcface;
|
package com.sw.plate.utils.arcface;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arcsoft.face.FaceEngine;
|
import com.arcsoft.face.FaceEngine;
|
||||||
import com.arcsoft.face.enums.RuntimeABI;
|
import com.arcsoft.face.enums.RuntimeABI;
|
||||||
@@ -14,6 +15,8 @@ import com.sw.plate.utils.arcface.facedb.entity.FaceEntity;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FaceApi {
|
public class FaceApi {
|
||||||
|
private static final String TAG = "FaceApi";
|
||||||
|
|
||||||
public interface ActiveCallback {
|
public interface ActiveCallback {
|
||||||
void onSuccess(int code);
|
void onSuccess(int code);
|
||||||
|
|
||||||
@@ -27,12 +30,12 @@ public class FaceApi {
|
|||||||
* @param list
|
* @param list
|
||||||
*/
|
*/
|
||||||
public void updateFaceData(int index, List<FaceEntity> list) {
|
public void updateFaceData(int index, List<FaceEntity> list) {
|
||||||
|
Log.d(TAG, "updateFaceData: index = " + index + ", listSize = " + list.size());
|
||||||
FaceDao faceDao = FaceDatabase.getInstance(App.getContext()).faceDao();
|
FaceDao faceDao = FaceDatabase.getInstance(App.getContext()).faceDao();
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
faceDao.deleteAll();
|
faceDao.deleteAll();
|
||||||
faceDao.resetId();
|
faceDao.resetId();
|
||||||
}
|
}
|
||||||
|
|
||||||
faceDao.insert(list);
|
faceDao.insert(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.sw.plate.utils.arcface.face;
|
|||||||
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
@@ -47,7 +49,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.Observer;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
@@ -529,7 +530,7 @@ public class FaceHelper implements FaceListener {
|
|||||||
if (recognizeInfoMap.containsKey(trackId)) {
|
if (recognizeInfoMap.containsKey(trackId)) {
|
||||||
onFaceFeatureInfoGet(faceFeature, trackId, errorCode);
|
onFaceFeatureInfoGet(faceFeature, trackId, errorCode);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "onFaceFeatureInfoGet: 等待活体结果时退出界面会执行,正常现象,可注释异常代码块");
|
Log.e(TAG, "onFaceFeatureInfoGet: 等待活体结果时退出界面会执行,正常现象,可注释异常代码块");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -549,40 +550,35 @@ public class FaceHelper implements FaceListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 定义一个Handler,用于处理延迟任务
|
||||||
|
private Handler delayHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 延迟 {@link RecognizeConfiguration#getLivenessFailedRetryInterval()}后,重新进行活体检测
|
* 延迟 {@link RecognizeConfiguration#getLivenessFailedRetryInterval()}后,重新进行活体检测
|
||||||
*
|
*
|
||||||
* @param trackId 人脸ID
|
* @param trackId 人脸ID
|
||||||
*/
|
*/
|
||||||
private void retryLivenessDetectDelayed(final Integer trackId) {
|
private void retryLivenessDetectDelayed(final Integer trackId) {
|
||||||
Observable.timer(recognizeConfiguration.getLivenessFailedRetryInterval(), TimeUnit.MILLISECONDS)
|
Log.d(TAG, "retryLivenessDetectDelayed: trackId = " + trackId + ", threadName =" + Thread.currentThread().getName());
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
Log.d(TAG, "retryLivenessDetectDelayed: Interval = " + recognizeConfiguration.getLivenessFailedRetryInterval());
|
||||||
.subscribe(new Observer<Long>() {
|
|
||||||
Disposable disposable;
|
|
||||||
|
|
||||||
@Override
|
// 创建延迟任务
|
||||||
public void onSubscribe(Disposable d) {
|
Runnable delayTask = new Runnable() {
|
||||||
disposable = d;
|
@Override
|
||||||
delayFaceTaskCompositeDisposable.add(disposable);
|
public void run() {
|
||||||
}
|
// 将该人脸状态置为UNKNOWN,帧回调处理时会重新进行活体检测
|
||||||
|
changeLiveness(trackId, LivenessInfo.UNKNOWN);
|
||||||
|
// 从集合中移除这个任务
|
||||||
|
delayFaceTaskList.remove(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
// 将任务添加到集合中管理
|
||||||
public void onNext(Long aLong) {
|
delayFaceTaskList.add(delayTask);
|
||||||
|
|
||||||
}
|
// 发送延迟任务
|
||||||
|
delayHandler.postDelayed(delayTask, recognizeConfiguration.getLivenessFailedRetryInterval());
|
||||||
@Override
|
|
||||||
public void onError(Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
// 将该人脸状态置为UNKNOWN,帧回调处理时会重新进行活体检测
|
|
||||||
changeLiveness(trackId, LivenessInfo.UNKNOWN);
|
|
||||||
delayFaceTaskCompositeDisposable.remove(disposable);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -591,40 +587,33 @@ public class FaceHelper implements FaceListener {
|
|||||||
* @param trackId 人脸ID
|
* @param trackId 人脸ID
|
||||||
*/
|
*/
|
||||||
private void retryRecognizeDelayed(final Integer trackId) {
|
private void retryRecognizeDelayed(final Integer trackId) {
|
||||||
|
Log.d(TAG, "retryRecognizeDelayed: trackId = " + trackId);
|
||||||
changeRecognizeStatus(trackId, RequestFeatureStatus.FAILED);
|
changeRecognizeStatus(trackId, RequestFeatureStatus.FAILED);
|
||||||
Observable.timer(recognizeConfiguration.getRecognizeFailedRetryInterval(), TimeUnit.MILLISECONDS)
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(new Observer<Long>() {
|
|
||||||
Disposable disposable;
|
|
||||||
|
|
||||||
@Override
|
// 创建延迟任务
|
||||||
public void onSubscribe(Disposable d) {
|
Runnable delayTask = new Runnable() {
|
||||||
disposable = d;
|
@Override
|
||||||
delayFaceTaskCompositeDisposable.add(disposable);
|
public void run() {
|
||||||
}
|
// 将该人脸特征提取状态置为FAILED,帧回调处理时会重新进行活体检测
|
||||||
|
changeRecognizeStatus(trackId, RequestFeatureStatus.TO_RETRY);
|
||||||
|
// 从集合中移除这个任务
|
||||||
|
delayFaceTaskList.remove(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
// 将任务添加到集合中管理
|
||||||
public void onNext(Long aLong) {
|
delayFaceTaskList.add(delayTask);
|
||||||
|
|
||||||
}
|
// 发送延迟任务
|
||||||
|
delayHandler.postDelayed(delayTask, recognizeConfiguration.getRecognizeFailedRetryInterval());
|
||||||
@Override
|
|
||||||
public void onError(Throwable e) {
|
|
||||||
Log.e(TAG, "retryRecognizeDelayed e = " + e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
// 将该人脸特征提取状态置为FAILED,帧回调处理时会重新进行活体检测
|
|
||||||
changeRecognizeStatus(trackId, RequestFeatureStatus.TO_RETRY);
|
|
||||||
delayFaceTaskCompositeDisposable.remove(disposable);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 需要在类中定义一个集合来管理所有的延迟任务,替代原来的CompositeDisposable
|
||||||
|
private List<Runnable> delayFaceTaskList = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFaceLivenessInfoGet(@Nullable LivenessInfo livenessInfo, Integer trackId, Integer errorCode) {
|
public void onFaceLivenessInfoGet(@Nullable LivenessInfo livenessInfo, Integer trackId, Integer errorCode) {
|
||||||
|
Log.d(TAG, "onFaceLivenessInfoGet: trackId = " + trackId);
|
||||||
if (livenessInfo != null) {
|
if (livenessInfo != null) {
|
||||||
int liveness = livenessInfo.getLiveness();
|
int liveness = livenessInfo.getLiveness();
|
||||||
Log.i(TAG, "onFaceLivenessInfoGet liveness:" + liveness);
|
Log.i(TAG, "onFaceLivenessInfoGet liveness:" + liveness);
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.sw.plate.utils.arcface.face;
|
||||||
|
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.Observer;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
|
||||||
|
public class Test {
|
||||||
|
|
||||||
|
private static final String TAG = "Test";
|
||||||
|
private CompositeDisposable delayFaceTaskCompositeDisposable = new CompositeDisposable();
|
||||||
|
|
||||||
|
public void test1() {
|
||||||
|
Log.d(TAG, "test1: ");
|
||||||
|
Observable.timer(10, TimeUnit.MILLISECONDS)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Observer<Long>() {
|
||||||
|
Disposable disposable;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
disposable = d;
|
||||||
|
delayFaceTaskCompositeDisposable.add(disposable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(Long value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
Log.d(TAG, "onComplete: ");
|
||||||
|
delayFaceTaskCompositeDisposable.remove(disposable);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,8 +9,6 @@ import androidx.room.RoomDatabase;
|
|||||||
import com.sw.plate.utils.arcface.facedb.dao.FaceDao;
|
import com.sw.plate.utils.arcface.facedb.dao.FaceDao;
|
||||||
import com.sw.plate.utils.arcface.facedb.entity.FaceEntity;
|
import com.sw.plate.utils.arcface.facedb.entity.FaceEntity;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
@Database(entities = {FaceEntity.class}, version = 1, exportSchema = false)
|
@Database(entities = {FaceEntity.class}, version = 1, exportSchema = false)
|
||||||
public abstract class FaceDatabase extends RoomDatabase {
|
public abstract class FaceDatabase extends RoomDatabase {
|
||||||
public abstract FaceDao faceDao();
|
public abstract FaceDao faceDao();
|
||||||
@@ -22,7 +20,9 @@ public abstract class FaceDatabase extends RoomDatabase {
|
|||||||
synchronized (FaceDatabase.class) {
|
synchronized (FaceDatabase.class) {
|
||||||
if (faceDatabase == null) {
|
if (faceDatabase == null) {
|
||||||
faceDatabase = Room.databaseBuilder(context, FaceDatabase.class,
|
faceDatabase = Room.databaseBuilder(context, FaceDatabase.class,
|
||||||
context.getExternalFilesDir("database") + File.separator + "faceDB.db").build();
|
context.getDatabasePath("faceDB.db").getPath()
|
||||||
|
// context.getExternalFilesDir("database") + File.separator + "faceDB.db"
|
||||||
|
).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Environment;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arcsoft.face.ErrorInfo;
|
import com.arcsoft.face.ErrorInfo;
|
||||||
@@ -354,8 +353,11 @@ public class FaceServer {
|
|||||||
* @return 存放注册照的文件夹路径
|
* @return 存放注册照的文件夹路径
|
||||||
*/
|
*/
|
||||||
private String getImageDir() {
|
private String getImageDir() {
|
||||||
return App.getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES)
|
// return App.getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES)
|
||||||
+ File.separator + "faceDB" + File.separator + "registerFaces";
|
// + File.separator + "faceDB" + File.separator + "registerFaces";
|
||||||
|
return App.getContext().getFilesDir()
|
||||||
|
+ File.separator + "faceDB"
|
||||||
|
+ File.separator + "registerFaces";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||