python - cv2 SIFT +蛮力匹配没有给出好的结果

标签 python opencv image-processing feature-detection sift

因此,我尝试使用 SIFT 将热图像与 rgb 图像叠加以匹配特征和单应性,以便以后可以叠加它们。我拥有的代码与我拥有的大约 50% 的热/rgb 集一起使用,但是很多集,比如这个,给出了可怕的结果。我认为单应性很好,但不起作用,因为匹配很差。我会附上一些代码,任何关于如何调整它的建议都会很棒,因为我已经花了很长时间试图让我自己工作。谢谢!

MIN_MATCH_COUNT = 10
sift = cv2.xfeatures2d.SIFT_create(sigma=1.6, contrastThreshold=0.04,edgeThreshold = 15)

kp1, des1 = sift.detectAndCompute(rgb, None)
kp2, des2 = sift.detectAndCompute(thermal, None)

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)
img3 = cv2.drawMatches(rgb, kp1, thermal, kp2, good, None, flags=2)

这给出了以下
SIFT features matches with brute force matcher
然后我用 RANSAC 对找到的匹配项进行单应性处理
    if len(good) > MIN_MATCH_COUNT:
    src_pts = np.float32([kp1[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
    dst_pts = np.float32([kp2[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)

    M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0, maxIters=1000)
    matchesMask = mask.ravel().tolist()

    h, w, c = rgb.shape
    pts = np.float32([[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0]]).reshape(-1, 1, 2)
    dst = cv2.perspectiveTransform(pts, M)

    thermal = cv2.polylines(thermal, [np.int32(dst)], True, 255, 3, cv2.LINE_AA) # draw lines around as a box
    draw_params = dict(matchColor=(0, 255, 0),  # draw matches in green color
                   singlePointColor=None,
                   matchesMask=matchesMask,  # draw only inliers
                   flags=2)

    img3 = cv2.drawMatches(rgb, kp1, thermal, kp2, good, None, **draw_params)

导致这个
Post homography matching features
就像我说的,我认为这是失败的,因为 BFMatcher 没有找到正确的匹配,但我不知道为什么。再次非常感谢任何和所有帮助!我尝试使用球体检测器,将 rgb 图像转换为灰度图像,并将图像预先调整为相似大小,但仍然得到不好的结果。

这是一个工作 rgb-thermal 对的示例,用于演示我正在尝试做的事情。
Here is an example of a working rgb-thermal pair

最佳答案

您的图像的问题在于它与自然图像相比非常简单(没有颜色,纹理没有重大差异等),您无法可靠地使用 SIFT 和其他针对普通照片制作的技术。大多数错误匹配实际上都是很好的匹配,因为匹配在本地看起来彼此相似(在获得描述符之后)。

我的建议是查看使用结构信息匹配图像的替代方案,或向图像添加信息(例如,使用高度彩虹颜色图,因为您的图像可以被视为凹凸图;使用距离变换 + 颜色图也可能有效,或者使用提到的两者+ 边缘检测作为一个非常奇怪但异质的彩色图像的 3 个 channel )并查看 SIFT 的行为是否不同。

关于python - cv2 SIFT +蛮力匹配没有给出好的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50937304/

相关文章:

MATLAB:从二进制图像中分割单个字母

java - 如何将网络摄像头捕获的图像与 Java Swing 中的另一个图像进行匹配?

python - Azure表单识别器错误: "Failed to download image from input URL."

python - Flask-SQLAlchemy:在回滚无效事务之前无法重新连接

matlab - 如何在 Matlab 中编辑 "mexopt.bat"文件?

c - 球碰撞检测

algorithm - 应该对算法/代码进行哪些更改才能获得预期的车辆形状?

python - 尽管文件关联和路径正确,但 Windows 10 不会使用正确版本的 python 启动我的 python 脚本。

python - 在 Gif 中保存 matplotlib 动画时出错

python - 从 np.array 保存到 JPG 时,cv2.imwrite 改变颜色