BruteForceMatcher报错“无法识别的标识符”



本文转自:http://blog.csdn.net/panda1234lee/article/details/8611363

最近Opencv升级比较快,从2.4.0到2.4.1到2.4.2,使得我这个还在使用2.3.1的人很不好意思,而且听说新版本里添加了tbb并行功能,急着想用这些功能的我赶紧下了2.4.2。

按部就班的解压、设置c++目录(我使用的是vs2008)、设置环境变量......一系列的完成之后,想用一下surf算法,就尝试着把pdf文档里的代码复制到了vs里,运行一下,发现不行,报错。。。瞬间有点被骗的感觉,这可是从官方发布的pdf里的最新代码啊!!!

  1. #include <iostream>  
  2. #include "opencv2/core/core.hpp"  
  3. #include "opencv2/features2d/features2d.hpp"  
  4. #include "opencv2/highgui/highgui.hpp"  
  5. #include "opencv2/nonfree/nonfree.hpp"  
  6. #include "opencv2/nonfree/features2d.hpp"  
  7.    
  8. using namespace std;  
  9. using namespace cv;  
  10. char *path1="D:\\TestData\\cvtest\\src\\left01.jpg";  
  11. char *path2="D:\\TestData\\cvtest\\src\\left03.jpg";  
  12.    
  13. int main()  
  14. {  
  15.     Mat src1=imread(path1,0);  
  16.    
  17.     /*namedWindow("image",CV_WINDOW_AUTOSIZE); 
  18.     imshow("image", src1); 
  19.     waitKey(0);*/  
  20.    
  21.     Mat src2=imread(path2,0);  
  22.     SurfFeatureDetector detector(400);  
  23.     vector<KeyPoint> keypoint1,keypoint2;  
  24.     detector.detect(src1,keypoint1);  
  25.     detector.detect(src2,keypoint2);  
  26.    
  27.     SurfDescriptorExtractor extractor;  
  28.     Mat descriptor1,descriptor2;  
  29.     extractor.compute(src1,keypoint1,descriptor1);  
  30.     extractor.compute(src2,keypoint2,descriptor2);  
  31.    
  32.     BruteForceMatcher<L2<float>> matcher;  
  33.     vector<DMatch>matches;  
  34.     matcher.match(descriptor1,descriptor2,matches);  
  35.    
  36.     namedWindow("matches",1);  
  37.     Mat img_matches;  
  38.     drawMatches(src1,keypoint1,src2,keypoint2,matches,img_matches);  
  39.     imshow("matches",img_matches);  
  40.     cvWaitKey(0);  
  41.     return 0;  
  42. }  
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/nonfree/features2d.hpp"
 
using namespace std;
using namespace cv;
char *path1="D:\\TestData\\cvtest\\src\\left01.jpg";
char *path2="D:\\TestData\\cvtest\\src\\left03.jpg";
 
int main()
{
    Mat src1=imread(path1,0);
 
    /*namedWindow("image",CV_WINDOW_AUTOSIZE);
    imshow("image", src1);
    waitKey(0);*/
 
    Mat src2=imread(path2,0);
    SurfFeatureDetector detector(400);
    vector<KeyPoint> keypoint1,keypoint2;
    detector.detect(src1,keypoint1);
    detector.detect(src2,keypoint2);
 
    SurfDescriptorExtractor extractor;
    Mat descriptor1,descriptor2;
    extractor.compute(src1,keypoint1,descriptor1);
    extractor.compute(src2,keypoint2,descriptor2);
 
    BruteForceMatcher<L2<float>> matcher;
    vector<DMatch>matches;
    matcher.match(descriptor1,descriptor2,matches);
 
    namedWindow("matches",1);
    Mat img_matches;
    drawMatches(src1,keypoint1,src2,keypoint2,matches,img_matches);
    imshow("matches",img_matches);
    cvWaitKey(0);
    return 0;
}

到群里问,大家也刚用2.4.2不久,只有个达人告诉我是头文件的问题。我试着去找了一下,发现2.3.1的include文件和2.4.2的差别很大,新版本里多了很多东西,对比了一下features2d.hpp这个文件,发现原先包含在features2d.hpp的BruteForceMatcher现在根本不在features2d.hpp中,我试着去查找其他有可能在的hpp文件,找了几个,发现这不是解决问题的办法,问google吧!在搜了一下之后发现,还真有人碰到了这个问题,也确实是头文件的问题:缺少了#include<opencv2/legacy/legacy.hpp>,加了之后,发现之前的错误确实没了。

但是新的问题出来了,说link出现问题,没经验的我还是只能问google(谷歌确实强大啊!!!),牛人一针见血的指出了问题所在:For those who would have the same problem, make sure you have ALL the right linker inputs (configuration -> linker -> inputs), included dlls such as opencv, highgui etc.在右键“属性”->"链接器"->“输入”->"附加依赖项"把新输入的legacy的静态文件opencv_legacy242d.lib加进来就ok了!

遇到的问题及解决:
1、大量的.dll文件(如msvcr100d.dll)未加载,这个可能是一些包含的相关的.dll文件的路径没加入到PATH中,可以找到位置后加入PATH,或者在工程调试选项中 设置对 源服务器的支持 与 microsoft符号服务器 的支持(需联网)。
2、参考 http://www.cnblogs.com/ll2008swu/archive/2012/07/23/2605639.html 在做2维特征提取时,发现SurfFeatureDetector并不在opencv2/features2d/features2d.hpp 而是在opencv2/nonfree/features2d.hpp
BruteForceMatcher  需加入opencv2/nonfree/features2d.hpp
包含上面文件最终还需加入 opencv2/legacy/legacy.hpp
//同时为正常link,须Linker下加入-lopencv_nonfree240(不然会出现error LNK2019: 无法解析的外部符号的问题)。

使用VC者依版本将opencv_nonfree242d.lib所在位置加入Linker路径设定中即可顺利执行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值