简体   繁体   中英

Surf feature error in code

在此输入图像描述

I am doing code for feature extraction using SURF , but it give me error in it here below is my program

#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;
}

These are the error's

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

It didn't show me the error when i write code in VS2010 , but it show me error when i debug it , and can i use the same code for video

Surf is non free that's why error's occur ,

it needed the following additions:

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

before doing anything else in main():

cv::initModule_nonfree();

and ofc link to opencv_nonfree244.lib

Go to Project Properties -> Linker -> General -> Additional Library Directories and make sure the list contains the path to your opencv library installation path. This should resemble <\\path\\to\\opencv\\build>\\lib\\ .

Go to Project Properties -> Linker -> Input -> Additional Dependencies and then paste the following library names as dependencies in the debug configuration:

opencv_core244d.lib
opencv_highgui244d.lib
opencv_imgproc244d.lib
opencv_features2d244d.lib

and the following in release configuration:

opencv_core244.lib
opencv_highgui244.lib
opencv_imgproc244.lib
opencv_features2d244.lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM