OpenCV4入门112:SURF特征检测及匹配
索引地址:系列索引
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/nonfree/nonfree.hpp" #include <iostream> using namespace cv;
static void ShowHelpText();
int main(int argc, char **argv) { system("color 2F");
ShowHelpText();
Mat srcImage1 = imread("1.jpg", 1); Mat srcImage2 = imread("2.jpg", 1); if (!srcImage1.data || !srcImage2.data) { printf("读取图片错误,请确定目录下是否有imread函数指定名称的图片存在~! \n"); return false; } imshow("原始图1", srcImage1); imshow("原始图2", srcImage2);
int minHessian = 400; SurfFeatureDetector detector(minHessian); std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect(srcImage1, keypoints_1); detector.detect(srcImage2, keypoints_2);
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);
imshow("特征点检测效果图1", img_keypoints_1); imshow("特征点检测效果图2", img_keypoints_2);
waitKey(0); return 0; }
void ShowHelpText() { printf("\n\n\t\t\t非常感谢购买《OpenCV3编程入门》一书!\n"); printf("\n\n\t\t\t此为本书OpenCV2版的第89个配套示例程序\n"); printf("\n\n\t\t\t 当前使用的OpenCV版本为:" CV_VERSION); printf("\n\n ----------------------------------------------------------------------------\n"); printf("\n\n\t欢迎来到【SURF特征点检测】示例程序\n\n"); printf("\n\t按键操作说明: \n\n" "\t\t键盘按键任意键- 退出程序\n\n"); }
|