错误:(49)未定义对'的引用;cv::Stitcher::createDefault(bool)和#x27;在Android中使用OpenCV本机
我正在开发一个Android应用程序,它涉及一些图像处理。我现在使用OpenCV缝合图像。我用C++做的。所以,我把OpenCV(本地C++和java)集成到我的Android项目中。但是,当我使用C++中的拼接特性并运行我的项目时,它就给了我编译错误。错误:(49)未定义对'的引用;cv::Stitcher::createDefault(bool)和#x27;在Android中使用OpenCV本机,android,c++,opencv,java-native-interface,opencv-stitching,Android,C++,Opencv,Java Native Interface,Opencv Stitching,我正在开发一个Android应用程序,它涉及一些图像处理。我现在使用OpenCV缝合图像。我用C++做的。所以,我把OpenCV(本地C++和java)集成到我的Android项目中。但是,当我使用C++中的拼接特性并运行我的项目时,它就给了我编译错误。 这是我的整个C++库(原生LIB)用于拼接图像。 // // Created by Acer on 3/28/2018. // #include <jni.h> #include <string> #include
这是我的整个C++库(原生LIB)用于拼接图像。
//
// Created by Acer on 3/28/2018.
//
#include <jni.h>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <iostream>
#include <fstream>
#include <opencv2/stitching.hpp>
using namespace std;
using namespace cv;
extern "C" {
jstring
Java_media_memento_memento_SphereCameraActivity_stitchPhotos(
JNIEnv *env,
jobject /* this */, jlong addrMat, jlong addrNewMat, jlongArray addrsPreviews) {
Mat &in = *(Mat *) addrMat;
Mat &newMat = *(Mat *) addrNewMat;
int size = env->GetArrayLength(addrsPreviews);
jlong *addrPreviewArray = env->GetLongArrayElements(addrsPreviews, NULL);
vector<Mat> imgs(size);
for (long i = 0; i < size; i++) {
jlong previewAddress = addrPreviewArray[i];
imgs[i] = *(Mat *) previewAddress;
}
bool try_use_gpu = false;
Mat pano;
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status = stitcher.stitch(imgs, pano);
if (status != Stitcher::OK) {
//the return map would be null
} else {
//copy the map.
pano.copyTo(newMat);
newMat = pano;
}
env->ReleaseLongArrayElements(addrsPreviews, addrPreviewArray, 0);
}
}
当我运行时,我得到了提到的错误
Error:error: linker command failed with exit code 1 (use -v to see invocation)
Error:(49) undefined reference to 'cv::Stitcher::createDefault(bool)'
Error:(50) undefined reference to 'cv::Stitcher::stitch(cv::_InputArray const&, cv::_OutputArray const&)'
我找到了这个链接-。但是我相信我正确地集成了C++ OpenCV本地LIB。这就是我可以使用其他库的原因。当我检查SDK文件夹中的文件时,stitching.hpp存在。那么,有什么可能以及如何解决呢?我遇到了一个非常类似的问题,通过在我的CMakeLists.txt文件中链接OpenCV SDK中的“libopencv_stitching.a”静态库解决了这个问题
file(GLOB CVLIBS
path/to/your/opencv/sdk/staticlibs/${ANDROID_ABI}/libopencv_stitching.a)
...
target_link_libraries( # Specifies the target library.
...
${CVLIBS}
# Links the target library to the log library
# included in the NDK.
${log-lib})
这个答案也很有用:我也有同样的问题。那么,你解决了这个问题吗?太棒了,今晚过得很愉快。
file(GLOB CVLIBS
path/to/your/opencv/sdk/staticlibs/${ANDROID_ABI}/libopencv_stitching.a)
...
target_link_libraries( # Specifies the target library.
...
${CVLIBS}
# Links the target library to the log library
# included in the NDK.
${log-lib})