android的車牌識別系統EasyPR
阿新 • • 發佈:2019-02-13
上篇文章介紹了身份證識別,現在我們來說說關於車牌識別。
EasyPR有如下特點:
1. 它基於openCV這個開源庫,這意味著所有它的程式碼都可以輕易的獲取。
2. 它能夠識別中文。例如車牌為蘇EUK722的圖片,它可以準確地輸出std:string型別的”蘇EUK722”的結果。
3. 它的識別率較高。目前情況下,字元識別已經可以達到90%以上的精度。
使用方法
package com.android.guocheng.easypr;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.fosung.libeasypr.view.EasyPRPreSurfaceView;
import com.fosung.libeasypr.view.EasyPRPreView;
public class MainActivity extends AppCompatActivity {
private EasyPRPreView easyPRPreView;
private Button btnShutter;
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
easyPRPreView = (EasyPRPreView) findViewById(R.id.preSurfaceView);
btnShutter = (Button) findViewById(R.id.btnShutter);
text = (TextView) findViewById(R.id.text);
initListener();
}
@Override
protected void onStart() {
super.onStart();
if (easyPRPreView != null) {
easyPRPreView.onStart();
}
}
@Override
protected void onStop() {
super.onStop();
if (easyPRPreView != null) {
easyPRPreView.onStop();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (easyPRPreView != null) {
easyPRPreView.onDestroy();
}
}
private void initListener() {
easyPRPreView.setRecognizedListener(new EasyPRPreSurfaceView.OnRecognizedListener() {
@Override
public void onRecognized(String result) {
if (result == null || result.equals("0")) {
Toast.makeText(MainActivity.this, "換個姿勢試試!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "識別成功", Toast.LENGTH_SHORT).show();
text.setText(result);
}
}
});
btnShutter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
easyPRPreView.recognize();//開始識別
}
});
}
}
佈局檔案
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000">
<com.fosung.libeasypr.view.EasyPRPreView
android:id="@+id/preSurfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:id="@+id/btnShutter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:text="識別"
android:textSize="16sp"
android:textColor="#FFFFFF"
android:background="@color/colorAccent"/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="16dp"
android:text="請將車牌放入框內"/>
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="18dp"
android:layout_below="@+id/title"/>
</RelativeLayout>
別忘了在manifest加入攝像機許可權<uses-permission android:name="android.permission.CAMERA" />
app在執行時,有車牌限定框,在框的範圍內進行影象裁剪,人為縮小了識別範圍,提高識別度。
本庫基於EasyPR_Android。
效果圖: