3

在此处输入图像描述

我正在使用 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 中编写代码时它没有显示错误,但是当我调试它时它显示错误,我可以将相同的代码用于视频吗

4

2 回答 2

5

冲浪不是免费的,这就是发生错误的原因,

它需要添加以下内容:

#include "opencv2/nonfree/nonfree.hpp"   // SURF is nonfree

在 main() 中执行任何其他操作之前:

cv::initModule_nonfree();

和 ofc 链接到 opencv_nonfree244.lib

于 2013-07-02T17:49:42.800 回答
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
于 2013-07-02T10:04:49.547 回答