Update Android Demo
This commit is contained in:
@@ -5,7 +5,7 @@ import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hyperai.hyperlpr3.api.APIDefine;
|
||||
import com.hyperai.hyperlpr3.bean.Parameter;
|
||||
import com.hyperai.hyperlpr3.bean.HyperLPRParameter;
|
||||
import com.hyperai.hyperlpr3.bean.Plate;
|
||||
import com.hyperai.hyperlpr3.core.HyperLPRCore;
|
||||
import com.hyperai.hyperlpr3.settings.TypeDefine;
|
||||
@@ -14,28 +14,26 @@ import com.hyperai.hyperlpr3.utils.SDKUtils;
|
||||
|
||||
public class HyperLPR3 extends TypeDefine implements APIDefine {
|
||||
|
||||
private final String TAG = "HyperLPR3";
|
||||
private final String TAG = "HyperLPR3-SDK";
|
||||
|
||||
private final HyperLPRCore mCore;
|
||||
|
||||
private final Context mContext;
|
||||
private boolean isInitSuccess;
|
||||
|
||||
public HyperLPR3(Context mContext, Parameter parameter) {
|
||||
this.mContext = mContext;
|
||||
String mResourceFolderPath = mContext.getExternalFilesDir(null).getAbsolutePath() + "/";
|
||||
SDKUtils.copyFilesFromAssets(mContext, SDKConfig.packDirName, mResourceFolderPath);
|
||||
Log.i(TAG, "resource: " + mResourceFolderPath);
|
||||
if (parameter.getModelPath() == null || "".equals(parameter.getModelPath())) {
|
||||
parameter.setModelPath(mResourceFolderPath);
|
||||
}
|
||||
private HyperLPR3() {
|
||||
mCore = new HyperLPRCore();
|
||||
mCore.createRecognizerContext(parameter);
|
||||
isInitSuccess = false;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
private static class LazyHolder {
|
||||
private static final HyperLPR3 INSTANCE = new HyperLPR3();
|
||||
}
|
||||
|
||||
public static final HyperLPR3 getInstance() {
|
||||
return LazyHolder.INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public void release() {
|
||||
mCore.release();
|
||||
}
|
||||
@@ -46,6 +44,26 @@ public class HyperLPR3 extends TypeDefine implements APIDefine {
|
||||
release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the license plate recognition algorithm SDK
|
||||
*
|
||||
* @param context context
|
||||
* @param parameter Initialization parameter
|
||||
*/
|
||||
@Override
|
||||
public void init(Context context, HyperLPRParameter parameter) {
|
||||
if (!isInitSuccess) {
|
||||
String mResourceFolderPath = context.getExternalFilesDir(null).getAbsolutePath() + "/";
|
||||
SDKUtils.copyFilesFromAssets(context, SDKConfig.packDirName, mResourceFolderPath);
|
||||
Log.i(TAG, "resource: " + mResourceFolderPath);
|
||||
if (parameter.getModelPath() == null || "".equals(parameter.getModelPath())) {
|
||||
parameter.setModelPath(mResourceFolderPath);
|
||||
}
|
||||
mCore.createRecognizerContext(parameter);
|
||||
isInitSuccess = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* License plate recognition interface.
|
||||
*
|
||||
@@ -58,6 +76,10 @@ public class HyperLPR3 extends TypeDefine implements APIDefine {
|
||||
*/
|
||||
@Override
|
||||
public Plate[] plateRecognition(byte[] buf, int height, int width, int rotation, int format) {
|
||||
if (!isInitSuccess) {
|
||||
Log.e(TAG, "HyperLPR3 is uninitialized.");
|
||||
return new Plate[0];
|
||||
}
|
||||
return mCore.plateRecognitionFromBuffer(buf, height, width, rotation, format);
|
||||
}
|
||||
|
||||
@@ -71,6 +93,10 @@ public class HyperLPR3 extends TypeDefine implements APIDefine {
|
||||
*/
|
||||
@Override
|
||||
public Plate[] plateRecognition(Bitmap image, int rotation, int format) {
|
||||
if (!isInitSuccess) {
|
||||
Log.e(TAG, "HyperLPR3 is uninitialized.");
|
||||
return new Plate[0];
|
||||
}
|
||||
int mWidth = image.getWidth();
|
||||
int mHeight = image.getHeight();
|
||||
int[] data = new int[image.getWidth() * image.getHeight()];
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
package com.hyperai.hyperlpr3.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.hyperai.hyperlpr3.bean.HyperLPRParameter;
|
||||
import com.hyperai.hyperlpr3.bean.Plate;
|
||||
|
||||
public interface APIDefine {
|
||||
|
||||
/**
|
||||
* Initialize the license plate recognition algorithm SDK
|
||||
*
|
||||
* @param context context
|
||||
* @param parameter Initialization parameter
|
||||
* */
|
||||
void init(Context context, HyperLPRParameter parameter);
|
||||
|
||||
/**
|
||||
* License plate recognition interface.
|
||||
*
|
||||
* @param buf Image data buffer.
|
||||
* @param height Height of the image
|
||||
* @param width Width of the image
|
||||
@@ -19,6 +30,7 @@ public interface APIDefine {
|
||||
|
||||
/**
|
||||
* License plate recognition interface.
|
||||
*
|
||||
* @param image Bitmap image
|
||||
* @param rotation Original data buffer rotation Angle
|
||||
* @param format Buffer data coded format
|
||||
|
||||
+21
-11
@@ -2,7 +2,7 @@ package com.hyperai.hyperlpr3.bean;
|
||||
|
||||
import com.hyperai.hyperlpr3.settings.TypeDefine;
|
||||
|
||||
public class Parameter {
|
||||
public class HyperLPRParameter {
|
||||
|
||||
private String modelPath;
|
||||
|
||||
@@ -14,76 +14,86 @@ public class Parameter {
|
||||
|
||||
private float nmsThreshold = 0.6f;
|
||||
|
||||
private float recConfidenceThreshold = 0.75f;
|
||||
private float recConfidenceThreshold = 0.85f;
|
||||
|
||||
private int detLevel = TypeDefine.DETECT_LEVEL_LOW;
|
||||
|
||||
private int maxNum = 3;
|
||||
|
||||
public Parameter() {
|
||||
public HyperLPRParameter() {
|
||||
}
|
||||
|
||||
public int getMaxNum() {
|
||||
return maxNum;
|
||||
}
|
||||
|
||||
public void setMaxNum(int maxNum) {
|
||||
public HyperLPRParameter setMaxNum(int maxNum) {
|
||||
this.maxNum = maxNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getModelPath() {
|
||||
return modelPath;
|
||||
}
|
||||
|
||||
public void setModelPath(String modelPath) {
|
||||
public HyperLPRParameter setModelPath(String modelPath) {
|
||||
this.modelPath = modelPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getThreads() {
|
||||
return threads;
|
||||
}
|
||||
|
||||
public void setThreads(int threads) {
|
||||
public HyperLPRParameter setThreads(int threads) {
|
||||
this.threads = threads;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isUseHalf() {
|
||||
return useHalf;
|
||||
}
|
||||
|
||||
public void setUseHalf(boolean useHalf) {
|
||||
public HyperLPRParameter setUseHalf(boolean useHalf) {
|
||||
this.useHalf = useHalf;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getBoxConfThreshold() {
|
||||
return boxConfThreshold;
|
||||
}
|
||||
|
||||
public void setBoxConfThreshold(float boxConfThreshold) {
|
||||
public HyperLPRParameter setBoxConfThreshold(float boxConfThreshold) {
|
||||
this.boxConfThreshold = boxConfThreshold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getNmsThreshold() {
|
||||
return nmsThreshold;
|
||||
}
|
||||
|
||||
public void setNmsThreshold(float nmsThreshold) {
|
||||
public HyperLPRParameter setNmsThreshold(float nmsThreshold) {
|
||||
this.nmsThreshold = nmsThreshold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getRecConfidenceThreshold() {
|
||||
return recConfidenceThreshold;
|
||||
}
|
||||
|
||||
public void setRecConfidenceThreshold(float recConfidenceThreshold) {
|
||||
public HyperLPRParameter setRecConfidenceThreshold(float recConfidenceThreshold) {
|
||||
this.recConfidenceThreshold = recConfidenceThreshold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getDetLevel() {
|
||||
return detLevel;
|
||||
}
|
||||
|
||||
public void setDetLevel(int detLevel) {
|
||||
public HyperLPRParameter setDetLevel(int detLevel) {
|
||||
this.detLevel = detLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.hyperai.hyperlpr3.core;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.hyperai.hyperlpr3.bean.Parameter;
|
||||
import com.hyperai.hyperlpr3.bean.HyperLPRParameter;
|
||||
import com.hyperai.hyperlpr3.bean.Plate;
|
||||
|
||||
public class HyperLPRCore {
|
||||
@@ -17,11 +17,7 @@ public class HyperLPRCore {
|
||||
|
||||
private boolean isRunning_;
|
||||
|
||||
// public void testBuffer(String savePath, byte[] buf, int height, int width, int rotation) {
|
||||
// TestBuffer(savePath, buf, height, width, rotation);
|
||||
// }
|
||||
|
||||
public void createRecognizerContext(Parameter parameter) {
|
||||
public void createRecognizerContext(HyperLPRParameter parameter) {
|
||||
ctxHandle_ = CreateRecognizerContext(parameter);
|
||||
Log.i(TAG, "HANDLE: " + ctxHandle_);
|
||||
isRunning_ = true;
|
||||
@@ -49,7 +45,7 @@ public class HyperLPRCore {
|
||||
|
||||
// native void TestBuffer(String savePath, byte[] buf, int height, int width, int rotation);
|
||||
|
||||
native long CreateRecognizerContext(Parameter parameterObj);
|
||||
native long CreateRecognizerContext(HyperLPRParameter parameterObj);
|
||||
|
||||
native int ReleaseRecognizerContext(long handle);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user