|
@@ -0,0 +1,252 @@
|
|
|
+package com.sunwin.visitorapp.fragment;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.media.ExifInterface;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.appcompat.app.AlertDialog;
|
|
|
+
|
|
|
+import com.baidu.ai.cameraui.IDcardCardActivity;
|
|
|
+import com.baidu.ai.cameraui.parameter.BaseParameter;
|
|
|
+import com.baidu.vis.general.IdcardModel;
|
|
|
+import com.baidu.vis.general.Predictor;
|
|
|
+import com.baidu.vis.general.SDKExceptions;
|
|
|
+import com.sunwin.visitorapp.BaseApplication;
|
|
|
+import com.sunwin.visitorapp.MainActivity;
|
|
|
+import com.sunwin.visitorapp.R;
|
|
|
+import com.sunwin.visitorapp.activity.VisitorRegisterAc;
|
|
|
+import com.sunwin.visitorapp.baidu.IDCardReadActivity;
|
|
|
+import com.sunwin.visitorapp.db.BlackUserModel;
|
|
|
+import com.sunwin.visitorapp.db.DatabaseManager;
|
|
|
+import com.sunwin.visitorapp.face.CameraPreviewData;
|
|
|
+import com.sunwin.visitorapp.face.FRImpl;
|
|
|
+import com.sunwin.visitorapp.model.MyIDCardInfo;
|
|
|
+import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
|
|
|
+import com.sunwin.visitorapp.utils.Constant;
|
|
|
+import com.sunwin.visitorapp.utils.FileUtil;
|
|
|
+import com.sunwin.visitorapp.utils.ImageUtil;
|
|
|
+import com.sunwin.visitorapp.utils.LogUtil;
|
|
|
+import com.sunwin.visitorapp.utils.PhotoUtil;
|
|
|
+import com.sunwin.visitorapp.view.FaceDetecterView;
|
|
|
+import com.zkteco.android.biometric.module.idcard.meta.IDCardInfo;
|
|
|
+
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.zkteco.android.biometric.core.utils.ToolUtils.getApplicationContext;
|
|
|
+
|
|
|
+public class OcrFragmnet extends BaseRegFragment implements View.OnClickListener, FaceDetecterView.Listener {
|
|
|
+
|
|
|
+
|
|
|
+ private LinearLayout mLlIdCardReg;
|
|
|
+ private ImageView mIv;
|
|
|
+ private TextView mTvAlum;
|
|
|
+ private TextView mTvPhoto;
|
|
|
+ private Bitmap snapShotBitmap;
|
|
|
+ private String outputFilePath;
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ @Override
|
|
|
+ public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
|
|
|
+
|
|
|
+ View view = inflater.inflate(R.layout.fragment_ocr_reg, container, false);
|
|
|
+
|
|
|
+
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
|
|
|
+ super.onViewCreated(view, savedInstanceState);
|
|
|
+ initView(view);
|
|
|
+ outputFilePath = getApplicationContext().getFilesDir() + "/output.jpg";
|
|
|
+ mFaceDetecterView.config(mContext, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView(@NotNull View view) {
|
|
|
+ mLlIdCardReg = view.findViewById(R.id.ll_id_card_reg);
|
|
|
+ mFaceDetecterView = view.findViewById(R.id.faceDetecterView);
|
|
|
+ mIv = view.findViewById(R.id.iv);
|
|
|
+ mTvAlum = view.findViewById(R.id.tv_alum);
|
|
|
+ mTvPhoto = view.findViewById(R.id.tv_photo);
|
|
|
+ mTvAlum.setOnClickListener(this);
|
|
|
+ mTvPhoto.setOnClickListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ String takePhotoPath;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.tv_alum:
|
|
|
+ PhotoUtil.openAlum(this, INTENT_CODE_PICK_IMAGE);
|
|
|
+ break;
|
|
|
+ case R.id.tv_photo:
|
|
|
+// takePhotoPath = PhotoUtil.takePicture(this, INTENT_CODE_CAMERA_IMAGE);
|
|
|
+
|
|
|
+ Intent intent = new Intent(mContext, IDCardReadActivity.class);
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putInt(BaseParameter.KEY_TAKE_PICTURE_TYPE, BaseParameter.TYPE_MANUAL);
|
|
|
+ bundle.putInt(BaseParameter.KEY_MASK_TYPE, BaseParameter.MASK_TYPE_IDCARD_FRONT);
|
|
|
+ bundle.putString(BaseParameter.KEY_OUTPUT_FILE_PATH, outputFilePath);
|
|
|
+ intent.putExtra(BaseParameter.KEY_MAIN, bundle);
|
|
|
+ startActivity(intent);
|
|
|
+// startActivityForResult(intent, CODE_GENERAL);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String idCrdPath;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (requestCode == INTENT_CODE_PICK_IMAGE) {
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ Uri uri = data.getData();
|
|
|
+ String path = FileUtil.getRealPathFromURI(mContext, uri);
|
|
|
+ Bitmap rotateBitmap = dealPic(path);
|
|
|
+ pictureFromAlbum(rotateBitmap);
|
|
|
+ } else {
|
|
|
+ // 取消的时候退出到的是预览界面
|
|
|
+// isToAlbumActivity = false;
|
|
|
+ }
|
|
|
+ } else if (requestCode == INTENT_CODE_CAMERA_IMAGE) {
|
|
|
+// loadingDialog.showLoadingDialog("");
|
|
|
+ LogUtil.debugLog("拍照path = " + takePhotoPath);
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ Bitmap bitmap = dealPic(takePhotoPath);
|
|
|
+ pictureFromAlbum(bitmap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Bitmap dealPic(String path) {
|
|
|
+ idCrdPath = path;
|
|
|
+ LogUtil.d(TAG, "pick image url: " + path);
|
|
|
+ Bitmap bitmap = FileUtil.getBitMapFromFile(path);
|
|
|
+ ExifInterface exif = null;
|
|
|
+ int exifRotation = 0;
|
|
|
+ try {
|
|
|
+ exif = new ExifInterface(path);
|
|
|
+ exifRotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
|
|
|
+ ExifInterface.ORIENTATION_NORMAL);
|
|
|
+ } catch (IOException e) {
|
|
|
+ LogUtil.e(TAG, "album selection picture get exif info error");
|
|
|
+ }
|
|
|
+
|
|
|
+ int rotation = ImageUtil.exifToDegrees(exifRotation);
|
|
|
+ Bitmap rotateBitmap = ImageUtil.createRotateBitmap(bitmap, rotation);
|
|
|
+ return rotateBitmap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void pictureFromAlbum(final Bitmap bitmap) {
|
|
|
+ snapShotBitmap = bitmap;
|
|
|
+ LogUtil.d(TAG, "albumSelectPictureSuccess");
|
|
|
+ mIv.setImageBitmap(bitmap);
|
|
|
+// changeToAction(true);
|
|
|
+// setCropBound();
|
|
|
+ onPictureProcess();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onPictureProcess() {
|
|
|
+ try {
|
|
|
+
|
|
|
+ int result = Predictor.getInstance().predict(snapShotBitmap);
|
|
|
+ if (result == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ IdcardModel resp = Predictor.getInstance().idcardDetection(1);
|
|
|
+ if (resp.nErrorCode != 0) {
|
|
|
+
|
|
|
+ LogUtil.e(TAG, "身份证质量异常,错误码:" + resp.nErrorCode);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LogUtil.e(TAG, "id:" + resp.number + "name:" + resp.name);
|
|
|
+ List<BlackUserModel> model = DatabaseManager.getInstance().query(BlackUserModel.class, "id_card_code", resp.number);
|
|
|
+ if (model.size() > 0) {
|
|
|
+ if (model.size() > 0) {
|
|
|
+ mContext.showBlackUserDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MyIDCardInfo idCardInfo = new MyIDCardInfo(new IDCardInfo(), resp.number, resp.name, idCrdPath);
|
|
|
+
|
|
|
+ FRImpl.getInstance().mMyIdCardInfo = idCardInfo;
|
|
|
+ mLlIdCardReg.setVisibility(View.GONE);
|
|
|
+ showTipDialog();
|
|
|
+ } catch (SDKExceptions.IlleagleLicense illeagleLicense) {
|
|
|
+ LogUtil.e(TAG, "SDKExceptions.IlleagleLicense:" + illeagleLicense);
|
|
|
+
|
|
|
+ } catch (SDKExceptions.NotInit notInit) {
|
|
|
+ LogUtil.e(TAG, "SDKExceptions.NotInit:" + notInit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showTipDialog() { // 创建退出对话框
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
|
|
+ builder.setTitle("温馨提示");
|
|
|
+ builder.setCancelable(false);
|
|
|
+ builder.setMessage("将对您的面部拍摄一张照片,用于人员信息录入,使用完成后会进行删除,不做保存。如同意请点击”确定“按钮");
|
|
|
+ builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ new Handler().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mFaceDetecterView.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ BaseApplication.getSystemTTS().playText("请看摄像头");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ mContext.finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void detectedFace() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void detectedUser(OpenDoorByFaceNetResultInfo info) {
|
|
|
+ BaseApplication.getSystemTTS().playText("识别成功");
|
|
|
+ Intent intent = new Intent(mContext, VisitorRegisterAc.class);
|
|
|
+ intent.putExtra(Constant.IIntentValue.CURRENTFACEPATH, info.getCurrentFace());
|
|
|
+ intent.putExtra(Constant.IIntentValue.RECOGNIZE_INFO, info);
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void detecterFail(String st) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void takePic(CameraPreviewData data) {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|