- android studio , ndk 17.2 cmake 18
- opencv for android sdk 4.5.4 : unzip 到下面 cmakelist.txt 中的 path
- snpe 1.68 : unzip 到下面 cmakelist.txt 中的 path
等android studio import 完成,所有 project component 都顯示了。
選 Project Files. 然後下面的 Object-Detection-with..... ,選 app - main - cpp 就會看到有 CMakeList.txt。
修改這個 CMakeList.txt 中的 opencv 和 snpe 的目錄:
diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 8aa71f5..3e041ce 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.4.1) project("objectrecognition") set(OpenCV_STATIC on) -set(OpenCV_DIR "/<OPENCV_PATH>/opencv-4.5.4-android-sdk/OpenCV-android-sdk/sdk/native/jni") +set(OpenCV_DIR "/home/charles-chang/OpenCV-android-sdk/sdk/native/jni") find_package(OpenCV REQUIRED) set(CMAKE_VERBOSE_MAKEFILE on) @@ -18,7 +18,7 @@ set(CMAKE_VERBOSE_MAKEFILE on) # build native_app_glue as a static lib include_directories(${ANDROID_NDK}/sources/android/native_app_glue ${COMMON_SOURCE_DIR}) -include_directories(/<SNPE_PATH>/snpe-1.68.0.3932/include/zdl) +include_directories(/home/charles-chang/snpe-1.68.0.3932/include/zdl) add_library(app_glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)然後選回 android, 選 build apk,會說 Native_C 有錯,就改:
diff --git a/app/src/main/cpp/Native_C.h b/app/src/main/cpp/Native_C.h index 56c5024..458a822 100644 --- a/app/src/main/cpp/Native_C.h +++ b/app/src/main/cpp/Native_C.h @@ -40,8 +40,8 @@ class Native_C { bool CreateCaptureSession(ANativeWindow* window); - int32_t GetCameraCount() { return m_camera_id_list->numCameras; } - uint32_t GetOrientation() { return m_camera_orientation; }; + int32_t GetCameraCount() { return camera_id_list->numCameras; } + uint32_t GetOrientation() { return camera_orientation; }; private:這樣就能 build apk OK.
然後再 build apk boundle.
出現manifest 沒有 version 的錯。
修改... 亂寫一個版本
diff --git a/app/build.gradle b/app/build.gradle index 3bc0773..7daba68 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,6 +10,8 @@ android { applicationId 'com.object.recognition' minSdkVersion 24 targetSdkVersion 29 + versionName '1.0.2' + versionCode 3 ndk { abiFilters 'armeabi-v7a'//, 'arm64-v8a', 'x86', 'x86_64'build Boundle OK
run 起來後,windows 一直打不開。因為下面這行被 optimize 調,所以要改:
diff --git a/app/src/main/cpp/main.cpp b/app/src/main/cpp/main.cpp index 88c8e52..785636d 100644 --- a/app/src/main/cpp/main.cpp +++ b/app/src/main/cpp/main.cpp @@ -156,17 +156,17 @@ void main::OnCreate() { void main::OnPause() {} void main::OnDestroy() {} -void main::SetNativeWindow(ANativeWindow* native_window) { +void main::SetNativeWindow(ANativeWindow* anative_window) { // Save native window - native_window = native_window; + native_window = anative_window; } void main::SetUpCamera() { native_camera = new Native_C(selected_camera_type); native_camera->MatchCaptureSizeRequest(&m_view, - ANativeWindow_getWidth(native_window), - ANativeWindow_getHeight(native_window)); + 720/*ANativeWindow_getWidth(native_window)*/, + 1080/*ANativeWindow_getHeight(native_window)*/); LOGI("______________mview %d\t %d\n", m_view.width, m_view.height);之後還有 camera aspect ratio 問題,找不到可用的camera 設定。所以固定.
要 adb root, remount,follow instruction push snpe so 和 dlc file,
是 push 整個 folder,所以要 follow 說明,不要擅自用 *
同公司的令一個project 也一樣。 一樣修改 CMakeList.txt 的 opencv 和 snpe 的 path,build.grandle 加上 version.
然後就是 commit code 的 dlc , class.txt 是從 sdcard 上讀取,要概回原來的。
另外這個dlc 和 class.txt 是在 assets folder,還有 push 的 folder 是 models 不是上一個 Object Detection 的 mode..
然後把存檔功能刪掉。
diff --git a/app/build.gradle b/app/build.gradle index 11378c8..6b306d9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,6 +21,8 @@ android { applicationId 'com.homesight.personrecognition' minSdkVersion 24 targetSdkVersion 29 + versionName '1.0.2' + versionCode 3 ndk { abiFilters 'armeabi-v7a'//, 'arm64-v8a', 'x86', 'x86_64' diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 12c12fc..c30cae2 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.4.1) project("persondetection") set(OpenCV_STATIC on) -set(OpenCV_DIR "/home/krishnapriya/Desktop/Office_work/opencv-4.7.0-android-sdk/OpenCV-android-sdk/sdk/native/jni") +set(OpenCV_DIR "/home/charles-chang/opencv-4.7.0-android-sdk/sdk/native/jni") find_package(OpenCV REQUIRED) set(CMAKE_VERBOSE_MAKEFILE on) @@ -18,7 +18,7 @@ set(CMAKE_VERBOSE_MAKEFILE on) # build native_app_glue as a static lib include_directories(${ANDROID_NDK}/sources/android/native_app_glue ${COMMON_SOURCE_DIR}) -include_directories(/home/krishnapriya/Desktop/Office_work/SNPE/snpe-1.51.0.2663/include/zdl) +include_directories(/home/charles-chang/snpe-1.51.0.2663/include/zdl) #set(SNPE_LIB_DIR "/home/krishnapriya/Desktop/Office_work/SNPE/snpe-1.51.0.2663/lib/aarch64-android-clang6.0") #set(DSP_LIB_DIR "/home/krishnapriya/Desktop/Office_work/SNPE/snpe-1.51.0.2663//lib/dsp") add_library(app_glue STATIC diff --git a/app/src/main/cpp/Native_Camera.cpp b/app/src/main/cpp/Native_Camera.cpp index e601b88..d12dab4 100644 --- a/app/src/main/cpp/Native_Camera.cpp +++ b/app/src/main/cpp/Native_Camera.cpp @@ -157,4 +157,4 @@ bool Native_Camera::CreateCaptureSession(ANativeWindow* window) { &m_capture_request, nullptr); return true; -} \ No newline at end of file +} diff --git a/app/src/main/cpp/Person_Detect.cpp b/app/src/main/cpp/Person_Detect.cpp index acf1158..9983989 100644 --- a/app/src/main/cpp/Person_Detect.cpp +++ b/app/src/main/cpp/Person_Detect.cpp @@ -1,4 +1,4 @@ -3#include "Person_Detect.h" +#include "Person_Detect.h" #include <unistd.h> #include <cmath> #include <opencv2/core/core.hpp> @@ -55,8 +55,8 @@ void Person_Detect::SetUpCamera() { m_native_camera = new Native_Camera(m_selected_camera_type); m_native_camera->MatchCaptureSizeRequest(&m_view, - ANativeWindow_getWidth(m_native_window), - ANativeWindow_getHeight(m_native_window)); + 720/*ANativeWindow_getWidth(m_native_window)*/, + 480/*ANativeWindow_getHeight(m_native_window)*/); LOGI("______________mview %d\t %d\n", m_view.width, m_view.height); LOGI("______________mview %d\t %d\n", ANativeWindow_getWidth(m_native_window),ANativeWindow_getHeight(m_native_window)); @@ -71,8 +71,8 @@ void Person_Detect::SetUpCamera() { m_camera_ready = m_native_camera->CreateCaptureSession(image_reader_window); } -//std::string class_name_path = "/storage/emulated/0/appData/models/classes.txt"; -std::string class_name_path = "/sdcard/Documents/classes.txt"; +std::string class_name_path = "/storage/emulated/0/appData/models/classes.txt"; +//std::string class_name_path = "/sdcard/Documents/classes.txt"; std::vector<std::string> load_class_list() { std::vector<std::string> class_list; @@ -88,7 +88,7 @@ std::vector<std::string> class_list = load_class_list(); void Person_Detect::CameraLoop() { bool buffer_printout = false; - video_writer.open("/sdcard/Documents/Person_Detect_video.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 10.0, cv::Size(640, 480), true); + //video_writer.open("/sdcard/Documents/Person_Detect_video.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 10.0, cv::Size(640, 480), true); while (1) { if (m_camera_thread_stopped) { break; } @@ -210,14 +210,14 @@ void Person_Detect::CameraLoop() { } cv::imwrite("/storage/emulated/0/appData/models/Person_Detect_bgr.jpg",bgr_img); cv::resize(img_mat, out_img, cv::Size(640, 480)); - video_writer.write(out_img); + //video_writer.write(out_img); cv::imwrite("/storage/emulated/0/appData/models/Person_Detect_image.jpg",out_img); pred_out.clear(); ANativeWindow_unlockAndPost(m_native_window); ANativeWindow_release(m_native_window); } - video_writer.release(); + //video_writer.release(); } diff --git a/app/src/main/cpp/Person_Detect.h b/app/src/main/cpp/Person_Detect.h index cbc6971..9c194f2 100644 --- a/app/src/main/cpp/Person_Detect.h +++ b/app/src/main/cpp/Person_Detect.h @@ -75,8 +75,8 @@ private: cv::VideoWriter video_writer; -// std::string model_path = "/storage/emulated/0/appData/models/yolov5_person_latest.dlc"; - std::string model_path = "/sdcard/Download/Telegram/yolov5_person_latest.dlc"; + std::string model_path = "/storage/emulated/0/appData/models/yolov5_person_latest.dlc"; + //std::string model_path = "/sdcard/Download/Telegram/yolov5_person_latest.dlc"; std::vector<std::string> output_layers {OUTPUT_LAYER_1}; std::map <std::string, std::vector<float>> pred_out; diff --git a/local.properties b/local.properties index 06c338c..ae5b6a0 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Thu Aug 17 18:03:24 IST 2023 -sdk.dir=/home/krishnapriya/Android/Sdk +#Wed Nov 01 16:48:14 CST 2023 +sdk.dir=/home/charles-chang/Android/Sdk
沒有留言:
張貼留言