我正在使用SURF进行特征提取的代码,但它给出了我的错误,下面是我的程序
#include <iostream>
#include <sys/stat.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <opencv/cv.h>
#include "opencv2/features2d/features2d.hpp"
#include <opencv/highgui.h>
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <vector>
#pragma comment (lib , "opencv_core244d.lib")
#pragma comment (lib ,"opencv_highgui244d.lib")
#pragma comment(lib , "opencv_imgproc244d.lib")
#pragma comment(lib ,"opencv_video244.lib")
using namespace cv ;
int main(int argc, char *argv[])
{
Mat image1, outImg1, image2, outImg2;
vector<KeyPoint> keypoints1, keypoints2;
image1 = imread("1.jpg",0);
image2 = imread("2.jpg",0);
SurfFeatureDetector surf(2500);
surf.detect(image1, keypoints1);
surf.detect(image2, keypoints2);
drawKeypoints(image1, keypoints1, outImg1, Scalar(255,255,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(image2, keypoints2, outImg2, Scalar(255,255,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
namedWindow("SURF detector img1");
imshow("SURF detector img1", outImg1);
namedWindow("SURF detector img2");
imshow("SURF detector img2", outImg2);
SurfDescriptorExtractor surfDesc;
Mat descriptors1, descriptors2;
surfDesc.compute(image1, keypoints1, descriptors1);
surfDesc.compute(image2, keypoints2, descriptors2);
cv::waitKey();
return 0;
}
这是错误的
Error2 error LNK2019: unresolved external symbol "public: void __thiscall cv::DescriptorExtractor::compute(class cv::Mat const &,class std::vector<class cv::KeyPoint,class std::allocator<class cv::KeyPoint> > &,class cv::Mat &)const " (?compute@DescriptorExtractor@cv@@QBEXABVMat@2@AAV?$vector@VKeyPoint@cv@@V?$allocator@VKeyPoint@cv@@@std@@@std@@AAV32@@Z) referenced in function _main
Error3 error LNK2019: unresolved external symbol "public: __thiscall cv::SURF::SURF(void)" (??0SURF@cv@@QAE@XZ) referenced in function _main
Error4 error LNK2019: unresolved external symbol "void __cdecl cv::drawKeypoints(class cv::Mat const &,class std::vector<class cv::KeyPoint,class std::allocator<class cv::KeyPoint> > const &,class cv::Mat &,class cv::Scalar_<double> const &,int)" (?drawKeypoints@cv@@YAXABVMat@1@ABV?$vector@VKeyPoint@cv@@V?$allocator@VKeyPoint@cv@@@std@@@std@@AAV21@ABV?$Scalar_@N@1@H@Z) referenced in function _main
Error5 error LNK2019: unresolved external symbol "public: void __thiscall cv::FeatureDetector::detect(class cv::Mat const &,class std::vector<class cv::KeyPoint,class std::allocator<class cv::KeyPoint> > &,class cv::Mat const &)const " (?detect@FeatureDetector@cv@@QBEXABVMat@2@AAV?$vector@VKeyPoint@cv@@V?$allocator@VKeyPoint@cv@@@std@@@std@@0@Z) referenced in function _main
Error6 error LNK2019: unresolved external symbol "public: __thiscall cv::SURF::SURF(double,int,int,bool,bool)" (??0SURF@cv@@QAE@NHH_N0@Z) referenced in function _main
Error7 error LNK2019: unresolved external symbol "public: virtual __thiscall cv::FeatureDetector::~FeatureDetector(void)" (??1FeatureDetector@cv@@UAE@XZ) referenced in function "public: virtual __thiscall cv::Feature2D::~Feature2D(void)" (??1Feature2D@cv@@UAE@XZ)
Error8 error LNK2019: unresolved external symbol "public: virtual __thiscall cv::DescriptorExtractor::~DescriptorExtractor(void)" (??1DescriptorExtractor@cv@@UAE@XZ) referenced in function "public: virtual __thiscall cv::Feature2D::~Feature2D(void)" (??1Feature2D@cv@@UAE@XZ)
Error9 error LNK1120: 7 unresolved externals
当我在VS2010中编写代码时没有显示错误,但是当我调试它时它显示错误,并且我可以使用相同的代码进行视频
答案 0 :(得分:5)
冲浪是非自由的,这就是错误发生的原因,
需要增加以下内容:
#include "opencv2/nonfree/nonfree.hpp" // SURF is nonfree
在main()中执行任何其他操作之前:
cv::initModule_nonfree();
和ofc链接到opencv_nonfree244.lib
答案 1 :(得分:1)
转到Project Properties -> Linker -> General -> Additional Library Directories
并确保该列表包含opencv库安装路径的路径。这应该类似<\path\to\opencv\build>\lib\
。
转到Project Properties -> Linker -> Input -> Additional Dependencies
,然后将以下库名称作为依赖项粘贴到调试配置中:
opencv_core244d.lib
opencv_highgui244d.lib
opencv_imgproc244d.lib
opencv_features2d244d.lib
以及发布配置中的以下内容:
opencv_core244.lib
opencv_highgui244.lib
opencv_imgproc244.lib
opencv_features2d244.lib