Add Android Demo
This commit is contained in:
@@ -41,4 +41,5 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'com.github.smuyyh:ImageSelector:3.0'
|
||||
implementation 'com.github.bumptech.glide:glide:3.7.0'
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.hyperai.hyperlpr_sdk_demo",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1,
|
||||
"versionName": "1.0",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
||||
@@ -48,8 +48,6 @@ public class CameraActivity extends Activity {
|
||||
private void initCamera() {
|
||||
previewFl = findViewById(R.id.preview_fl);
|
||||
plateTv = findViewById(R.id.plate_tv);
|
||||
// regTv = findViewById(R.id.reg_tv);
|
||||
// regTv.setOnClickListener(this);
|
||||
image = findViewById(R.id.image);
|
||||
cameraPreview = new CameraPreviews(this);
|
||||
previewFl.addView(cameraPreview);
|
||||
@@ -103,10 +101,4 @@ public class CameraActivity extends Activity {
|
||||
|
||||
// stopPreview();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// CameraPreviews cameraPreview = new CameraPreviews(this);
|
||||
// previewFl.addView(cameraPreview);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -4,18 +4,45 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
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.Plate;
|
||||
import com.yuyh.library.imgsel.ISNav;
|
||||
import com.yuyh.library.imgsel.common.ImageLoader;
|
||||
import com.yuyh.library.imgsel.config.ISListConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private Button cameraBtn;
|
||||
private Button albumBtn;
|
||||
private Context mCtx;
|
||||
private static final int REQUEST_LIST_CODE = 0;
|
||||
private static final int REQUEST_CAMERA_CODE = 1;
|
||||
|
||||
private final String TAG = "HyperLPR-App";
|
||||
|
||||
private ImageView imageView;
|
||||
|
||||
private TextView mResult;
|
||||
|
||||
HyperLPR3 hyperLPR3;
|
||||
|
||||
|
||||
private static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||||
@@ -45,10 +72,25 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
mCtx = this;
|
||||
cameraBtn = findViewById(R.id.cameraBtn);
|
||||
albumBtn = findViewById(R.id.albumBtn);
|
||||
imageView = findViewById(R.id.imageView);
|
||||
mResult = findViewById(R.id.mResult);
|
||||
|
||||
verifyStoragePermissions(this);
|
||||
|
||||
|
||||
Parameter parameter = new Parameter();
|
||||
hyperLPR3 = new HyperLPR3(mCtx, parameter);
|
||||
|
||||
ISNav.getInstance().init(new ImageLoader() {
|
||||
@Override
|
||||
public void displayImage(Context context, String path, ImageView imageView) {
|
||||
Glide.with(context).load(path).into(imageView);
|
||||
}
|
||||
});
|
||||
|
||||
cameraBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -61,8 +103,72 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
// 自由配置选项
|
||||
ISListConfig config = new ISListConfig.Builder()
|
||||
// 是否多选, 默认true
|
||||
.multiSelect(false)
|
||||
// 是否记住上次选中记录, 仅当multiSelect为true的时候配置,默认为true
|
||||
.rememberSelected(false)
|
||||
// “确定”按钮背景色
|
||||
.btnBgColor(Color.GRAY)
|
||||
// “确定”按钮文字颜色
|
||||
.btnTextColor(Color.BLUE)
|
||||
// 使用沉浸式状态栏
|
||||
.statusBarColor(Color.parseColor("#3F51B5"))
|
||||
// 返回图标ResId
|
||||
.backResId(androidx.appcompat.R.drawable.abc_cab_background_top_mtrl_alpha)
|
||||
// 标题
|
||||
.title("图片")
|
||||
// 标题文字颜色
|
||||
.titleColor(Color.WHITE)
|
||||
// TitleBar背景色
|
||||
.titleBgColor(Color.parseColor("#3F51B5"))
|
||||
// 裁剪大小。needCrop为true的时候配置
|
||||
.cropSize(1, 1, 200, 200)
|
||||
.needCrop(false)
|
||||
// 第一个是否显示相机,默认true
|
||||
.needCamera(false)
|
||||
// 最大选择图片数量,默认9
|
||||
.maxNum(1)
|
||||
.build();
|
||||
|
||||
// 跳转到图片选择器
|
||||
ISNav.getInstance().toListActivity(mCtx, config, REQUEST_LIST_CODE);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
Bitmap bitmap = null;
|
||||
String showText = "";
|
||||
// 图片选择结果回调
|
||||
if (requestCode == REQUEST_LIST_CODE && resultCode == RESULT_OK && data != null) {
|
||||
List<String> pathList = data.getStringArrayListExtra("result");
|
||||
Log.i(TAG, pathList.get(0));
|
||||
bitmap = BitmapFactory.decodeFile(pathList.get(0));
|
||||
} else if (requestCode == REQUEST_CAMERA_CODE && resultCode == RESULT_OK && data != null) {
|
||||
String path = data.getStringExtra("result");
|
||||
Log.i(TAG, path);
|
||||
bitmap = BitmapFactory.decodeFile(path);
|
||||
}
|
||||
if (bitmap != null) {
|
||||
|
||||
imageView.setImageBitmap(bitmap);
|
||||
Plate[] plates = hyperLPR3.plateRecognition(bitmap, HyperLPR3.CAMERA_ROTATION_0, HyperLPR3.STREAM_BGRA);
|
||||
for (Plate plate: plates) {
|
||||
String type = "未知车牌";
|
||||
if (plate.getType() != HyperLPR3.PLATE_TYPE_UNKNOWN) {
|
||||
type = HyperLPR3.PLATE_TYPE_MAPS[plate.getType()];
|
||||
}
|
||||
String pStr = "[" + type + "]" + plate.getCode() + "\n";
|
||||
showText += pStr;
|
||||
mResult.setText(showText);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,28 +6,52 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cameraBtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="打开相机"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.2"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.863" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/albumBtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="打开相册"
|
||||
android:text="选择图片识别"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.776"
|
||||
app:layout_constraintHorizontal_bias="0.791"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.863" />
|
||||
app:layout_constraintVertical_bias="0.923" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/cameraBtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="实时车牌识别"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.217"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.923" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="297dp"
|
||||
android:layout_height="419dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.227"
|
||||
tools:srcCompat="@tools:sample/avatars" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/mResult"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.233"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView"
|
||||
app:layout_constraintVertical_bias="0.079" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">HyperLPR_SDK_Demo</string>
|
||||
<string name="app_name">HyperLPR3-App</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,16 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.HyperLPR_SDK_Demo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
@@ -3,7 +3,6 @@ buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:7.0.2"
|
||||
|
||||
@@ -44,4 +44,5 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'com.github.smuyyh:ImageSelector:3.0'
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hyperai.hyperlpr3">
|
||||
|
||||
</manifest>
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
package com.hyperai.hyperlpr3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hyperai.hyperlpr3.api.APIDefine;
|
||||
@@ -60,5 +61,22 @@ public class HyperLPR3 extends TypeDefine implements APIDefine {
|
||||
return mCore.plateRecognitionFromBuffer(buf, height, width, rotation, format);
|
||||
}
|
||||
|
||||
/**
|
||||
* License plate recognition interface.
|
||||
*
|
||||
* @param image Bitmap image
|
||||
* @param rotation Original data buffer rotation Angle
|
||||
* @param format Buffer data coded format
|
||||
* @return Resulting object array
|
||||
*/
|
||||
@Override
|
||||
public Plate[] plateRecognition(Bitmap image, int rotation, int format) {
|
||||
int mWidth = image.getWidth();
|
||||
int mHeight = image.getHeight();
|
||||
int[] data = new int[image.getWidth() * image.getHeight()];
|
||||
image.getPixels(data, 0, mWidth, 0, 0, mWidth, mHeight);
|
||||
return mCore.plateRecognitionFromImage(data, mHeight, mWidth, rotation, format);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.hyperai.hyperlpr3.api;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.hyperai.hyperlpr3.bean.Plate;
|
||||
|
||||
public interface APIDefine {
|
||||
@@ -15,4 +17,13 @@ public interface APIDefine {
|
||||
*/
|
||||
Plate[] plateRecognition(byte[] buf, int height, int width, int rotation, int format);
|
||||
|
||||
/**
|
||||
* License plate recognition interface.
|
||||
* @param image Bitmap image
|
||||
* @param rotation Original data buffer rotation Angle
|
||||
* @param format Buffer data coded format
|
||||
* @return Resulting object array
|
||||
*/
|
||||
Plate[] plateRecognition(Bitmap image, int rotation, int format);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ public class HyperLPRCore {
|
||||
return PlateRecognitionFromBuffer(ctxHandle_, buf, height, width, rotation, format);
|
||||
}
|
||||
|
||||
public Plate[] plateRecognitionFromImage(int[] buf, int height, int width, int rotation, int format) {
|
||||
return PlateRecognitionFromImage(ctxHandle_, buf, height, width, rotation, format);
|
||||
}
|
||||
|
||||
public int release() {
|
||||
int ret = -1;
|
||||
if (isRunning_) {
|
||||
@@ -50,4 +54,8 @@ public class HyperLPRCore {
|
||||
native int ReleaseRecognizerContext(long handle);
|
||||
|
||||
native Plate[] PlateRecognitionFromBuffer(long handle, byte[] buf, int height, int width, int rotation, int format);
|
||||
|
||||
native Plate[] PlateRecognitionFromImage(long handle, int[] buf, int height, int width, int rotation, int format);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ dependencyResolutionManagement {
|
||||
google()
|
||||
mavenCentral()
|
||||
jcenter() // Warning: this repository is going to shut down soon
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
}
|
||||
rootProject.name = "HyperLPR_SDK_Demo"
|
||||
|
||||
Reference in New Issue
Block a user