Android 识别车牌信息
打开我们心爱的Android Studio
导入需要的资源
gradle
//开源车牌识别安卓SDK库
implementation("com.github.HyperInspire:hyperlpr3-android-sdk:1.0.3")
button.setOnClickListener(v -> {
Log.d("Test", "");
try (InputStream file = getAssets().open("lp1.jpg")) {
Bitmap lpImg = BitmapFactory.decodeStream(file);
Bitmap showImg = null;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
showImg = Bitmap.createBitmap(lpImg.getWidth(), lpImg.getHeight(), Bitmap.Config.RGB_565, false);
}
if (showImg != null) {
canvas.setBitmap(showImg);
// 绘制画笔
Paint paint = new Paint();
paint.setStrokeWidth(2);//设置画笔宽为2
paint.setARGB(255, 255, 0, 0);
paint.setStyle(Paint.Style.STROKE);
// 绘制画笔到画布上
canvas.drawBitmap(lpImg, 0, 0, new Paint());
Plate[] plates = HyperLPR3.getInstance().plateRecognition(lpImg, HyperLPR3.CAMERA_ROTATION_0, HyperLPR3.STREAM_BGRA);
// 自定义字符串内容
StringBuilder builder = new StringBuilder();
for (int i = 0; i < plates.length; i++) {
Plate plate = plates[i];
canvas.drawRect(plate.getX1(), plate.getY1(), plate.getX2(), plate.getY2(), paint);
builder.append('第').append(i+1).append("车牌").append("\n");
builder.append("车牌内容").append(plate.getCode()).append("\n");
}
img.setImageBitmap(showImg);
text.setText(builder.toString());
}
} catch (IOException e) {
Toast.makeText(this, "图像加载失败了", Toast.LENGTH_SHORT).show();
}
});