OpenCV版本为2.4.12,Visual Studio 开发环境中运行。
在图像特征检测、匹配中出现了运行错误:
Unhandled exception at 0x569D1C00 (opencv_features2d2412d.dll) in Macher.exe: 0xC0000005: Access violation reading location 0x00000000.
经过调试、定位,问题出现在下列语句:
detector->detect(image1, keypoints1);
detector->detect(image2, keypoints2);
发现detector对象为NULL,处于没被初始化的状态。
奇怪!明明使用了下面的语句进行了初始化:
detector = FeatureDetector::create(detectorName);
extractor = DescriptorExtractor::create(descriptorName);
问题就在这个create函数上。根据网上搜集的答案,总结如下:
用create之前要先加上:initModule_nonfree();
当然首先需要包含头文件:#include "opencv2/nonfree/nonfree.hpp"
多谢这句话:“注意initModule_<modulename>()函数,这个函数要在create前使用,才可以动态的创建算法,不然那个create的指针很野哦。大家都懂的。如果要使用SURF、SIFT算法,就要调用inintModule_nonfree(),要使用EM算法,就要先调用initModule_ml()。”