我正在尝试使用 OpenCV 库编写我的第一个程序。我使用 XCode 4.6.2 作为 IDE,并且我已经按照很多教程来设置所有内容。这是我的一小段代码
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/nonfree/nonfree.hpp>
using namespace cv;
int main(int argc, const char * argv[])
{
String pathToImages="myPathToImages/";
Mat img1=imread(pathToImages+"im1.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat img2=imread(pathToImages+"im2.jpg",CV_LOAD_IMAGE_GRAYSCALE);
if( !img1.data || !img2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SIFT Detector
cv::SiftFeatureDetector detector;
std::vector<cv::KeyPoint> keypoints_1;
std::vector<cv::KeyPoint> keypoints_2;
detector.detect(img1, keypoints_1);
detector.detect(img2, keypoints_2);
//DO SOMENTHING
return 0;
}
如果我尝试构建它,我会收到此错误:
Undefined symbols for architecture x86_64:
"cv::FeatureDetector::~FeatureDetector()", referenced from:
cv::Feature2D::~Feature2D() in main.o
"cv::DescriptorExtractor::~DescriptorExtractor()", referenced from:
cv::Feature2D::~Feature2D() in main.o
"cv::SIFT::SIFT(int, int, double, double, double)", referenced from:
_main in main.o
"cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const", referenced from:
_main in main.o
"VTT for cv::SIFT", referenced from:
cv::SIFT::~SIFT() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我正在使用 libstdc++(GNU C++ 标准库)作为 C++ 标准库。有人知道出了什么问题吗?