Prechádzať zdrojové kódy

存储图片路径更改,解决删除图片文件夹存入文件失败问题
增加黑名单访问提醒
识别失败播报频率过快问题
其他优化

ifengouy 2 rokov pred
rodič
commit
461e1d1198

+ 1 - 0
app/src/main/java/com/sunwin/visitorapp/SplashActivity.java

@@ -120,6 +120,7 @@ public class SplashActivity extends AppCompatActivity {
         String content = "";
         try {
             InputStream instream = context.getAssets().open("CBG_Android_Face_Reco---36502-Formal-one-stage.cert");
+//            InputStream instream = context.getAssets().open("2_CBG_Android_Face_Reco---30-Trial-one-stage.cert");
             if (instream != null) {
                 InputStreamReader inputreader = new InputStreamReader(instream);
                 String line;

+ 0 - 1
app/src/main/java/com/sunwin/visitorapp/activity/NoCardRegActivity.java

@@ -35,7 +35,6 @@ public class NoCardRegActivity extends BaseActivity implements View.OnClickListe
         mTvHeadTitle = (TextView) findViewById(R.id.tv_head_title);
         findViewById(R.id.head_iv_back).setOnClickListener(this);
         mTvHeadTitle.setText("访客登记");
-        BaseApplication.getSystemTTS().playText("请看摄像头");
         getSupportFragmentManager().beginTransaction().add(R.id.fl_content,
                  NoCardRegFragment.newInstance(currentFacePath,userInfo)).commit();
     }

+ 10 - 0
app/src/main/java/com/sunwin/visitorapp/activity/VisitInputActivity.java

@@ -8,12 +8,17 @@ import android.widget.Button;
 import android.widget.EditText;
 
 import com.sunwin.visitorapp.BaseActivity;
+import com.sunwin.visitorapp.BaseApplication;
 import com.sunwin.visitorapp.R;
+import com.sunwin.visitorapp.db.BlackUserModel;
+import com.sunwin.visitorapp.db.DatabaseManager;
 import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.ToastUtils;
 import com.sunwin.visitorapp.view.UINav;
 
+import java.util.List;
+
 public class VisitInputActivity extends BaseActivity implements View.OnClickListener {
     private UINav mUINav;
     private EditText mEditName;
@@ -59,6 +64,11 @@ public class VisitInputActivity extends BaseActivity implements View.OnClickList
             ToastUtils.showToast("身份证号长度错误");
             return;
         }
+        List<BlackUserModel> model = DatabaseManager.getInstance().query(BlackUserModel.class, "id_card_code", idNum);
+        if (model.size() > 0) {
+            BaseApplication.getSystemTTS().playText("黑名单用户");
+        }
+
         OpenDoorByFaceNetResultInfo info = new OpenDoorByFaceNetResultInfo();
         info.setIdNum(idNum);
         info.setPerson_name(name);

+ 16 - 2
app/src/main/java/com/sunwin/visitorapp/activity/VisitSignActivity.java

@@ -2,6 +2,8 @@ package com.sunwin.visitorapp.activity;
 
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
 import android.text.TextUtils;
 import android.view.View;
 import android.widget.LinearLayout;
@@ -10,11 +12,13 @@ import android.widget.TextView;
 import com.sunwin.visitorapp.BaseActivity;
 import com.sunwin.visitorapp.BaseApplication;
 import com.sunwin.visitorapp.R;
+import com.sunwin.visitorapp.db.BlackUserModel;
 import com.sunwin.visitorapp.db.DatabaseManager;
 import com.sunwin.visitorapp.db.UserInfoModel;
 import com.sunwin.visitorapp.face.CameraPreviewData;
 import com.sunwin.visitorapp.face.IDCardReaderUtil;
 import com.sunwin.visitorapp.face.IdCardReadCallback;
+import com.sunwin.visitorapp.face.SwFaceLoop;
 import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
 import com.sunwin.visitorapp.model.UploadRecordRequsetModel;
 import com.sunwin.visitorapp.net.ApiService;
@@ -69,6 +73,11 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
         mFaceDetecterView.onDestroy();
     }
 
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+    }
+
     private void initialData() {
         visitSignType = getIntent().getIntExtra(Constant.IIntentValue.VISIT_SIGN_TYPE, 1);
         visitType = getIntent().getIntExtra(Constant.IIntentValue.VISIT_TYPE, 1);
@@ -100,6 +109,11 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
     }
 
     private void updataUserInfoByIdNum(String idNum, int type) {
+        List<BlackUserModel> model = DatabaseManager.getInstance().query(BlackUserModel.class, "id_card_code", idNum);
+        if (model.size() > 0) {
+            BaseApplication.getSystemTTS().playText("黑名单用户");
+        }
+
         List<UserInfoModel> userInfoModels = DatabaseManager.getInstance().query(UserInfoModel.class, "idNum", idNum);
         updateUserInfo(userInfoModels);
         updateRecord(userInfoModels, type);
@@ -198,6 +212,7 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
     @Override
     public void detectedUser(OpenDoorByFaceNetResultInfo openDoorByFaceNetResultInfo) {
         LogUtil.e(TAG, "-------------detectedUser--------------");
+
         BaseApplication.getSystemTTS().playText("识别成功");
         String idNum = openDoorByFaceNetResultInfo.getIdNum();
         currentFace = openDoorByFaceNetResultInfo.getCurrentFace();
@@ -208,7 +223,7 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
 
     @Override
     public void detecterFail(String st) {
-
+        BaseApplication.getSystemTTS().playText(st);
     }
 
     @Override
@@ -241,5 +256,4 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
             });
         }
     }
