优化
This commit is contained in:
@@ -652,21 +652,53 @@ public class FaceHelper implements FaceListener {
|
||||
});
|
||||
}
|
||||
|
||||
private int failCount = 0;
|
||||
private long startTime = 0;
|
||||
|
||||
private void searchFace(final FaceFeature faceFeature, final Integer trackId) {
|
||||
CompareResult compareResult = FaceServer.getInstance().searchFaceFeature(faceFeature, frEngine);
|
||||
if (compareResult == null || compareResult.getFaceEntity() == null) {
|
||||
if (startTime == 0) {
|
||||
failCount = 0;
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
if (System.currentTimeMillis() - startTime > 10*1000) {
|
||||
failCount = 0;
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
failCount++;
|
||||
float similar;
|
||||
if (compareResult != null) {
|
||||
similar = compareResult.getSimilar();
|
||||
} else {
|
||||
similar = 0f;
|
||||
}
|
||||
// new Handler(Looper.getMainLooper()).post(()-> {
|
||||
// try {
|
||||
// Toast.makeText(App.getContext(),"识别失败"+failCount+"次,similar="+similar, Toast.LENGTH_SHORT).show();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
Log.d(TAG, "collectFace,searchFace查询失败"+failCount+"次,similar="+similar);
|
||||
if (failCount >= 2) {
|
||||
recognizeCallback.onRecognized(null, LivenessInfo.UNKNOWN, false);
|
||||
return;
|
||||
}
|
||||
retryRecognizeDelayed(trackId);
|
||||
return;
|
||||
}
|
||||
compareResult.setTrackId(trackId);
|
||||
boolean pass = compareResult.getSimilar() > recognizeConfiguration.getSimilarThreshold();
|
||||
compareResult.setSimilarPass(pass);
|
||||
Log.d(TAG, "collectFace,searchFace: pass="+pass+",similar="+compareResult.getSimilar()+",threshold="+recognizeConfiguration.getSimilarThreshold());
|
||||
recognizeCallback.onRecognized(compareResult, getRecognizeInfo(recognizeInfoMap, trackId).getLiveness(), pass);
|
||||
if (pass) {
|
||||
setName(trackId, "识别通过");
|
||||
noticeCurrentStatus("识别通过");
|
||||
changeRecognizeStatus(trackId, RequestFeatureStatus.SUCCEED);
|
||||
} else {
|
||||
noticeCurrentStatus("未通过:NOT_REGISTERED");
|
||||
noticeCurrentStatus("未通过:NOT_REGISTERED,"+compareResult.getSimilar());
|
||||
retryRecognizeDelayed(trackId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,12 @@ public class CompareResult {
|
||||
private int compareCode;
|
||||
private long cost;
|
||||
|
||||
private boolean similarPass;
|
||||
|
||||
public void setSimilarPass(boolean similarPass) {
|
||||
this.similarPass = similarPass;
|
||||
}
|
||||
|
||||
public CompareResult(FaceEntity faceEntity, float similar) {
|
||||
this.faceEntity = faceEntity;
|
||||
this.similar = similar;
|
||||
|
||||
@@ -45,10 +45,15 @@ public class FaceEntity implements Parcelable {
|
||||
@ColumnInfo(name = "register_time")
|
||||
private long registerTime;
|
||||
/**
|
||||
* 用户类型:1-普通会员、2-临时用户、3-内部员工、或者其它待定类型
|
||||
* 用户类型:1-普通会员、2-临时用户、或者其它待定类型
|
||||
*/
|
||||
@ColumnInfo(name = "user_type")
|
||||
private String userType;
|
||||
/**
|
||||
* 会员编号
|
||||
*/
|
||||
@ColumnInfo(name = "cardNo")
|
||||
private String cardNo;
|
||||
|
||||
@Ignore
|
||||
private int trackId;//人脸追踪ID
|
||||
@@ -66,6 +71,8 @@ public class FaceEntity implements Parcelable {
|
||||
this.imagePath = faceEntity.imagePath;
|
||||
this.featureData = faceEntity.featureData;
|
||||
this.registerTime = faceEntity.registerTime;
|
||||
this.userType = faceEntity.getUserType();
|
||||
this.cardNo = faceEntity.getCardNo();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +82,8 @@ public class FaceEntity implements Parcelable {
|
||||
userName = in.readString();
|
||||
imagePath = in.readString();
|
||||
featureData = in.createByteArray();
|
||||
userType = in.readString();
|
||||
cardNo = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<FaceEntity> CREATOR = new Creator<FaceEntity>() {
|
||||
@@ -145,6 +154,16 @@ public class FaceEntity implements Parcelable {
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public String getCardNo() {
|
||||
return cardNo;
|
||||
}
|
||||
|
||||
public void setCardNo(String cardNo) {
|
||||
this.cardNo = cardNo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
@@ -158,10 +177,9 @@ public class FaceEntity implements Parcelable {
|
||||
dest.writeString(imagePath);
|
||||
dest.writeByteArray(featureData);
|
||||
dest.writeString(userType);
|
||||
dest.writeString(cardNo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
@@ -176,12 +194,13 @@ public class FaceEntity implements Parcelable {
|
||||
TextUtils.equals(this.userName, that.userName) &&
|
||||
TextUtils.equals(this.imagePath, that.imagePath) &&
|
||||
Arrays.equals(featureData, that.featureData) &&
|
||||
TextUtils.equals(this.userType, that.userType);
|
||||
TextUtils.equals(this.userType, that.userType) &&
|
||||
TextUtils.equals(this.cardNo, that.cardNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = Objects.hash(faceId, registerTime, userName, imagePath, userType);
|
||||
int result = Objects.hash(faceId, registerTime, userName, imagePath, userType, cardNo);
|
||||
result = 31 * result + Arrays.hashCode(featureData);
|
||||
return result;
|
||||
}
|
||||
|
||||
+15
-6
@@ -283,8 +283,8 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
||||
);
|
||||
}
|
||||
// 填入在设置界面设置好的配置信息
|
||||
boolean enableLive = !ConfigUtil.getLivenessDetectType(context).equals(context.getString(R.string.value_liveness_type_disable));
|
||||
// enableLive = false;
|
||||
// boolean enableLive = !ConfigUtil.getLivenessDetectType(context).equals(context.getString(R.string.value_liveness_type_disable));
|
||||
boolean enableLive = false;
|
||||
boolean enableFaceQualityDetect = ConfigUtil.isEnableImageQualityDetect(context);
|
||||
boolean enableFaceMoveLimit = ConfigUtil.isEnableFaceMoveLimit(context);
|
||||
boolean enableFaceSizeLimit = ConfigUtil.isEnableFaceSizeLimit(context);
|
||||
@@ -472,13 +472,20 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
||||
}
|
||||
}
|
||||
|
||||
private String getUserId(CompareResult result) {
|
||||
if (result != null && result.getFaceEntity() != null) {
|
||||
return result.getFaceEntity().getUserName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecognized(CompareResult compareResult, Integer live, boolean similarPass) {
|
||||
Disposable disposable = Observable.just(true).observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
|
||||
// TODO: 2026/1/21 测试使用 Observable.just(similarPass)代替Observable.just(true)---
|
||||
Observable.just(similarPass).observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
|
||||
Log.d(TAG, "collectFace,onRecognized: similarPass=" + similarPass + ",live=" + live + ",userId=" + getUserId(compareResult));
|
||||
if (similarPass) {
|
||||
if (recognizeUserId != null) {
|
||||
recognizeUserId.postValue(compareResult);
|
||||
}
|
||||
recognizeUserId.postValue(compareResult);
|
||||
boolean isAdded = false;
|
||||
List<CompareResult> compareResults = compareResultList.getValue();
|
||||
if (compareResults != null && !compareResults.isEmpty()) {
|
||||
@@ -500,6 +507,8 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
||||
getFaceItemEventMutableLiveData().postValue(new FaceItemEvent(compareResults.size() - 1, EventType.INSERTED));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
recognizeUserId.postValue(compareResult);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user