代码参考至github上面的EasyPR_Android的源码,感谢为开源付出贡献的程序猿
源码地址 :https://github.com/linuxxx/EasyPR_Android
使用步骤:
1、下载源码到本地,使用AndroidStudio打开,直接运行可能会有错误,我在开发时出现了找不到ndk-build文件,不是代码不能够运行,而是在build.gradle中没有配置完整,大家找到
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=0'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
更改为:
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=0'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
这样就OK了 只是没有指明ndk-build的后缀,加上.cmd就好了。。
2、就算你自己能运行了 车牌识别也可以使用了,接下来问题是如何移植到自己的项目中去。
3、首先你需要创建一个属于自己的项目 ,然后把EasyPR_Android 中的jni文件夹下的所有文件原封不动的复制到你的java目录中去,然后把OpencvNative文件夹也复制到你的项目根目录下,编写自己的activity和PlateRecognizer,编写完成之后更改jni文件下的EasyPR.cpp和EasyPR.h的代码,配置build.gradle,然后重新编译程序,就会生成libs文件夹和obj文件夹。
4、如果你感觉代码太多了,你可以只保留libs文件 其他复制过来的东西都可以删除了。
5、完成以上任务 就可以尽情的使用的车牌识别了。。。
附 效果图