package com.basic.security.utils;
|
|
import android.graphics.Bitmap;
|
import android.graphics.BitmapFactory;
|
import android.graphics.ImageFormat;
|
import android.graphics.Rect;
|
import android.graphics.YuvImage;
|
|
import java.io.ByteArrayOutputStream;
|
import java.io.Serializable;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
public class DetectedResult implements Serializable {
|
|
public byte[] originalCameraData = null;
|
public boolean originalCameraDataChanged;
|
|
public List<FacePosition> facePositions = new ArrayList<>();
|
public byte[] frameJpgData;
|
public byte[] bgrData;
|
public int width;
|
public int height;
|
public String resultText;
|
public int featureCount = 0;
|
public boolean isRgb;
|
public boolean shouldExtractFeature;
|
public Bitmap frameBitmap;
|
|
public boolean stranger = false;
|
|
public byte[] nv21Array;
|
ByteArrayOutputStream jpgBaos = new ByteArrayOutputStream();
|
static RenderScriptHelper renderScriptHelper = new RenderScriptHelper();
|
static Object renderScriptHelperLock = new Object();
|
|
public Bitmap getFrameBitmap() {
|
if (frameBitmap == null) {
|
if (nv21Array != null) {
|
synchronized (renderScriptHelperLock) {
|
frameBitmap = renderScriptHelper.getBitmapFromFrameData(nv21Array, width, height);
|
}
|
// YuvImage im = new YuvImage(nv21Array, ImageFormat.NV21, width,
|
// height, null);
|
// Rect r = new Rect(0, 0, width, height);
|
// jpgBaos.reset();
|
// im.compressToJpeg(r, 100, jpgBaos);
|
// byte[] jpgByteArray = jpgBaos.toByteArray();
|
// frameBitmap = BitmapFactory.decodeByteArray(jpgByteArray, 0, jpgBaos.size());
|
// System.out.println("DetectedResult.getFrameBitmap");
|
}
|
}
|
return frameBitmap;
|
}
|
|
public boolean stranger() {
|
return stranger;
|
}
|
|
public void setStranger() {
|
try {
|
boolean hasKnownPerson = false;
|
boolean hasStranger = false;
|
for (FacePosition facePosition : facePositions) {
|
if (facePosition.compareFeatureResult != null) {
|
if (facePosition.compareFeatureResult.person != null) {
|
hasKnownPerson = true;
|
}
|
if (facePosition.score >= 80 && facePosition.compareFeatureResult.person == null) {
|
hasStranger = true;
|
}
|
}
|
}
|
stranger = !hasKnownPerson && hasStranger;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|