gpt4 book ai didi

python - 如何创建关键点来计算 SIFT?

转载 作者:太空宇宙 更新时间:2023-11-03 21:05:41 26 4
gpt4 key购买 nike

我正在使用 OpenCV-Python。

我已经使用 cv2.cornerHarris 识别角点。输出类型为 dst

我需要计算角点的 SIFT 特征。 sift.compute() 的输入必须是 KeyPoint 类型。

我不知道如何使用 cv2.KeyPoint()

我该怎么做?

最佳答案

Harris 检测器返回 dst,与您的图像具有相同的形状。哈里斯在它认为是角球的地方做标记。所以,你必须从 dst 中提取关键点。

def harris(self, img):
'''
Harris detector
:param img: an color image
:return: keypoint, image with feature marked corner
'''

gray_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray_img = np.float32(gray_img)
dst = cv2.cornerHarris(gray_img, 2, 3, 0.04)
result_img = img.copy() # deep copy image

# Threshold for an optimal value, it may vary depending on the image.
result_img[dst > 0.01 * dst.max()] = [0, 0, 255]

# for each dst larger than threshold, make a keypoint out of it
keypoints = np.argwhere(dst > 0.01 * dst.max())
keypoints = [cv2.KeyPoint(x[1], x[0], 1) for x in keypoints]

return (keypoints, result_img)

关于python - 如何创建关键点来计算 SIFT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29415719/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com