package com.basic.security.utils;
|
|
import android.graphics.Bitmap;
|
|
import com.basic.security.manager.BaseSettingManager;
|
import com.basic.security.manager.HintRecognizeManager;
|
|
import java.io.ByteArrayOutputStream;
|
import java.io.Serializable;
|
|
public class FacePosition implements Serializable {
|
public int x1;
|
public int y1;
|
public int x2;
|
public int y2;
|
public int yaw; // 左右角度
|
public int pitch; //
|
public int roll; //
|
public float score;
|
public long trackerId;
|
public boolean liveness;
|
public String featureName;
|
public byte[] featureData;
|
public long createTime;
|
public boolean allowPass;
|
public String allowPassIdentityName;
|
public double faceRatio;
|
public FaceTitleAndTips compareFeatureResult;
|
public DetectedResult detectedResult;
|
public Bitmap faceBitmap;
|
BitmapHolder bitmapHolder = new BitmapHolder();
|
private byte[] faceJpgData;
|
|
public byte[] faceJpgData() {
|
Bitmap frameBitmap = detectedResult.getFrameBitmap();
|
if (faceJpgData == null) {
|
cropImage();
|
}
|
return faceJpgData;
|
}
|
|
private byte[] cropImage() {
|
float ratio = 0.8f;
|
int enlargeWidth = (int) (ratio * (x2 - x1));
|
int enlargeHeight = (int) (ratio * (y2 - y1));
|
x1 = x1 - enlargeWidth / 2;
|
x2 = x2 + enlargeWidth / 2;
|
y1 = y1 - enlargeHeight / 2;
|
y2 = y2 + enlargeHeight / 2;
|
if (x1 < 0) {
|
x1 = 0;
|
}
|
if (y1 < 0) {
|
y1 = 0;
|
}
|
if (x2 > detectedResult.width) {
|
x2 = detectedResult.width;
|
}
|
if (y2 > detectedResult.height) {
|
y2 = detectedResult.height;
|
}
|
int width = (x2 - x1);
|
int height = (y2 - y1);
|
if (width > detectedResult.width) {
|
width = detectedResult.width;
|
}
|
if (height > detectedResult.height) {
|
height = detectedResult.height;
|
}
|
Bitmap bitmap = detectedResult.getFrameBitmap();
|
|
byte[] faceData = null;
|
if (bitmap != null) {
|
bitmapHolder.storeBitmap(bitmap);
|
bitmapHolder.cropBitmap(x1, y1, x2, y2);
|
faceBitmap = bitmapHolder.getBitmapAndFree();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
faceBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
|
faceData = stream.toByteArray();
|
|
// if (faceBitmap != null && !faceBitmap.isRecycled()) {
|
// faceBitmap.recycle();
|
// }
|
// faceBitmap = null;
|
// bitmap = null;
|
}
|
faceJpgData = faceData;
|
return faceData;
|
}
|
|
public boolean detectScoreCanRecognize() { // 已注册人员是否识别出来
|
return featureData != null && score >= 0.80;
|
}
|
|
|
public boolean detectScoreCanRecognize1() { // 已注册人员是否识别出来
|
return score >= 0.80;
|
}
|
|
public boolean detectScoreCanSignUp() { // 得分是否可以注册
|
// System.out.println("FacePosition.detectScoreCanSignUp score="+score);
|
if (Constants.isNewIDCardReader) {
|
boolean b = haveFaceAngleHintForSignUp() == null && score >= 0.80;
|
// System.out.println("FacePosition.detectScoreCanSignUp 1 " + b + " " + score);
|
return b;
|
}
|
boolean detectScoreCanSignUp = haveFaceAngleHintForSignUp() == null && score >= 0.95 && featureData != null;
|
if (detectScoreCanSignUp) {
|
System.out.println("FacePosition.detectScoreCanSignUp detectScoreCanSignUp=" + detectScoreCanSignUp + ", && featureData =" + featureData);
|
}
|
// System.out.println("FacePosition.detectScoreCanSignUp 1 " + detectScoreCanSignUp + " " + score);
|
return detectScoreCanSignUp;
|
}
|
|
public void readFaceFeature() {
|
try {
|
if (featureName != null && !"".equals(featureName)) {
|
featureData = FileUtil.readFile1(featureName);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
public String haveFaceAngleHintForSignUp() {
|
String haveFaceAngleHint = null;
|
try {
|
// BaseSettingManager.getFaceRatio() 根据设置的屏幕比,让人脸在设置的屏幕比+_0.2浮动
|
if (faceRatio > Double.parseDouble(BaseSettingManager.getFaceRatio()) + 0.2) {
|
// haveFaceAngleHint = HintRecognizeManager.getFaceMaxAngleMessage();
|
haveFaceAngleHint = "向后站";
|
} else if (faceRatio < Double.parseDouble(BaseSettingManager.getFaceRatio()) - 0.2) {
|
// haveFaceAngleHint = HintRecognizeManager.getFaceMinAngleMessage();
|
haveFaceAngleHint = "向前站";
|
} else if (yaw > HintRecognizeManager.getRightRotationAngle()) { //
|
haveFaceAngleHint = HintRecognizeManager.getRightRotationMessage();
|
} else if (yaw < HintRecognizeManager.getLeftRotationAngle()) {
|
haveFaceAngleHint = HintRecognizeManager.getLeftRotationMessage();
|
} else if (pitch > HintRecognizeManager.getHeadDownAngle()) { //
|
haveFaceAngleHint = HintRecognizeManager.getHeadUpAngleMessage();
|
} else if (pitch < HintRecognizeManager.getHeadUpAngle()) {
|
haveFaceAngleHint = HintRecognizeManager.getHeadDownAngleMessage();
|
} else if (roll > 10) {
|
haveFaceAngleHint = "请正脸对准摄像头";
|
} else if (roll < -10) {
|
haveFaceAngleHint = "请正脸对准摄像头";
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return haveFaceAngleHint;
|
}
|
}
|