使用TensorFlow Android Inference Interface在Android上進行圖像物體檢測
不支持Camera2 API的手機也可以物體檢測:https://github.com/lijiancheng0614/android-TFDetect
從TensorFlow源代碼編譯TensorFlow Android Camera Demo
參考 https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android/
使用Bazel編譯
下載TensorFlow源代碼
git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
準備環境
安裝Bazel
安裝Android NDK,版本應與Bazel配合,見官網對應的版本
安裝Android SDK
編輯
tensorflow/WORKSPACE
中NDK和SDK的路徑
編譯
# From tensorflow bazel build -c opt //tensorflow/examples/android:tensorflow_demo
安裝
adb install -r bazel-bin/tensorflow/examples/android/tensorflow_demo.apk
使用Android Studio和Bazel編譯
修改tensorflow/examples/android/build.gradle
中Bazel的路徑,直接用Android Studio導入tensorflow/examples/android/
目錄作爲新的Android Studio項目。
不支持Camera2 API的手機
由於部分手機不支持Camera2 API,故需要把調用Camera2 API的代碼去掉。
具體來說,把tracking部分的代碼刪掉,只做object detection,並更新相應畫bounding box的代碼,這樣速度也有所加快。