|
@@ -36,12 +36,9 @@ import io.reactivex.rxjava3.observers.DisposableSingleObserver
|
|
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.launch
|
|
|
-import okhttp3.ResponseBody
|
|
|
import org.koin.core.component.get
|
|
|
import org.koin.core.component.inject
|
|
|
-import retrofit2.Call
|
|
|
-import retrofit2.Callback
|
|
|
-import retrofit2.Response
|
|
|
+import java.io.ByteArrayOutputStream
|
|
|
import java.io.File
|
|
|
import java.nio.ByteBuffer
|
|
|
import java.util.*
|
|
@@ -85,7 +82,7 @@ class DialogValidateFace( mContext: Context) : FullScreenPopupView(mContext), IV
|
|
|
this.faceHandleRet=faceHandleRet
|
|
|
mBinding.mPreviewView.scaleType=PreviewView.ScaleType.FIT_CENTER
|
|
|
runCamera(this, mBinding.mPreviewView, faceHandleRet, context = context)
|
|
|
- mBinding.mPreviewView.bringToFront()
|
|
|
+ //mBinding.mPreviewView.bringToFront()
|
|
|
mBinding.takePhoto.setOnClickListener(this)
|
|
|
}
|
|
|
|
|
@@ -314,19 +311,85 @@ class DialogValidateFace( mContext: Context) : FullScreenPopupView(mContext), IV
|
|
|
override fun onSuccess(t: INetworkMain.UserFaceStoreListResp) {
|
|
|
var registryImgUrl= t.rows.get(0).alignedpic
|
|
|
if(registryImgUrl.isNotEmpty()){
|
|
|
- var respCall= get<INetworkMain>().userFaceImage(registryImgUrl.substring(1,registryImgUrl.length))
|
|
|
- respCall.enqueue(object:Callback<ResponseBody>{
|
|
|
- override fun onResponse(p0: Call<ResponseBody>, p1: Response<ResponseBody>) {
|
|
|
+ var respCall= get<INetworkMain>().userFaceImage(registryImgUrl).execute()
|
|
|
+
|
|
|
+
|
|
|
+ var registerData:ByteArray?=null
|
|
|
+ if(null!=respCall.body()) {
|
|
|
+ var bos: ByteArrayOutputStream? =null
|
|
|
+ try{
|
|
|
+ bos=ByteArrayOutputStream()
|
|
|
+ val ins= respCall.body()!!.byteStream()
|
|
|
+ val byteArray= ByteArray(1024)
|
|
|
+ var len:Int
|
|
|
+ while(((ins.read(byteArray)).also{ len=it})!=-1){
|
|
|
+ bos.write(byteArray,0,len)
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (e:Exception){
|
|
|
+ //ignore
|
|
|
+ registerData=ByteArray(0)
|
|
|
+ }finally {
|
|
|
+ bos?.close()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bos != null) {
|
|
|
+ registerData= bos.toByteArray()
|
|
|
+ }else{
|
|
|
+ registerData=ByteArray(0)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- FaceRecog.cwComputeMatchScore(handle,btFeature, p1.body()?.bytes(),1,scores)
|
|
|
- Log.d("demo", "检测到相似度为:${scores[0]}" )
|
|
|
+
|
|
|
+ if(null!=registerData) {
|
|
|
+
|
|
|
+ try{
|
|
|
+ var dFaceBuffer=Array(1){_ ->FaceInfo()}
|
|
|
+ var dres=FaceDetTrack.cwFaceDetection(handle, registerData,640, 480, FaceInterface.cw_img_form_t.CW_IMAGE_BINARY , 0, 0, FaceInterface.cw_op_t.CW_OP_ALL , dFaceBuffer)
|
|
|
+
|
|
|
+ if (dres >= FaceInterface.cw_errcode_t.CW_UNKNOWN_ERR) {
|
|
|
+ scores[0]=0.0F
|
|
|
+ Log.d("demo", "检测到相似度为:${scores[0]}")
|
|
|
+ }else if(dres>1){
|
|
|
+ scores[0]=0.0F
|
|
|
+ Log.d("demo", "检测到相似度为:${scores[0]}")
|
|
|
+ }else{
|
|
|
+ val dtFeature=ByteArray(iFeaLen)
|
|
|
+ FaceRecog.cwGetFaceFeature(handle,dFaceBuffer[0].alignedData,dFaceBuffer[0].alignedW,
|
|
|
+ dFaceBuffer[0].alignedH,dFaceBuffer[0].nChannels, dtFeature)
|
|
|
+ FaceRecog.cwComputeMatchScore(handle, btFeature, dtFeature, 1, scores)
|
|
|
+ Log.d("demo", "检测到相似度为:${scores[0]}")
|
|
|
+ }
|
|
|
+ }catch (e:Exception){
|
|
|
+ scores[0]=0.0F
|
|
|
+ Log.d("demo", "人脸对比异常:${e.message}")
|
|
|
+ Log.d("demo", "检测到相似度为:${scores[0]}")
|
|
|
}
|
|
|
|
|
|
- override fun onFailure(p0: Call<ResponseBody>, p1: Throwable) {
|
|
|
- Log.d("demo", "请求id为0的客户人脸信息二进制错误:${p1.message}" )
|
|
|
+
|
|
|
+ } else{
|
|
|
+ scores[0]=0.0F
|
|
|
+ Log.d("demo", "检测到相似度为:${scores[0]}")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ context.lifecycleScope.launch {
|
|
|
+ if(scores.isNotEmpty() && scores[0] > 0.750000) {
|
|
|
+ Toast.makeText(context, "检测到人脸:${faceDetRet},是同一个人", Toast.LENGTH_SHORT).show()
|
|
|
+ }else{
|
|
|
+ Toast.makeText(context, "检测到人脸:${faceDetRet},不是同一个人", Toast.LENGTH_SHORT).show()
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- })
|
|
|
}
|
|
|
|
|
|
|
|
@@ -346,13 +409,7 @@ class DialogValidateFace( mContext: Context) : FullScreenPopupView(mContext), IV
|
|
|
|
|
|
|
|
|
|
|
|
- context.lifecycleScope.launch {
|
|
|
- if(scores.isNotEmpty() && scores[0] > 0.750000) {
|
|
|
- Toast.makeText(context, "检测到人脸:${faceDetRet},是同一个人", Toast.LENGTH_SHORT).show()
|
|
|
- }else{
|
|
|
- Toast.makeText(context, "检测到人脸:${faceDetRet},不是同一个人", Toast.LENGTH_SHORT).show()
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|
|
@@ -472,9 +529,7 @@ class DialogValidateFace( mContext: Context) : FullScreenPopupView(mContext), IV
|
|
|
result.addListener({
|
|
|
try {
|
|
|
if (result.get().isFocusSuccessful) {
|
|
|
- mBinding.focusView.showFocusView(x.toInt(),y.toInt())
|
|
|
Log.d("demo", "聚集成功")
|
|
|
-
|
|
|
} else {
|
|
|
Log.d("demo", "聚集失败")
|
|
|
}
|