2

我在 Android 中使用 OpenCV 非自由模块时遇到问题。我阅读了本教程 https://sites.google.com/site/wghsite/technical-notes/sift_surf_opencv_android

但是在运行 ndk-build 之后,它显示以下错误..

guru@guru-Aspire-5738:~/Android/OpenCVWorkspace/sift_opencv_android/jni$ ~/Android/android-ndk-r9/ndk-build 

Install        : libopencv_java.so => libs/armeabi-v7a/libopencv_java.so  
Install        : libnonfree.so => libs/armeabi-v7a/libnonfree.so  
Compile++ thumb  : test_sift <= test_sift.cpp
/home/guru/Android/OpenCVWorkspace/sift_opencv_android/jni/test_sift.cpp:2:33: fatal error: opencv2/core/core.hpp: No such file or directory
compilation terminated.  
make: ***[/home/guru/Android/OpenCVWorkspace/sift_opencv_android/obj/local/armeabi-v7a/objs/test_sift/test_sift.o] Error 1

这是我的代码..

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>


using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
 if( argc != 3)
 {
 cout <<" Usage: sift input_image output_image" << endl;
 return -1;
 }

 //cv::initModule_nonfree();
 //cout <<"initModule_nonfree() called" << endl;

 Mat image;
 image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
 if(! image.data )
 {
 cout <<  "Could not open or find the image" << std::endl ;
 return -1;
 }

 vector<KeyPoint> keypoints;
 Mat descriptors;

 // Create a SIFT keypoint detector.
 SiftFeatureDetector detector;
 detector.detect(image, keypoints);
 cout << "Detected " << (int) keypoints.size() << " keypoints" <<endl;

 // Compute feature description.
 detector.compute(image,keypoints, descriptors);
 cout << "Computed feature."<<endl;

 // Store description to "descriptors.des".
 FileStorage fs;
 fs.open("descriptors.des", FileStorage::WRITE);
 cout << "Opened file to store the features."<<endl;
 fs << "descriptors" << descriptors;
 cout << "Finished writing file."<<endl;
 fs.release();
 cout << "Released file."<<endl;

 // Show keypoints in the output image.
 Mat outputImg;
 Scalar keypointColor = Scalar(0, 0, 255);
 drawKeypoints(image, keypoints, outputImg, keypointColor, DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
 cout << "Drew keypoints in output image file."<<endl;


 namedWindow("Output image", CV_WINDOW_NORMAL );
 imshow("Output image", outputImg);
 waitKey(0);


 cout << "Generate the output image."<<endl;
 imwrite(argv[2], outputImg);

 cout << "Done."<<endl;
 return 0;
}

我的 Android.mk 是..

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := sift_prebuilt
LOCAL_SRC_FILES := libnonfree.so
include $(PREBUILT_SHARED_LIBRARY)



include $(CLEAR_VARS)
LOCAL_MODULE    := opencv_java_prebuilt
LOCAL_SRC_FILES := libopencv_java.so
include $(PREBUILT_SHARED_LIBRARY)


LOCAL_C_INCLUDE:= /home/guru/Android/OpenCV-2.4.6-android-sdk/sdk/native/jni/include
LOCAL_MODULE    := test_sift 
LOCAL_LDLIBS +=  -llog -ldl
LOCAL_SHARED_LIBRARIES := sift_prebuilt opencv_java_prebuilt
LOCAL_SRC_FILES := test_sift.cpp

include $(BUILD_EXECUTABLE)

请帮助..

4

1 回答 1

2

我想你忘了包括“opencv2/core/core.hpp”。这是您的包括:

LOCAL_C_INCLUDE:= /home/guru/Android/OpenCV-2.4.6-android-sdk/sdk/native/jni/include

将“opencv2/core/core.hpp”添加到LOCAL_C_INCLUDE.

于 2013-09-24T01:20:17.857 回答