python - 在图片上检测到超过 1 个对象

标签 python opencv computer-vision sift surf

我写了一个小脚本,可以通过 SIFT 描述符方法 在全局图片中找到一个对象。但是我有一个关于在同一张图片中进行多次检测的问题。

我有这张全局图片:

enter image description here

我有这个模板:

enter image description here

我的脚本如下:

import numpy as np
import cv2

#########################
# SIFT descriptors part #
#########################

img1 = cv2.imread('/Users/valentinjungbluth/Desktop/SIFT:SURF Algo/lampe.jpg',0)
img2 = cv2.imread('/Users/valentinjungbluth/Desktop/SIFT:SURF Algo/ville.jpg',0)

# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()

print (img1.dtype)
print (img2.dtype)


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

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

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

img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,None,flags=2)

cv2.imwrite('matches.jpg',img3)

结果是:

enter image description here

我的问题是:

我如何检测其他灯?因为所有的灯都非常相似,我想匹配图片中出现的所有灯。

非常感谢!

编辑 Micka 的回答:

enter image description here

在 0.2 比例距离处什么都没有出现,但如果我把 0.75 :

enter image description here

最佳答案

这是个好问题。我可以想到以下几种方法:

1.Sliding Windowing technique - 做一个窗口,模板的大小,在整个图像中滑动,就可以在全局图像中搜索"template"。您可以对金字塔执行此操作,以便处理比例和平移变化。 Sliding Window Technique

  1. SIFT - 尝试将全局图像与模板进行匹配并找到所有匹配项。然后你应该过滤具有相对姿势的匹配项。可能您需要另一个过滤,但我认为这种方法更通用,因为它比以前的限制更多。

希望对您有所帮助!

关于python - 在图片上检测到超过 1 个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41160721/

相关文章:

ios - iOS 上的 OpenCV : False matching with SurfFeatureDetector and FlannBasedMatcher

python - 用于分类的图像转换器

python - 将行写入 CSV 文件而不添加引号

python - 使用 dictwriter 覆盖同一 csv 文件中的行

python - 无法从任何类中的析构函数调用函数

opencv - 在尝试复制 Bit16 Mat 时,实际上只有一半被复制

python - 排列Leetcode

Android OpenCV FAST 角点检测过滤

C# - 多点触控帮助? USB网络摄像头输入?图像分析?

python - Pytorch的 "Fold"和 "Unfold"是如何工作的?