aidl.srcDirs = [‘src/main/java’]
res.srcDirs = [‘src/main/res’]
manifest.srcFile ‘src/main/AndroidManifest.xml’
}
}
externalNativeBuild {
cmake {
path ‘src/main/jni/CMakeLists.txt’ //配置地址修改
}
}
4.5.2 project/build.gradle(APP_ABI)
gradle.afterProject { project ->
if (project.pluginManager.hasPlugin(‘com.android.application’)
|| project.pluginManager.hasPlugin(‘com.android.library’)
|| project.pluginManager.hasPlugin(‘com.android.test’)
|| project.pluginManager.hasPlugin(‘com.android.feature’) ) {
if (true) {
gradle.println(“Override build ABIs for the project ${project.name}”)
project.android {
splits {
abi {
enable true
universalApk false
//reset()
//include ‘armeabi-v7a’
//include ‘arm64-v8a’
//include ‘x86’
//include ‘x86_64’
}
}
}
}
if (true) {
gradle.println(“Override lintOptions for the project ${project.name}”)
project.android {
lintOptions {
// checkReleaseBuilds false
abortOnError false
}
}
}
// (you still need to re-build OpenCV with debug information to debug it)
if (true) {
gradle.println(“Override doNotStrip-debug for the project ${project.name}”)
project.android {
buildTypes {
debug {
packagingOptions {
doNotStrip ‘**/*.so’ // controlled by OpenCV CMake scripts
}
}
}
}
}
if (false || project.hasProperty(“doNotStrip”)) {
gradle.println(“Override doNotStrip-release for the project ${project.name}”)
project.android {
buildTypes {
release {
packagingOptions {
doNotStrip ‘**/*.so’ // controlled by OpenCV CMake scripts
}
}
}
}
}
}
}
4.5.3 OpenCV API level is android-21(opencv-sdk的minSdkVersion为21)
D:\Code\Android\MyOpenCV\app\src\main\jni\CMakeLists.txt : C/C++ debug|x86 : CMake Warning at D:/Code/Android/MyOpenCV/sdk/native/jni/abi-x86/OpenCVConfig.cmake:105 (message):
Minimum required by OpenCV API level is android-21
Call Stack (most recent call first):
D:/Code/Android/MyOpenCV/sdk/native/jni/OpenCVConfig.cmake:44 (include)
CMakeLists.txt:8 (find_package)
请将minSdkVersion设置为21
minSdkVersion 21
4.5.4 OS independent 冲突
现象
More than one file was found with OS independent path ‘META-INF/native-image/ios-x86_64/jnijavacpp/reflect-config.json’.
解决
packagingOptions {
exclude ‘META-INF/proguard/androidx-annotations.pro’
exclude ‘META-INF/native-image/**’
}
4.5.5 修改DetectionBasedTracker_jni.cpp
文件
将示例项目中的头文件copy到DetectionBasedTracker_jni.cpp
头部
#include <DetectionBasedTracker_jni.h>
#include <opencv2/core.hpp>
#include <opencv2/objdetect.hpp>
#include
#include
#include <android/log.h>
#define LOG_TAG “FaceDetection/DetectionBasedTracker”
#define LOGD(…) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, VA_ARGS))
using namespace std;
using namespace cv;
inline void vector_Rect_to_Mat(vector
{
mat = Mat(v_rect, true);
}
class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
{
public:
CascadeDetectorAdapter(cv::Ptrcv::CascadeClassifier detector):
IDetector(),
Detector(detector)
{
LOGD(“CascadeDetectorAdapter::Detect::Detect”);
CV_Assert(detector);
}
void detect(const cv::Mat &Image, std::vectorcv::Rect &objects)
{
LOGD(“CascadeDetectorAdapter::Detect: begin”);
LOGD(“CascadeDetectorAdapter::Detect: scaleFactor=%.2f, minNeighbours=%d, minObjSize=(%dx%d), maxObjSize=(%dx%d)”, scaleFactor, minNeighbours, minObjSize.width, minObjSize.height, maxObjSize.width, maxObjSize.height);
Detector->detectMultiScale(Image, objects, scaleFactor, minNeighbours, 0, minObjSize, maxObjSize);
LOGD(“CascadeDetectorAdapter::Detect: end”);
}
virtual ~CascadeDetectorAdapter()
{
LOGD(“CascadeDetectorAdapter::Detect::~Detect”);
}
private:
CascadeDetectorAdapter();
cv::Ptrcv::CascadeClassifier Detector;
};
struct DetectorAgregator
{
cv::Ptr mainDetector;
cv::Ptr trackingDetector;
cv::Ptr tracker;
DetectorAgregator(cv::Ptr& _mainDetector, cv::Ptr& _trackingDetector):
mainDetector(_mainDetector),
trackingDetector(_trackingDetector)
{
CV_Assert(_mainDetector);
CV_Assert(_trackingDetector);
DetectionBasedTracker::Parameters DetectorParams;
tracker = makePtr(mainDetector, trackingDetector, DetectorParams);
}
};
将示例项目中每个方法的实现copcy到对应方法上(nativeCreateObject为例)
修改前
/*
-
Class: com_example_myopencv_DetectionBasedTracker
-
Method: nativeCreateObject
-
Signature: (Ljava/lang/String;I)J
*/
JNIEXPORT jlong JNICALL Java_com_example_myopencv_DetectionBasedTracker_nativeCreateObject
(JNIEnv *, jclass, jstring, jint);
修改后
/*
-
Class: com_example_myopencv_DetectionBasedTracker
-
Method: nativeCreateObject
-
Signature: (Ljava/lang/String;I)J
*/
JNIEXPORT jlong JNICALL Java_com_example_myopencv_DetectionBasedTracker_nativeCreateObject
(JNIEnv * jenv, jclass, jstring jFileName, jint faceSize)
{
LOGD(“Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject enter”);
const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL);
string stdFileName(jnamestr);
jlong result = 0;
LOGD(“Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject”);
try
{
cv::Ptr mainDetector = makePtr(
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
文末
我总结了一些Android核心知识点,以及一些最新的大厂面试题、知识脑图和视频资料解析。
需要的小伙伴私信【学习】我免费分享给你,以后的路也希望我们能一起走下去。(谢谢大家一直以来的支持,需要的自己领取)
直接点击链接也可以领取哦!
部分资料一览:
- 330页PDF Android学习核心笔记(内含8大板块)
-
Android学习的系统对应视频
-
Android进阶的系统对应学习资料
- Android BAT大厂面试题(有解析)
文末
我总结了一些Android核心知识点,以及一些最新的大厂面试题、知识脑图和视频资料解析。
需要的小伙伴私信【学习】我免费分享给你,以后的路也希望我们能一起走下去。(谢谢大家一直以来的支持,需要的自己领取)
直接点击链接也可以领取哦!
部分资料一览:
- 330页PDF Android学习核心笔记(内含8大板块)
[外链图片转存中…(img-FQl9AcWp-1710670887859)]
[外链图片转存中…(img-SSxcbzSD-1710670887860)]
-
Android学习的系统对应视频
-
Android进阶的系统对应学习资料
[外链图片转存中…(img-uIiK6gE3-1710670887860)]
- Android BAT大厂面试题(有解析)