Detect more than one object in the picture

I wrote a little script that allows you to find an object in a global image SIFT descriptors method. But I have a question about multiple detections in one picture.

I have this global picture:

enter image description here

I have this template:

enter image description here

My script looks like this:

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)

And the result:

enter image description here

My question is:

How can I detect these other lamps? Since all the lamps are very similar, and I want to match all the lamps that are present in the image.

Thank you very much!

EDIT With Miki's answer:

enter image description here

Nothing is displayed at 0.2 scale distance, but if I set 0.75:

enter image description here

+4
source share
2 answers

. :

1. . "" , , . , . Sliding window method

  1. SIFT. . . , , , , , .

, !

+1

, .

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

, , , , . "" . , !

+1

Source: https://habr.com/ru/post/1663822/


All Articles