1

In function keypoint_calc(cv::Mat)': FilePath/MyFirstOpenCVJNI-master/jni/first-opencvjni.cpp:35: undefined reference tocv::xfeatures2d::SIFT::create(int, int, double, double, double)'

./obj/local/arm64-v8a/objs/first-opencvjni/first-opencvjni.o: In function sift_descriptor(cv::Mat, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >)': FilePath/MyFirstOpenCVJNI-master/jni/first-opencvjni.cpp:45: undefined reference tocv::xfeatures2d::SIFT::create(int, int, double, double, double)'

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
#include <GLES2/gl2.h>
#include <android/log.h>

#include <opencv2/flann/flann.hpp>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <iostream>

#define  LOG_TAG    "cpp-file"

are my includes.

And on those mentioned lines i have following code.

cv::Ptr<cv::xfeatures2d::SIFT> feature_detector = cv::xfeatures2d::SIFT::create(200);

and

cv::Ptr<cv::xfeatures2d::SIFT> feature_detector = cv::xfeatures2d::SIFT::create(200);

I'm a noob to JNI any help would be highly appreciated.

1 Answers1

0

Undefined reference is reported by the linker. Your project (Android.mk or CMakeLists.txt) should include the OpenCV libraries. SIFT is patented, therefore it is not part of the free prebuilt OpenCV Android distribution. You can either build libnonfree.so separately and use it as a prebuilt shared library in your app, or compile SIFT as a static library.

Detailed instructions can be found here and here, but they may require adaptation for the latest (3.2) version, and the new NDK release. If you don't care about the latest version, you can also download prebuilt binaries.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307