在 OpenCV 中计算特征匹配 (BFMatcher) 中的相似性度量

发布于 2025-01-14 01:53:46 字数 849 浏览 0 评论 0原文

我正在比较图像,并且使用 BFMatcher 来执行特征匹配

我的实际代码是:

def get_similarity_from_desc(approach, query_desc, corp_desc):
    if approach == 'sift':
        # BFMatcher with euclidean distance
        bf = cv.BFMatcher()
    else:
        # BFMatcher with hamming distance
        bf = cv.BFMatcher(cv.NORM_HAMMING)
    
    matches = bf.knnMatch(query_desc,corp_desc,k=2)
    # Apply ratio test
    good = []
    for m,n in matches:
        if m.distance < 0.75*n.distance:
            good.append([m])
    similarity = ??
    return similarity

我想知道是否可以在给定良好匹配列表的情况下计算相似性度量 good 以及两个图像的描述符 query_desccorp_desc

此时我想到:

similarity = len(good) / len(matches)

但是我认为这不是一个正确的判断方式两幅图像之间的相似度

你知道一个更好吗计算该度量的方法?

I am comparing images and I have used BFMatcher to perform feature matching

My actual code is:

def get_similarity_from_desc(approach, query_desc, corp_desc):
    if approach == 'sift':
        # BFMatcher with euclidean distance
        bf = cv.BFMatcher()
    else:
        # BFMatcher with hamming distance
        bf = cv.BFMatcher(cv.NORM_HAMMING)
    
    matches = bf.knnMatch(query_desc,corp_desc,k=2)
    # Apply ratio test
    good = []
    for m,n in matches:
        if m.distance < 0.75*n.distance:
            good.append([m])
    similarity = ??
    return similarity

I am wondering if it is possible to compute a similarity measure given the list of good matches good and the descriptors of the two images query_desc and corp_desc

At this moment I have thought:

similarity = len(good) / len(matches)

But I think this is not a correct way of determining similarity between two images

Do you know a better approach for computing this measure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝在阴天搁浅。 2025-01-21 01:53:46

我终于做到了这一点,似乎效果很好:

def get_similarity_from_desc(approach, search_desc, idx_desc):
    if approach == 'sift' or approach == 'orb_sift':
        # BFMatcher with euclidean distance
        bf = cv.BFMatcher()
    else:
        # BFMatcher with hamming distance
        bf = cv.BFMatcher(cv.NORM_HAMMING)
    matches = bf.match(search_desc, idx_desc)
    # Distances between search and index features that match
    distances = [m.distance for m in matches]
    # Distance between search and index images
    distance = sum(distances) / len(distances)
    # If distance == 0 -> similarity = 1
    similarity = 1 / (1 + distance)
    return similarity

来源:https://linuxtut.com/en/c9497ffb5240622ede01 /

I have finally done this, which seems to work well:

def get_similarity_from_desc(approach, search_desc, idx_desc):
    if approach == 'sift' or approach == 'orb_sift':
        # BFMatcher with euclidean distance
        bf = cv.BFMatcher()
    else:
        # BFMatcher with hamming distance
        bf = cv.BFMatcher(cv.NORM_HAMMING)
    matches = bf.match(search_desc, idx_desc)
    # Distances between search and index features that match
    distances = [m.distance for m in matches]
    # Distance between search and index images
    distance = sum(distances) / len(distances)
    # If distance == 0 -> similarity = 1
    similarity = 1 / (1 + distance)
    return similarity

Source: https://linuxtut.com/en/c9497ffb5240622ede01/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文