【opencv/feature2d module】(五)Feature Detection

本文介绍在OpenCV 4.0.1环境下,如何使用SIFT和SURF算法进行特征检测。这两种算法能在图像缩放、噪声、高亮度等环境下稳定检测特征,适用于图像匹配和识别任务。文章提供了在Windows平台下配置与使用这两个算法的详细步骤及代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

说在前面

  • opencv版本:4.0.1
  • 操作系统:win10
  • vs版本:2017
  • 官方文档:Feature Detection
  • 其他说明:自学,记录,demo

补充

Feature Detection

  • 检测特征我们首先我们得提取特征,那么哪些特征是我们关注的呢?
    • 这些特征在图像缩放、噪声、高亮度等环境下依然能被检测到,这些区域通常在图像中高对比度的地方,例如边;[ 原文:To perform reliable recognition, it is important that the features extracted from the training image be detectable even under changes in image scale, noise and illumination. Such points usually lie on high-contrast regions of the image, such as object edges.]
    • 这些特征的相对位置不会因为在不同的图像中而改变。[原文:Another important characteristic of these features is that the relative positions between them in the original scene shouldn’t change from one image to another. ]

Scale-invariant feature transform(SIFT)

Speeded Up Robust Features(SURF)

Code

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

using namespace cv;
using namespace cv::xfeatures2d;
using std::cout;
using std::endl;
int main()
{
	Mat src = imread("1.jpg", IMREAD_GRAYSCALE);
	if (src.empty())
	{
		cout << "Could not open or find the image!\n" << endl;
		return -1;
	}
	//-- Step 1: Detect the keypoints using SURF Detector
	int minHessian = 400;
	Ptr<SURF> detector = SURF::create(minHessian);//SURF
	//Ptr<SIFT> detector = SIFT::create();//SIFT
	std::vector<KeyPoint> keypoints;
	detector->detect(src, keypoints);
	//-- Draw keypoints
	Mat img_keypoints;
	drawKeypoints(src, keypoints, img_keypoints);
	//-- Show detected (drawn) keypoints
	imshow("SURF Keypoints", img_keypoints);
	waitKey();
	return 0;
}

Result

  • SIFT

在这里插入图片描述

  • SURF

在这里插入图片描述


(o゚v゚)ノ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值