最早之前接觸人工智能是從一篇博客開始的,這篇博客作者記錄了自己仿照一本教程開發的一套車牌識別系統開始,進而引申到人工智能領域的機器學習和深度學習。本文借鑑作者的這套系統,分析其實現,調試並更新其網絡模型,並落地到android手機的具體應用上,記錄引申到的相關領域的學習筆記:
1. C/C++
2. JAVA
3. Android開發
4. 算法相關
5. 人工智能/機器學習/深度學習
6. 相關工具使用
7. 學習資料
visutal studio code:
1.快捷鍵:
- 跳到函數定義處:F12;
- 跳回上次瀏覽位置:ALT+←
- 查找函數位置:alt+n
part1:從android上移植開始;
下載了android版本的車牌識別系統:.....
安裝android studio,並配置了sdk和ndk;過程不是很順利,記錄一下:
1. 加載已有android 工程後,編譯,出現錯誤:
CreateProcess error=2, 系統找不到指定的文件
無論編譯還是清除,都是這個錯誤,查找了很多資料,結果都沒用,後來自己研究發現報錯原因:app的build.gradle文件,報錯的時候提示:
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'D:\android-studio\android-ndk-r11c-windows-x86_64\android-ndk-r11c/ndk-build'
原來是找不到ndk-build, 打開工程的ndk路徑下發現是有這個文件的,但是這個腳本把ndk-build當作了文件夾,所以給他加上後綴就ok了:ndk-build.cmd,再次執行clean,成功~~~
下面編譯apk,又有錯誤:
Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.
- butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
依賴庫報錯,於是修改
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.jakewharton:butterknife:7.0.1'
annotationProcessor 'com.jakewharton:butterknife:7.0.1'
compile 'cn.pedant.sweetalert:library:1.3'
}
再次編譯,成功編譯出apk;
現在開始調試apk...
1. svmFile 始終爲null,原因是執行
mediaStorageDir.mkdirs()
創建文件夾storage/emulated/0/Documents/PlateRcognizer失敗,需要添加動態權限:
在AndroidManifest.xml中申請權限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
才baseActivaty中申請權限:
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
requestPermissions(
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
}
2. err:打開攝像頭失敗:Failed to connect to camera service
解決:android 6.0以後版本需要添加動態權限:
在AndroidManifest.xml中申請權限:
<uses-permission android:name="android.permission.CAMERA" />
使用之前動態申請權限:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {Manifest.permission.CAMERA}, 1);
}
}
3. 遇到 gradle:版本問題
androidstudio導入項目後,報錯:Could not find com.android.tools.build:gradle:3.1.0
項目根目錄的 build.gradle文件中添加其他可供下載的倉庫:google()、 jcenter()、mavenCentral()
修改build.gradle:
buildscript {
repositories {
google()
jcenter()
}
=============================
完事具備,東風也來了.....
靠,我的nokia 平板是android 5.1的,經過上述修改過的版本是基於最新的android 10的sdk和build tool 製作的apk,居然無法運行;無奈,將android studio的sdk和build tools降低到源碼匹配的23版本, 一切搞定;
替換成老版本,sdk用Android6.0 API23; ndk 用r11, build報錯:
ERROR: Failed to resolve: com.android.support:appcompat-v7:23.4.0
Add Google Maven repository and sync project
Show in Project Structure dialog
Affected Modules: app
在platerecognizer的build.gradle 的依賴加上:
allprojects {
repositories {
jcenter()
maven {url "https://maven.google.com"}
}
}
重新編譯,成功;
折騰一圈結果還是用人家的老版本, 我TM只學會了怎麼配置和使用android studio......