ifengouy 2 years ago
parent
commit
7e53545a2b

+ 0 - 3
app/src/main/java/com/sunwin/visitorapp/activity/VisitSignActivity.java

@@ -2,8 +2,6 @@ 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;
@@ -18,7 +16,6 @@ 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;

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

@@ -22,7 +22,7 @@ import com.sunwin.visitorapp.adapter.DepartmentAdapter;
 import com.sunwin.visitorapp.adapter.NetInfoAdapter;
 import com.sunwin.visitorapp.db.DatabaseManager;
 import com.sunwin.visitorapp.db.UserInfoModel;
-import com.sunwin.visitorapp.face.SwFaceLoop;
+import com.sunwin.visitorapp.face.FRImpl;
 import com.sunwin.visitorapp.model.DepartmentResult;
 import com.sunwin.visitorapp.model.NetInfo;
 import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
@@ -262,7 +262,7 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
                     LogUtil.e(TAG, "--code--" + code);
                     if (code == 0) {
                         String personId = response.body().getResult();
-                        String faceToken = SwFaceLoop.getInstance().addFace(currentFacePath);
+                        String faceToken = FRImpl.getInstance().addFace(currentFacePath);
 
                         infoModel.setCategoryName(categoryName);
                         infoModel.setDeviceId(AppUtil.getDeviceId());

+ 2 - 2
app/src/main/java/com/sunwin/visitorapp/camera/CameraSurfaceView.java

@@ -15,7 +15,7 @@ import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 
 import com.guo.android_extend.tools.FrameHelper;
-import com.sunwin.visitorapp.face.SwFaceLoop;
+import com.sunwin.visitorapp.face.FRImpl;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.LogUtil;
 
@@ -212,7 +212,7 @@ public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Call
     }
 
     public void reStartCamera() {
-        SwFaceLoop.getInstance().recognizeTime =0;
+        FRImpl.getInstance().recognizeTime =0;
         openCamera();
         mCamera.setDisplayOrientation(Constant.rotate);
         mCamera.startPreview();

+ 3 - 116
app/src/main/java/com/sunwin/visitorapp/face/FRAbsLoop.java → app/src/main/java/com/sunwin/visitorapp/face/FRAbs.java

@@ -1,6 +1,5 @@
 package com.sunwin.visitorapp.face;
 
-import android.app.Activity;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -10,14 +9,11 @@ import android.graphics.YuvImage;
 import android.os.Environment;
 import android.util.Log;
 
-import com.guo.android_extend.java.AbsLoop;
 import com.guo.android_extend.java.ExtByteArrayOutputStream;
 import com.sunwin.visitorapp.model.UserModel;
 import com.sunwin.visitorapp.model.bus.DescEvent;
 import com.sunwin.visitorapp.utils.BitmapUtils;
 import com.sunwin.visitorapp.utils.Constant;
-import com.sunwin.visitorapp.utils.ConvertUtil;
-import com.sunwin.visitorapp.utils.SharePrefenceUtils;
 import com.zkteco.android.biometric.module.idcard.meta.IDCardInfo;
 
 import org.greenrobot.eventbus.EventBus;
@@ -25,34 +21,21 @@ import org.greenrobot.eventbus.EventBus;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
 
 /**
- * 集成引擎步骤:
- * 1. 实现抽象函数 initialEngine、onPreview、searchFaceLocally、uninitialEngine。
- * 2. 构造全局单例
- * <p>
- * Created by shitianci on 2018/7/6.
+ * 人脸feed 和recognize 抽线类
  */
+public abstract class FRAbs {
 
-public abstract class FRAbsLoop {
-
-    static final String TAG = FRAbsLoop.class.getSimpleName();
+    static final String TAG = FRAbs.class.getSimpleName();
 
     protected volatile IFaceInfo mCurFaceInfo; //当前正在处理的人脸信息
     public IDCardInfo idCardInfo;//刷身份证开门时的身份证信息
-    public UserModel userModel;//刷卡卡门时用户信息
-    public static int DETECTER_BACK_TYPE = 0; //后台同步提取的数据
     public static int DETECTER_FRONT_TYPE = 1;//前端提取的数据
 
     //初始化引擎
     public abstract void initialEngine(Context context);
 
-    //处理静态图片 ,返回人脸矩阵
-    public abstract List<Rect> faceDetection(Bitmap bitmap, int type);//加上类别,区分不同的特征提取
-
-    public Activity currentActivity;
 
     /**
      * 检测文件是否有人脸,有则返回bitmap, 否则返回null;
@@ -68,33 +51,9 @@ public abstract class FRAbsLoop {
         return null;
     }
 
-//    //识别人脸
-//    public OpenDoorByFaceNetResultInfo searchFaceLocally(byte[] imageNV21, Rect rect, String face_image) {
-//        OpenDoorByFaceNetResultInfo openDoorByFaceNetResultInfo = new OpenDoorByFaceNetResultInfo();
-//        openDoorByFaceNetResultInfo.setCode(-1);
-//        if (SpUtils.getBoolean("isIdNumberOpenDoor", false)) {
-//            if (idCardInfo == null) {
-//                openDoorByFaceNetResultInfo.setMessage(DescEvent.DESC_FR_TIP_2);
-//            } else {
-//                openDoorByFaceNetResultInfo.setMessage(DescEvent.DESC_FR_TIP);
-//            }
-//
-//        } else if (SpUtils.getBoolean("iscardCheckFace", false)) {
-//            openDoorByFaceNetResultInfo.setMessage(DescEvent.DESC_NEED_FLUSH_CARD);
-//        } else {
-//            openDoorByFaceNetResultInfo.setMessage(DescEvent.DESC_FR_TIP);
-//        }
-//
-//
-//        return openDoorByFaceNetResultInfo;
-//    }
-
     //保存人脸
     public abstract void saveFace(UserModel userModel);
 
-    public void editSaveFace(UserModel userModel) {
-    }
-
 
     //销毁引擎
     public abstract void uninitialEngine();
@@ -108,7 +67,6 @@ public abstract class FRAbsLoop {
 
 
     public void searchFace() {
-//        Log.e(TAG, "进入人脸检索");
         if (mS_BeforeSearchFace == 0L) {
 
         } else {
@@ -183,41 +141,10 @@ public abstract class FRAbsLoop {
 
 
         bitmap = BitmapUtils.scaleBitmap(bitmap, 200, 200);
-
-//                bitmap = BitmapUtils.toGrayscale(BitmapUtils.scaleBitmap(bitmap, 96, 112));
-//
-//        final OpenDoorByFaceNetResultInfo openDoorByFaceNetResultInfo;
-//        final String face_image = ConvertUtil.bitmapToBase64(bitmap);
-//
-//        //本地识别
-//        openDoorByFaceNetResultInfo = searchFaceLocally(imageNV21, rect, face_image);
-//
-//
-////        Log.d(TAG, "OpenDoorByFaceNetResultInfo:" + openDoorByFaceNetResultInfo.toString());
-//        if (openDoorByFaceNetResultInfo.getCode() == 0) {
-//            EventBus.getDefault().post(new DescEvent().setDesc(DescEvent.DESC_FR_SUCC).setOpenDoorByFaceNetResultInfo(openDoorByFaceNetResultInfo));
-//            //成功了休眠
-//            try {
-//                sleep(Constant.NumerValue.TIME_CLOSE_DIALOG);
-//            } catch (InterruptedException e) {
-//                e.printStackTrace();
-//            }
-//            stopVerify();
-//            //TODO 放在识别线程,影响识别效率,需要移走
-////            uploadImageNV21(yuv, openDoorByFaceNetResultInfo.getPerson_name()
-////                    + "-" + openDoorByFaceNetResultInfo.getPerson_code()
-////                    + "-" + TimeUtil.longToString(System.currentTimeMillis(), "yyyyMMddHHmmss") + ".jpg");
-//        } else {
-//            //抛出失败原因
-//            EventBus.getDefault().post(new DescEvent().setDesc(openDoorByFaceNetResultInfo.getMessage()));
-//        }
-
-
         mCurFaceInfo = null;
         bmp.recycle();
         bitmap.recycle();
         startVerify();
-//        EventBus.getDefault().post(new DescEvent().setDesc(DescEvent.DESC_FR_TIP));
 
     }
 
@@ -250,21 +177,7 @@ public abstract class FRAbsLoop {
         }
         return pictureFile;
     }
-/*
-    //上传 imageNV21
-    private void uploadImageNV21(YuvImage yuv, String fileName) {
-        Rect rect = new Rect(0, 0, yuv.getWidth(), yuv.getHeight());
-        final File pictureFile = saveImageNV21(yuv, rect, 100, fileName);
-        List<String> paths = new ArrayList<>();
-        paths.add(pictureFile.getAbsolutePath());
-        RepositoryCollection.uploadFaceImg(paths);
-        pictureFile.delete();
-    }*/
-
-
-    public void over() {
 
-    }
 
     public void start() {
 
@@ -294,27 +207,10 @@ public abstract class FRAbsLoop {
      * @param mHeight 高度
      */
     public void setWH(int mWidth, int mHeight) {
-//        Log.d(TAG, "setWH: " + mWidth + "*"+ mHeight);
         this.mWidth = mWidth;
         this.mHeight = mHeight;
     }
 
-    /**
-     * 摄像线程:不断处理摄像数据,返回人脸框,同时将 人脸信息(图片、人脸框、特征值) 传给人像搜索线程。
-     *
-     * @param object
-     */
-    public synchronized void pushFaceInfo(IFaceInfo object) {
-        mCurFaceInfo = object;
-//        saveImageNV21(object.getImage(), mWidth, mHeight, object.getImageRect(), 100,TimeUtil.longToString(System.currentTimeMillis(), "yyyyMMddHHmmss") + "检测" + ".jpg");
-
-        if (mS_BeforeSearchFace == 0L) {
-            mS_BeforeSearchFace = System.currentTimeMillis();
-        } else {
-            Log.e(TAG, "走到这里,意味着两个线程对于mImageNV21的处理出问题了");
-        }
-    }
-
 
     /**
      * sdk 初始化是否成功
@@ -323,14 +219,5 @@ public abstract class FRAbsLoop {
         return false;
     }
 
-    /**
-     * 异步提取特征
-     */
-    public void saveToFavemodel(Bitmap bitmap) {
-
-    }
-    public Bitmap cropFace(Bitmap bitmap){
-        return bitmap;
-    }
 
 }

+ 3 - 3
app/src/main/java/com/sunwin/visitorapp/face/FRAbsLoopFactory.java

@@ -6,14 +6,14 @@ public class FRAbsLoopFactory implements FaceDecterFactory {
 
 
     @Override
-    public FRAbsLoop createFRAblLoop(Context context, int type) {
-        FRAbsLoop frAbsLoop=null;
+    public FRAbs createFRAblLoop(Context context, int type) {
+        FRAbs frAbsLoop=null;
         switch (type) {
             case 0:
 //                frAbsLoop= IdFaceAbsLoop.getInstance();
                 break;
             case 1:
-                frAbsLoop= SwFaceLoop.getInstance();
+                frAbsLoop= FRImpl.getInstance();
                 break;
         }
         return frAbsLoop;

+ 9 - 15
app/src/main/java/com/sunwin/visitorapp/face/SwFaceLoop.java → app/src/main/java/com/sunwin/visitorapp/face/FRImpl.java

@@ -47,11 +47,12 @@ import mcv.facepass.types.FacePassRecognitionResult;
 import mcv.facepass.types.FacePassRecognitionState;
 import mcv.facepass.types.FacePassTrackOptions;
 
-
-public class SwFaceLoop extends FRAbsLoop {
+/**
+ * 人脸feed 和recogize处理、facapasssdk初始化
+ */
+public class FRImpl extends FRAbs {
     private static final String DEBUG_TAG = "SwFaceLoop";
-    public static boolean shouldStop = false;
-    private static SwFaceLoop mSwFaceLoop;
+    private static FRImpl mSwFaceLoop;
     private FacePassHandler mFacePassHandler;
     private boolean isLocalGroupExist;
     private NV21ToBitmap nV21ToBitmap;
@@ -64,15 +65,15 @@ public class SwFaceLoop extends FRAbsLoop {
 
     private String group_name = "facepass";
 
-    public SwFaceLoop(Context context) {
+    public FRImpl(Context context) {
         initialEngine(context);
     }
 
-    public static SwFaceLoop getInstance() {
+    public static FRImpl getInstance() {
         if (mSwFaceLoop == null) {
-            synchronized (SwFaceLoop.class) {
+            synchronized (FRImpl.class) {
                 if (mSwFaceLoop == null) {
-                    mSwFaceLoop = new SwFaceLoop(BaseApplication.getInstance());
+                    mSwFaceLoop = new FRImpl(BaseApplication.getInstance());
                 }
             }
         }
@@ -207,10 +208,6 @@ public class SwFaceLoop extends FRAbsLoop {
         }
     }
 
-    @Override
-    public List<Rect> faceDetection(Bitmap bitmap, int type) {
-        return null;
-    }
 
     @Override
     public boolean detectFace(File file, int type) {
@@ -236,9 +233,6 @@ public class SwFaceLoop extends FRAbsLoop {
 
     @Override
     public void searchFace() {
-        if (shouldStop) {
-            return;
-        }
         oneDetect();
 
     }

+ 1 - 1
app/src/main/java/com/sunwin/visitorapp/face/FaceDecterFactory.java

@@ -8,5 +8,5 @@ import android.content.Context;
  * create at 2018/9/20 0020 下午 7:16
  */
 interface FaceDecterFactory {
-    FRAbsLoop createFRAblLoop(Context context, int type);
+    FRAbs createFRAblLoop(Context context, int type);
 }

+ 2 - 2
app/src/main/java/com/sunwin/visitorapp/face/IDCardReaderUtil.java

@@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit;
 public class IDCardReaderUtil implements Runnable {
 
     private static final String TAG = "IDCardReaderUtil";
-    private final FRAbsLoop mFRAbsLoop;
+    private final FRAbs mFRAbsLoop;
     private Context mContext;
     private Thread childThread;
     private boolean stopRead;
@@ -140,7 +140,7 @@ public class IDCardReaderUtil implements Runnable {
                             mAuthentticaImagePath = dirPath + fileName;
                             Bitmap bitmap = IDPhotoHelper.Bgr2Bitmap(buf);
                             BitmapUtils.saveJPGE_After(mContext, bitmap, mAuthentticaImagePath, 100);
-                            mFRAbsLoop.detectFace(new File(mAuthentticaImagePath), FRAbsLoop.DETECTER_FRONT_TYPE);
+                            mFRAbsLoop.detectFace(new File(mAuthentticaImagePath), FRAbs.DETECTER_FRONT_TYPE);
                             mFRAbsLoop.idCardInfo = idCardInfo;
                             if (mContext != null) {
                                 LogUtil.e("detecterView", idCardInfo.getName());

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

@@ -17,7 +17,7 @@ import com.sunwin.visitorapp.R;
 import com.sunwin.visitorapp.camera.CameraHolder;
 import com.sunwin.visitorapp.camera.CameraSurfaceView;
 import com.sunwin.visitorapp.face.CameraPreviewData;
-import com.sunwin.visitorapp.face.FRAbsLoop;
+import com.sunwin.visitorapp.face.FRAbs;
 import com.sunwin.visitorapp.face.FRAbsLoopFactory;
 import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
 import com.sunwin.visitorapp.model.bus.DescEvent;
@@ -123,7 +123,7 @@ public class FaceDetecterView extends RelativeLayout {
     }
 
 
-    FRAbsLoop mFRAbsLoop = null;
+    FRAbs mFRAbsLoop = null;
 
     public void config(Activity activity, Listener listener) {
         View view = View.inflate(activity, R.layout.view_face_detecter, this);