Update Android Demo
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package com.hyperai.hyperlpr_sdk_demo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Handler;
|
||||
@@ -20,11 +18,10 @@ import android.view.WindowManager;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.hyperai.hyperlpr3.HyperLPR3;
|
||||
import com.hyperai.hyperlpr3.bean.Parameter;
|
||||
import com.hyperai.hyperlpr3.bean.HyperLPRParameter;
|
||||
import com.hyperai.hyperlpr3.bean.Plate;
|
||||
|
||||
/**
|
||||
@@ -45,8 +42,6 @@ public class CameraPreviews extends SurfaceView implements SurfaceHolder.Callbac
|
||||
|
||||
private Context mContext;
|
||||
|
||||
HyperLPR3 hyperLPR3;
|
||||
|
||||
public CameraPreviews(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
@@ -57,8 +52,9 @@ public class CameraPreviews extends SurfaceView implements SurfaceHolder.Callbac
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
// mPaint.setColor(ContextCompat.getColor(context, R.color.colorAccent));
|
||||
|
||||
Parameter parameter = new Parameter();
|
||||
hyperLPR3 = new HyperLPR3(mContext, parameter);
|
||||
HyperLPRParameter parameter = new HyperLPRParameter();
|
||||
// hyperLPR3 = new HyperLPR3();
|
||||
// hyperLPR3.init(mContext, parameter);
|
||||
}
|
||||
public Camera getCameraInstance(){
|
||||
if (mCamera == null){
|
||||
@@ -135,16 +131,12 @@ public class CameraPreviews extends SurfaceView implements SurfaceHolder.Callbac
|
||||
synchronized (lock){
|
||||
// 处理data
|
||||
Camera.Size previewSize = camera.getParameters().getPreviewSize();
|
||||
|
||||
// String save_path = mContext.getExternalFilesDir(null).getAbsolutePath() + "/" + "a.jpg";
|
||||
// core.testBuffer(save_path, data, previewSize.height, previewSize.width, 3);
|
||||
Plate[] plates = hyperLPR3.plateRecognition(data, previewSize.height, previewSize.width, HyperLPR3.CAMERA_ROTATION_270, HyperLPR3.STREAM_YUV_NV21);
|
||||
Plate[] plates = HyperLPR3.getInstance().plateRecognition(data, previewSize.height, previewSize.width, HyperLPR3.CAMERA_ROTATION_270, HyperLPR3.STREAM_YUV_NV21);
|
||||
for (Plate plate : plates) {
|
||||
Log.i(TAG, "" + plate.toString());
|
||||
}
|
||||
|
||||
if(!isStopReg && plates.length > 0) {
|
||||
|
||||
// isStopReg = true;
|
||||
sendPlate(plates);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.hyperai.hyperlpr3.HyperLPR3;
|
||||
import com.hyperai.hyperlpr3.bean.Parameter;
|
||||
import com.hyperai.hyperlpr3.bean.HyperLPRParameter;
|
||||
import com.hyperai.hyperlpr3.bean.Plate;
|
||||
import com.yuyh.library.imgsel.ISNav;
|
||||
import com.yuyh.library.imgsel.common.ImageLoader;
|
||||
@@ -42,8 +42,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private TextView mResult;
|
||||
|
||||
HyperLPR3 hyperLPR3;
|
||||
|
||||
|
||||
private static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||||
private static final String[] PERMISSIONS_STORAGE = {
|
||||
@@ -81,8 +79,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
verifyStoragePermissions(this);
|
||||
|
||||
|
||||
Parameter parameter = new Parameter();
|
||||
hyperLPR3 = new HyperLPR3(mCtx, parameter);
|
||||
// 车牌识别算法配置参数
|
||||
HyperLPRParameter parameter = new HyperLPRParameter()
|
||||
.setDetLevel(HyperLPR3.DETECT_LEVEL_LOW)
|
||||
.setMaxNum(1)
|
||||
.setRecConfidenceThreshold(0.85f);
|
||||
// 初始化(仅执行一次生效)
|
||||
HyperLPR3.getInstance().init(this, parameter);
|
||||
|
||||
ISNav.getInstance().init(new ImageLoader() {
|
||||
@Override
|
||||
@@ -158,7 +161,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (bitmap != null) {
|
||||
|
||||
imageView.setImageBitmap(bitmap);
|
||||
Plate[] plates = hyperLPR3.plateRecognition(bitmap, HyperLPR3.CAMERA_ROTATION_0, HyperLPR3.STREAM_BGRA);
|
||||
Plate[] plates = HyperLPR3.getInstance().plateRecognition(bitmap, HyperLPR3.CAMERA_ROTATION_0, HyperLPR3.STREAM_BGRA);
|
||||
for (Plate plate: plates) {
|
||||
String type = "未知车牌";
|
||||
if (plate.getType() != HyperLPR3.PLATE_TYPE_UNKNOWN) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define HYPERLPR_VER_MAJOR 3
|
||||
#define HYPERLPR_VER_MINOR 0
|
||||
#define HYPERLPR_VER_PATCH 1
|
||||
Reference in New Issue
Block a user