在上一篇配置好opencv3.3.0的opencv_contrib扩展包的基础上
在学习SURF算法时,按照书上的程序写
//输入图像
Mat image = imread("E:\\paper_and_code\\20180906\\SURF_test_1008\\1.jpg");Mat outimage;//输出图像
vector<KeyPoint> keyPoints;//关键点SurfFeatureDetector surf(3000);//设置SURF特征检测器
surf.detect(image, keyPoints);//检测图像中的SURF特征点
但是出现很多错误(如下):
Error C2259 'cv::xfeatures2d::SURF': cannot instantiate abstract class
Error C2664 'cv::xfeatures2d::SURF::SURF(cv::xfeatures2d::SURF &&)': cannot convert argument 1 from 'int' to 'const cv::xfeatures2d::SURF &'
Error (active) no instance of constructor "cv::xfeatures2d::SURF::SURF" matches the argument listError (active) object of abstract class type "cv::xfeatures2d::SURF" is not allowed:
在查找了资料后了解到,在opencv3.3的版本中SurfFeatureDetector是SURF类 ,但在class SURF 中有纯虚函数,所以SurfFeatureDetector不能实例化,也就是SurfFeatureDetector不能直接定义对象。
把上述的代码改进为如下代码就可以使用了
//输入图像
Mat image = imread("E:\\paper_and_code\\20180906\\SURF_test_1008\\1.jpg");Mat outimage;//输出图像
vector<KeyPoint> keyPoints;//关键点
Mat dstImage;Ptr<SurfFeatureDetector> detector = SurfFeatureDetector::create(minHessian);//设置SURF特征检测器
detector->detectAndCompute(image, Mat(), keyPoints, dstImage);//检测图像中的SURF特征点