【问题标题】:Using MSER as a keypoint detector and SIFT as descriptor使用 MSER 作为关键点检测器和 SIFT 作为描述符
【发布时间】:2019-01-13 23:07:23
【问题描述】:

我正在尝试使用 MSER 提取关键点并使用 SIFT 作为特征描述符,然后匹配匹配的关键点。我使用 Python 做了以下操作:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img1 = cv2.imread('1.jpg')
img2 = cv2.imread('2.jpg') 

mser = cv2.MSER_create()

kp1 = mser.detect(img1)
kp2 = mser.detect(img2)

sift = cv2.xfeatures2d.SIFT_create()

kp1, des1 = sift.detectAndCompute(img1, kp1)
kp2, des2 = sift.detectAndCompute(img2, kp2)

bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)

good = []
for m, n in matches:
    if m.distance < 0.8 * n.distance:
        good.append(m)

good = sorted(good, key=lambda x: x.distance)
print len(good)

matching_result = cv2.drawMatches(img1, kp1, img2, kp2, good, None, flags=2)
cv2.imwrite('result.jpg', matching_result)

但是,得到以下错误:

kp1, des1 = sift.detectAndCompute(img1, kp1)
TypeError: mask is not a numpy array, neither a scalar

我该如何解决这个问题?而且,我使用检测器和描述符的方式是否正确?

【问题讨论】:

  • 而不是detectAndCompute python api中有compute方法吗?如果您想输入预先计算的关键点来描述它们,则应该使用它。

标签: python image opencv image-processing computer-vision


【解决方案1】:

您可以根据现有的关键点计算描述符。快速修复可以从您的代码中更改这些行:

kp1, des1 = sift.detectAndCompute(img1, kp1)
kp2, des2 = sift.detectAndCompute(img2, kp2)

改为使用 compute() 函数:

kp1, des1 = sift.compute(img1, kp1)
kp2, des2 = sift.compute(img2, kp2)

【讨论】:

  • 感谢您的友好回复。我在我的问题中的意思是我想使用 MSER 作为特征“检测器”,而 SIFT 作为特征“描述符”。所以,我需要同时使用两者。希望这能澄清这一点?
猜你喜欢
  • 2012-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-22
  • 2021-09-18
  • 2015-01-01
  • 1970-01-01
相关资源
最近更新 更多