#include<iostream>
//#include <opencv2/xfeatures2d.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void main()
{
double start, duration_ms;
cv::Mat mask1, mask2, imgshowcanny;
cv::Mat imgShow1, imgShow2, imgShow3;
// 声明并从data文件夹里读取两个rgb与深度图
cv::Mat rgb1 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\1.jpg", 0);
cv::Mat rgb2 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\2.jpg", 0);
cv::Mat rgb3 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\3.jpg", 0);
cv::Mat rgb4 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\4.jpg", 0);
cv::Mat rgb5 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\5.jpg", 0);
cv::Mat rgb6 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\6.jpg", 0);
cv::Mat rgb7 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\7.jpg", 0);
cv::Mat rgb8 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\8.jpg", 0);
cv::Mat rgb9 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\9.jpg", 0);
cv::Mat rgb10 = cv::imread("D:\\python_opencv\\source_image\\1123\\1\\10.jpg", 0);
vector< cv::KeyPoint > kp1, kp2, kp3, kp4, kp5, kp6, kp7, kp8, kp9, kp10; //关键点
mask1 = rgb1.clone();
//边缘检测
//cout << "Canny edge detection" << endl;
//mask1 = Mat::zeros(rgb1.size(), CV_8UC1);
//mask2 = Mat::zeros(rgb2.size(), CV_8UC1);
cv::Canny(mask1, mask1, 50, 200, 3);
//cv::Canny(rgb2, mask2, 50, 150, 3);
cv::Mat element = getStructuringElement(MORPH_RECT, Size(3, 3));
dilate(mask1, mask1, element);
cv::imwrite("F:/study work/Visual Odometry dev/VO_practice_2016.4/算法测试/KAZE算法/data/mask1.jpg", mask1);
imgshowcanny = mask1.clone();
cv::resize(imgshowcanny, imgshowcanny, cv::Size(imgshowcanny.cols / 2, imgshowcanny.rows / 2));
cv::imshow("mask", imgshowcanny);
//特征检测算法:AKAZE
cv::Ptr<cv::AKAZE> akaze = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.001f, 4, 4, KAZE::DIFF_PM_G2);
Mat descriptors_1, descriptors_2, descriptors_3, descriptors_4, descriptors_5, descriptors_6, descriptors_7, descriptors_8, descriptors_9, descriptors_10;
start = double(getTickCount());
akaze->detectAndCompute(rgb1, mask1, kp1, descriptors_1, false);
duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();//计时
std::cout << "It took " << duration_ms << " ms to detect features in pic1 using AKAZE." << std::endl;
start = double(getTickCount());
akaze->detectAndCompute(rgb2, cv::Mat(), kp2, descriptors_2, false);
duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();//计时
std::cout << "It took " << duration_ms << " ms to detect features in pic2 using AKAZE." << std::endl;
akaze->detectAndCompute(rgb3, cv::Mat(), kp3, descriptors_3, false);
akaze->detectAndCompute(rgb4, cv::Mat(), kp4, descriptors_4, false);
akaze->detectAndCompute(rgb5, cv::Mat(), kp5, descriptors_5, false);
akaze->detectAndCompute(rgb6, cv::Mat(), kp6, descriptors_6, false);
akaze->detectAndCompute(rgb7, cv::Mat(), kp7, descriptors_7, false);
akaze->detectAndCompute(rgb8, cv::Mat(), kp8, descriptors_8, false);
akaze->detectAndCompute(rgb9, cv::Mat(), kp9, descriptors_9, false);
akaze->detectAndCompute(rgb10, cv::Mat(), kp10, descriptors_10, false);
// 可视化, 显示特征点
cout << "Key po
基于KAZE的图像配准代码
最新推荐文章于 2024-02-25 17:08:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)