# Find an image in a huge list of other images (feature matching, ORB, BRISK, …)

Imagine I have 20k images of different Beer bottles in different situations, positions, orientations,... I would like to find the picture that contains that specific beer I'm looking for, say a Corona. How could I achieve this ?

From what I read in the literature, I would choose a Feature Matching approach. SIFT and SURF being patented, I chose to go for either ORB or BRISK. Now I tried to code this approach in Python and my observations are : it's really slow to loop through 20k images. The slowest part being the computation of the matcher : bf.knnMatch(des1,des2, k=2).

My questions are : Is Feature Matching the most appropriate approach here ? Are there ways to improve and fasten a lot the use of ORB or BRISK algorithms ? Should I be smarter in my approach ? I have been thinking of a way not to loop through all my images but do some kind of pre-selection : for instance I could look at the most prominent color in my image, and only try to match on images that have similar prominent colors (supposing they are on the same table and same environment then, so that only the beer color would impact my pre-computations...)

import numpy as np
import cv2 as cv

lowe_ratio = 0.8

finder = cv.ORB_create()
# find the keypoints and descriptors with ORB
kp1, des1 = finder.detectAndCompute(img1,None)
kp2, des2 = finder.detectAndCompute(img2,None)

# BFMatcher with default params
bf = cv.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)

# Apply ratio test
good = []

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

# Here some code to keep the best match.