Python Opencv实践 - FAST关键点检测

参考资料:

FAST角点检测算法笔记_亦枫Leonlew的博客-CSDN博客

【OpenCV-Python】28.OpenCV的特征检测——特征点检测_opencv特征点检测_机器视觉小学徒的博客-CSDN博客

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

img = cv.imread("../SampleImages/shunsuke.jpg", cv.IMREAD_COLOR)

#FAST关键点检测
#1. 创建FAST对象
#   cv.FastFeatureDetector_create()
fast = cv.FastFeatureDetector_create()
#2. 设置阈值
#    fast.setThreshold(thresh)
#    thresh: 阈值
fast.setThreshold(20)
#3. 确保非极大值抑制打开
fast.setNonmaxSuppression(1)
#4. 调用FAST对象的detect方法检测关键点
#   kp = fast.detect(img, None)
#   kp:关键点信息
#   img:待检测图像
keypoints = fast.detect(img, None)

#绘制关键点
img_threshold20 = img.copy()
cv.drawKeypoints(img_threshold20, keypoints, img_threshold20, (0,255,0))
#关闭非极大值抑制
fast.setNonmaxSuppression(0)
keypoints = fast.detect(img, None)
img_nonmaxsuppression_disabled = img.copy()
cv.drawKeypoints(img_nonmaxsuppression_disabled, keypoints, img_nonmaxsuppression_disabled, (0,255,0))

#显示图像
fig,axes = plt.subplots(nrows=1, ncols=3, figsize=(16,16), dpi=100)
axes[0].set_title("Original")
axes[0].imshow(img[:,:,::-1])
axes[1].set_title("Non Max Suppression Enabled")
axes[1].imshow(img_threshold20[:,:,::-1])
axes[2].set_title("Non Max Suppression Disabled")
axes[2].imshow(img_nonmaxsuppression_disabled[:,:,::-1])

猜你喜欢

转载自blog.csdn.net/vivo01/article/details/132817274
今日推荐