上篇文章介紹了身份證識別,現在我們來說說關于車牌識別。
EasyPR是一個開源的中文車牌識別系統,gitHub地址
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。
效果圖:
最后附上demo源碼
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答