-
 }

+ 0 - 32
app/src/main/java/com/sunwin/visitorapp/face/FRAbsLoop.java

@@ -100,7 +100,6 @@ public abstract class FRAbsLoop {
     public abstract void uninitialEngine();
 
     public volatile boolean isCanVerify; //是否能进行识别,弹窗的时候就暂停抓取图片识别
-    public volatile boolean isVerifying; //是否正在识别
     public volatile boolean isTimeWrong; //是否正在识别
 
     int mWidth;
@@ -108,33 +107,6 @@ public abstract class FRAbsLoop {
     private long mS_BeforeSearchFace; //统计 检测到人脸,到执行searchFace 的时间
 
 
-
-    public void setup() {
-    }
-
-
-    public void loop() {
-        if (!isCanVerify) {
-            Log.w(TAG, "弹窗时,不需要进行识别");
-            return;
-        }
-        if (isVerifying) {
-//            Log.w(TAG, "正在识别中");
-            return;
-        }
-        if (mCurFaceInfo == null) {
-//            Log.w(TAG,"没有检测到人脸");
-            return;
-        }
-
-
-        synchronized (FRAbsLoop.class) {
-            isVerifying = true;
-            searchFace();
-        }
-    }
-
-
     public void searchFace() {
 //        Log.e(TAG, "进入人脸检索");
         if (mS_BeforeSearchFace == 0L) {
@@ -152,7 +124,6 @@ public abstract class FRAbsLoop {
         if (imageNV21 == null) {
             Log.e(TAG, "走到这里,意味着数据冲突了");
 //            EventBus.getDefault().post(new DescEvent().setDesc("数据遗失"));
-            isVerifying = false;
             try {
                 Thread.sleep(2000);
             } catch (InterruptedException e) {
@@ -179,7 +150,6 @@ public abstract class FRAbsLoop {
         } catch (Exception e) {
             e.printStackTrace();
             mCurFaceInfo = null;
-            isVerifying = false;
             return;
         }
 
@@ -188,7 +158,6 @@ public abstract class FRAbsLoop {
         Bitmap bmp = BitmapFactory.decodeByteArray(ops.getByteArray(), 0, ops.getByteArray().length);
         if (bmp == null) {
             mCurFaceInfo = null;
-            isVerifying = false;
             return;
         }
         try {
@@ -310,7 +279,6 @@ public abstract class FRAbsLoop {
     public void startVerify() {
         Log.d(TAG, "startVerify");
         isCanVerify = true;
-        isVerifying = false;
     }
 
 

+ 5 - 7
app/src/main/java/com/sunwin/visitorapp/face/SwFaceLoop.java

@@ -323,10 +323,6 @@ public class SwFaceLoop extends FRAbsLoop {
                     if (isTimeWrong) {
                         Thread.sleep(1000);
                     }
-                    if (isVerifying) {
-                        Thread.sleep(100);
-                        continue;
-                    }
 
                 } catch (InterruptedException e) {
                     e.printStackTrace();
@@ -446,12 +442,14 @@ public class SwFaceLoop extends FRAbsLoop {
 
     private void recognizeFail() {
         ++recognizeTime;
-        LogUtil.e(TAG, "recognizeFail==========================recognizeTime = " + recognizeTime);
+        LogUtil.d(TAG, "recognizeFail==========================recognizeTime = " + recognizeTime);
         if (recognizeTime == Constant.COMPARSION_FREQUENCY) {
+            LogUtil.e(TAG, "recognizeFail==========send================recognizeTime = " + recognizeTime);
             EventBus.getDefault().post(new DescEvent().setDesc(DescEvent.DESC_FR_NO_BODY));
             recognizeTime = 0;
+        } else {
+            resetTraceId();
         }
-        resetTraceId();
     }
 
     private void idCardRecognite(DetectResult detectResult) {
@@ -530,7 +528,7 @@ public class SwFaceLoop extends FRAbsLoop {
             if (result != null) {
                 if (result.result == 0) {
                     boolean b = mFacePassHandler.bindGroup(group_name, result.faceToken);
-                    LogUtil.e(TAG, "bindGroup: " + currentFacePath + ":" + b+",token="+ new String(result.faceToken));
+                    LogUtil.e(TAG, "bindGroup: " + currentFacePath + ":" + b + ",token=" + new String(result.faceToken));
                     return new String(result.faceToken);
                 }
             }

+ 12 - 0
app/src/main/java/com/sunwin/visitorapp/fragment/IdcardRegFragment.java

@@ -14,6 +14,8 @@ import com.sunwin.visitorapp.BaseApplication;
 import com.sunwin.visitorapp.BaseFragment;
 import com.sunwin.visitorapp.R;
 import com.sunwin.visitorapp.activity.VisitorRegisterAc;
+import com.sunwin.visitorapp.db.BlackUserModel;
+import com.sunwin.visitorapp.db.DatabaseManager;
 import com.sunwin.visitorapp.face.CameraPreviewData;
 import com.sunwin.visitorapp.face.IDCardReaderUtil;
 import com.sunwin.visitorapp.face.IdCardReadCallback;
@@ -26,6 +28,8 @@ import com.sunwin.visitorapp.view.FaceDetecterView;
 
 import org.jetbrains.annotations.NotNull;
 
+import java.util.List;
+
 /**
  * 身份证登记 fragment
  */
@@ -73,18 +77,26 @@ public class IdcardRegFragment extends BaseFragment implements IdCardReadCallbac
         mLlIdCardReg = view.findViewById(R.id.ll_id_card_reg);
         mFaceDetecterView = view.findViewById(R.id.faceDetecterView);
     }
+
     private String mCardPath;
+
     @Override
     public void onIdNumRead(String idNum, String mAuthentticaImagePath) {
         LogUtil.e(TAG, "idNum = " + idNum);
         mCardPath = mAuthentticaImagePath;
+        List<BlackUserModel> model = DatabaseManager.getInstance().query(BlackUserModel.class, "id_card_code", idNum);
+
         //读取身份证后显示人脸扫描框
         if (isAdded())
             mContext.runOnUiThread(new Runnable() {
                 @Override
                 public void run() {
+                    if (model.size() > 0) {
+                        BaseApplication.getSystemTTS().playText("黑名单用户");
+                    }
                     mLlIdCardReg.setVisibility(View.GONE);
                     ToastUtils.showToast(getString(R.string.have_readed_id_card));
+                    BaseApplication.getSystemTTS().playText(getString(R.string.have_readed_id_card));
                     mFaceDetecterView.setVisibility(View.VISIBLE);
                 }
             });

+ 6 - 1
app/src/main/java/com/sunwin/visitorapp/fragment/NoCardRegFragment.java

@@ -90,7 +90,12 @@ public class NoCardRegFragment extends BaseFragment implements FaceDetecterView.
         builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
-                mFaceDetecterView.needTakePic = true;
+               new Handler().postDelayed(new Runnable() {
+                   @Override
+                   public void run() {
+                       mFaceDetecterView.needTakePic = true;
+                   }
+               },1000);
                 BaseApplication.getSystemTTS().playText("请看摄像头");
             }
         });

+ 2 - 0
app/src/main/java/com/sunwin/visitorapp/utils/AppUtil.java

@@ -9,6 +9,8 @@ import java.math.BigDecimal;
 public class AppUtil {
     public static String getPackageName(){
         return BaseApplication.getInstance().getPackageName();
+    }public static String getFileDir(){
+        return BaseApplication.getInstance().getFilesDir().getPath();
     }
 
     public  static String getDeviceId(){

+ 1 - 1
app/src/main/java/com/sunwin/visitorapp/utils/Constant.java

@@ -24,7 +24,7 @@ public class Constant {
     public static final String SWBINDIR = "/sdcard/models";
     public static final String SWRECODE = "/sdcard/swRecode";
 
-    public static final String RecognitionDir = Environment.getExternalStorageDirectory() + "/faceRecognition/"; //记录图片存储位置
+    public static final String RecognitionDir = /*Environment.getExternalStorageDirectory() +*/ AppUtil.getFileDir()+"/"; //记录图片存储位置
 
     public static volatile boolean isReConnectUsb = false;//是否重新连接
 

+ 4 - 4
app/src/main/java/com/sunwin/visitorapp/view/FaceDetecterView.java

@@ -223,17 +223,17 @@ public class FaceDetecterView extends RelativeLayout {
         } else if (event.getDesc().equalsIgnoreCase(DescEvent.DESC_FR_TIP_2)) {
         } else if (event.getDesc().equalsIgnoreCase(DescEvent.DESC_FR_NO_BODY)) {
             isCanFlush = true;
-            BaseApplication.getSystemTTS().playText(event.getDesc());
             if (mListener != null) {
                 mListener.detecterFail(event.getDesc());
-
             }
         } else if (event.getDesc().equalsIgnoreCase(DescEvent.DESC_FR_FROCUSE_EYE)) {
             BaseApplication.getSystemTTS().playText(event.getDesc());
         } else if (event.getDesc().equalsIgnoreCase(DescEvent.DESC_TAKE_PIC)) {
             if (needTakePic) {
-                needTakePic = false;
-                mListener.takePic(event.getCameraPreviewData());
+                if (mListener != null) {
+                    needTakePic = false;
+                    mListener.takePic(event.getCameraPreviewData());
+                }
             }
         }
     }