OpenCV学习问题记录(五)

1、特征点检测器与描述符
在这里插入图片描述
这些方法中基本都包括检测器和相应的描述符两个部分,以下为HOG类描述符SIFT和binary类的描述符BRISK的代码实现与对比。不过由于版权问题,HOG类在OpenCV中不能免费使用。

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

using namespace std;

void descKeypoints1()
{
	// load image from file and convert to grayscale
	cv::Mat imgGray;
	cv::Mat img = cv::imread("E:/传感器融合/SensorFusion/所有代码/所有代码/3_Camera/04_Tracking Image Features/gradient_filtering/images/img1.png");
	cv::cvtColor(img, imgGray, cv::COLOR_BGR2GRAY);

	// BRISK detector / descriptor
	cv::Ptr<cv::FeatureDetector> detector = cv::BRISK::create();
	vector<cv::KeyPoint> kptsBRISK;

	double t = (double)cv::getTickCount();
	detector->detect(imgGray, kptsBRISK);
	t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
	cout << "BRISK detector with n= " << kptsBRISK.size() << " keypoints in " << 1000 * t / 1.0 << " ms" << endl;

	cv::Ptr<cv::DescriptorExtractor> descriptor = cv::BRISK::create();
	cv::Mat descBRISK;
	t = (double)cv::getTickCount();
	descriptor->compute(imgGray, kptsBRISK, descBRISK);
	t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
	cout << "BRISK descriptor in " << 1000 * t / 1.0 << " ms" << endl;

	// visualize results
	cv::Mat visImage = img.clone();
	cv::drawKeypoints(img, kptsBRISK, visImage, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
	string windowName = "BRISK Results";
	cv::namedWindow(windowName, 1);
	imshow(windowName, visImage);

	// STUDENT CODE
	detector = cv::xfeatures2d::SIFT::create();
	vector<cv::KeyPoint> kptsSIFT;

	t = (double)cv::getTickCount();
	detector->detect(imgGray, kptsSIFT);
	t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
	cout << "SIFT detector with n= " << kptsSIFT.size() << " keypoints in " << 1000 * t / 1.0 << " ms" << endl;

	descriptor = cv::xfeatures2d::SiftDescriptorExtractor::create();
	cv::Mat descSIFT;
	t = (double)cv::getTickCount();
	descriptor->compute(imgGray, kptsSIFT, descSIFT);
	t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
	cout << "SIFT descriptor in " << 1000 * t / 1.0 << " ms" << endl;

	visImage = img.clone();
	cv::drawKeypoints(img, kptsSIFT, visImage, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
	windowName = "SIFT Results";
	cv::namedWindow(windowName, 2);
	imshow(windowName, visImage);
	cv::waitKey(0);

	// EOF STUDENT CODE
}

int main()
{
	descKeypoints1();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值