White Record: "Opencv3 programming entry" P403 on Opencv extension module version differences

After Opencv3 version, the feature point detection on SURF, in addition to the change in the module header, and change the program usage. (When you run this program, I use the VS2019 + Opencv4.1.1)

The difference:
position module header file has changed
increase xfeatures2d namespace (otherwise undefined identifier is displayed SURF)
③SurfFeatureDetector Detector (minHessian) changed:
Ptr = SURF :: the Create Detector (minHessian);
④detector.detect (srcImage1, keypoints_1);
detector.detect (srcImage2, keypoints_2); change:
detector-> Detect (srcImage1, keypoints_1);
detector-> Detect (srcImage2, keypoints_2);

A .SURF algorithm
feature detection
scale space
selection invariance: illumination invariance, rotation invariance
feature vector

Two .SURF algorithm theory
(not repeat them here, in terms of the book is very clear)

Three .API Introduction

cv::xfeatures2d::SURF::creat(double HessianThreshold = 100.
			     int nOctaves = 4,
			     int nOctaveLayers = 3,
			     bool extend = false,
			     bool upright = false
 			     )
 //upright = 0 表示计算选择不变性,1表示不计算,速度更快
 //HessianThreshold默认值在300——500之间
 //nOctaves = 4 表示四个尺度空间
 //nOctaveLayers 表示每个尺度的层数

drawKeypoints()函数
//(书上讲的很详细,看书即可)

IV. Source (compared with the book, pay attention to different places)

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/xfeatures2d/nonfree.hpp>
#include <iostream>

using namespace cv;
using namespace std;
using namespace xfeatures2d;

int main(int argc, char** argv)
{
	//【0】改变console字体颜色    
 	system("color 2F");

	//【1】载入源图片并显示
	Mat srcImage1 = imread("E:\\pictures\\27.jpg", 1);
 	Mat srcImage2 = imread("E:\\pictures\\28.jpg", 1);
 	if (!srcImage1.data || !srcImage2.data)//检测是否读取成功
 	{
 		printf("读取图片错误! \n"); return false;
 	}
 	imshow("原始图1", srcImage1);
 	imshow("原始图2", srcImage2);

	//【2】定义需要用到的变量和类
 	int minHessian = 400;//定义SURF中的hessian阈值特征点检测算子
 	Ptr<SURF> detector = SURF::create(minHessian); //指针数组
 	vector<KeyPoint> keypoints_1, keypoints_2;//vector模板类是能够存放任意类型的动态数组,能够增加和压缩数据

	//【3】调用detect函数检测出SURF特征关键点,保存在vector容器中
 	detector->detect(srcImage1, keypoints_1);
 	detector->detect(srcImage2, keypoints_2);

	//【4】绘制特征关键点.
 	Mat img_keypoints_1; Mat img_keypoints_2;
 	drawKeypoints(srcImage1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
 	drawKeypoints(srcImage2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT);

	//【5】显示效果图
 	imshow("特征点检测效果图1", img_keypoints_1);
 	imshow("特征点检测效果图2", img_keypoints_2);

	waitKey(0);
 	return 0;
}

Output:
Here Insert Picture Description
Here Insert Picture Description

Published 25 original articles · won praise 0 · Views 459

Guess you like

Origin blog.csdn.net/qq_45445740/article/details/103463706