我正在尝试使用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 ++标准库。有人知道什么是错的吗?
答案 0 :(得分:0)
我包含了库
#include <opencv2/nonfree/features2d.hpp>
而不是
#include "opencv2/features2d/features2d.hpp"
以下是我用于应用SIFT检测器的完整库
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>