Ask Your Question
0

Comparing image to a database of images using SURF - python

asked 2013-12-28 05:15:06 -0600

janeq1992 gravatar image

Hey there I hope you guys can help me out. My goal is to write a program which will compare a photo of a car with a database of images (with a cars ofc) and tell me "That car is most likely a BMW" - I want only information about mark of a car.

I decided to use SURF. I'm getting keypoints and descriptors from database images and "my BMW". But how shall I match them ? Which matcher would be the best (BFMatcher, FlannMatcher, KNearest) and how shall I use them ?

For example that's what I got already.

import numpy as np
import cv2

# Load database
bmw1 = cv2.imread('database/bmw1.jpg')
audi1 = cv2.imread('database/audi1.jpg')
hundai1 = cv2.imread('database/hundai1.jpg')

# grayscale
gbmw1 = cv2.cvtColor(bmw1,cv2.COLOR_BGR2GRAY)
gaudi1 = cv2.cvtColor(audi1,cv2.COLOR_BGR2GRAY)
ghundai1 = cv2.cvtColor(hundai1,cv2.COLOR_BGR2GRAY)

#  SURF
minHessian = 1000
surf = cv2.SURF(minHessian)

# kp and desc of database
kp_bmw1, des_bmw1 = surf.detectAndCompute(gbmw1,None)
kp_audi1, des_audi1 = surf.detectAndCompute(gaudi1,None)
kp_hundai1, des_hundai1 = surf.detectAndCompute(ghundai1,None)

#Load my test photo
test = cv2.imread('photo.jpg')
gtest = cv2.cvtColor(gtest,cv2.COLOR_BGR2GRAY)
kp_test, des_test = surf.detectAndCompute(gtest,None)
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-12-29 10:17:57 -0600

Guanta gravatar image

Classifying single surf descriptors is not the way to go, the easiest way is to create global descriptors. Either you form a bag-of-words descriptor from local descriptors, see e.g. http://answers.opencv.org/question/8677/image-comparison-with-a-database/#8686, or you use global descriptors like GIST (google for it). For these global descriptors you can then train a classifier (e.g. SVM). You can also use the cascade-classifier of OpenCV, see http://docs.opencv.org/doc/user_guide/ug_traincascade.html. Here also a global descriptor (HOG/LBP/HAAR) is formed and then classified using a cascade of simple classifiers.

Please also note that this question has been asked and answered a lot, so please use the search function!

edit flag offensive delete link more
0

answered 2013-12-28 06:10:58 -0600

FLY gravatar image

Well i have little knowledge about it , i hope you can get the well explained answer soon , but for a little knowledge , I think FlannMatcher is best suitable technique with Surf and you need to use SVM , and you also need to compute discriptors and keypoints of all the images in your database and need to save them in the xml file and than the image which you want to test , computer thats image descriptor and keypoints and match them through FlannMatcher , hope its helpfull

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-12-28 05:15:06 -0600

Seen: 5,893 times

Last updated: Dec 29 '13