首页 > 其他 > 详细

角点检测

时间:2021-03-05 09:56:17      阅读:29      评论:0      收藏:0      [点我收藏+]
import cv2 as cv
import numpy as np

filename = ‘JG.png‘
img = cv.imread(filename)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
_, img2 = cv.threshold(gray, 0, 0xff, cv.THRESH_OTSU)
# cv.imshow(‘ordinary‘, img2)
# FAST角点检测算法:
fast = cv.FastFeatureDetector_create(threshold=40, nonmaxSuppression=True, type=cv.FAST_FEATURE_DETECTOR_TYPE_9_16)
kp = fast.detect(img, None)
cv.drawKeypoints(img, kp, img, color=(255, 255, 255))

# SURF角点检测
minHessian = 1000
detector = cv.xfeatures2d.SURF_create(minHessian)
descriptor = cv.xfeatures2d.SURF_create()
matcher1 = cv.DescriptorMatcher_create(‘BruteForce‘)
# 检测特征点
keyPoint1 = detector.detect(img)
keyPoint2 = detector.detect(img2)
# 计算特征点对应描述子
_, descriptor1 = descriptor.compute(img, keyPoint1)
_, descriptor2 = descriptor.compute(img2, keyPoint2)
# 描述子匹配
matches = matcher1.match(descriptor1, descriptor2)
img_matches = np.empty(img2.shape)
img_matches1 = cv.drawMatches(img, keyPoint1, img2, keyPoint2, matches, img_matches)
cv.imshow(‘img_matches‘, img_matches1)
cv.waitKey()
print(‘keyPoint1.size = ‘, len(keyPoint1))
print(‘keyPoint2.size = ‘, len(keyPoint2))

cv.waitKey()
cv.destroyAllWindows()

角点检测

原文:https://www.cnblogs.com/hanker99/p/14483859.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!