Discussion:
SURF to compare images
Leandro Vasco da Rocha
2012-11-14 12:43:06 UTC
Permalink
Hello,

I was studying opencv for python and I found Mahotas.

I have to solve the following problem: I will send a picture and the system will
search a database of images with different images which are similar to the
one that was sent (like google search images). My desire is to bring the
images that have over 70% similarity.

What is the best way to do this? Any suggestions?

I'm do one test using opencv and Py2.7, but now I need to compare the
images and obtain percent of common points.

*# Load the images**
img =cv2.imread(MEDIA_ROOT + "/uploads/imagerecognize/armchair.jpg")

# Convert them to grayscale
imgg =cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# SURF extraction
surf = cv2.FeatureDetector_create("SURF")
surfDescriptorExtractor = cv2.DescriptorExtractor_create("SURF")
kp = surf.detect(imgg)
kp, descritors = surfDescriptorExtractor.compute(imgg,kp)

# Setting up samples and responses for kNN
samples = np.array(descritors)
responses = np.arange(len(kp),dtype = np.float32)

# kNN training
knn = cv2.KNearest()
knn.train(samples,responses)

modelImages = [MEDIA_ROOT + "/uploads/imagerecognize/1.jpg", MEDIA_ROOT
+ "/uploads/imagerecognize/2.jpg", MEDIA_ROOT +
"/uploads/imagerecognize/3.jpg"]

for modelImage in modelImages:

# Now loading a template image and searching for similar keypoints
template = cv2.imread(modelImage)
templateg= cv2.cvtColor(template,cv2.COLOR_BGR2GRAY)
keys = surf.detect(templateg)

keys,desc = surfDescriptorExtractor.compute(templateg, keys)

for h,des in enumerate(desc):
des = np.array(des,np.float32).reshape((1,128))

retval, results, neigh_resp, dists = knn.find_nearest(des,1)
res,dist = int(results[0][0]),dists[0][0]


if dist<0.1: # draw matched keypoints in red color
color = (0,0,255)

else: # draw unmatched in blue color
#print dist
color = (255,0,0)

#Draw matched key points on original image
x,y = kp[res].pt
center = (int(x),int(y))
cv2.circle(img,center,2,color,-1)

#Draw matched key points on template image
x,y = keys[h].pt
center = (int(x),int(y))
cv2.circle(template,center,2,color,-1)



cv2.imshow('img',img)
cv2.imshow('tm',template)
cv2.waitKey(0)
cv2.destroyAllWindows()*

Thanks!

Best regards,
Leandro.

--
Andreas Mueller
2012-11-21 19:10:27 UTC
Permalink
Post by Leandro Vasco da Rocha
Hello,
I was studying opencv for python and I found Mahotas.
I have to solve the following problem: I will send a picture and the
system will search a database of images with different images which
are similar to the one that was sent (like google search images). My
desire is to bring the images that have over 70% similarity.
What is the best way to do this? Any suggestions?
Depending on how you measure similarity, "gist" or just a tiny image
might be a better descriptor than surf.

I would imagine that for such a retrieval task learning a ranking model
should be good.
No idea how to train it, though ;)

Andy

--
Luis Pedro Coelho
2012-11-22 00:33:06 UTC
Permalink
Received: by 10.50.154.132 with SMTP id vo4mr565974igb.7.1353544390305;
Wed, 21 Nov 2012 16:33:10 -0800 (PST)
X-BeenThere: pythonvision-/***@public.gmane.org
Received: by 10.50.202.97 with SMTP id kh1ls5138335igc.11.canary; Wed, 21 Nov
2012 16:33:09 -0800 (PST)
Received: by 10.66.73.1 with SMTP id h1mr1479157pav.0.1353544389824;
Wed, 21 Nov 2012 16:33:09 -0800 (PST)
Received: by 10.66.73.1 with SMTP id h1mr1479156pav.0.1353544389812;
Wed, 21 Nov 2012 16:33:09 -0800 (PST)
Received: from homiemail-a91.g.dreamhost.com (caibbdcaaaaf.dreamhost.com. [208.113.200.5])
by gmr-mx.google.com with ESMTP id js4si399733pbb.2.2012.11.21.16.33.09;
Wed, 21 Nov 2012 16:33:09 -0800 (PST)
Received-SPF: neutral (google.com: 208.113.200.5 is neither permitted nor denied by best guess record for domain of luis-lDyIkTiGk8zrZ44/***@public.gmane.org) client-ip=208.113.200.5;
Received: from homiemail-a91.g.dreamhost.com (localhost [127.0.0.1])
by homiemail-a91.g.dreamhost.com (Postfix) with ESMTP id 64C47AE05B
for <pythonvision-/***@public.gmane.org>; Wed, 21 Nov 2012 16:33:05 -0800 (PST)
Received: from [192.168.1.66] (bl7-129-135.dsl.telepac.pt [85.240.129.135])
(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
(No client certificate requested)
(Authenticated sender: luis-lDyIkTiGk8zrZ44/***@public.gmane.org)
by homiemail-a91.g.dreamhost.com (Postfix) with ESMTPSA id F1E0FAE059
for <pythonvision-/***@public.gmane.org>; Wed, 21 Nov 2012 16:33:04 -0800 (PST)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
In-Reply-To: <50AD2723.1020903-T6EGJOV9q4e6hr9I/***@public.gmane.org>
X-Original-Sender: luis-lDyIkTiGk8zrZ44/***@public.gmane.org
X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com:
208.113.200.5 is neither permitted nor denied by best guess record for domain
of luis-lDyIkTiGk8zrZ44/***@public.gmane.org) smtp.mail=luis-lDyIkTiGk8zrZ44/***@public.gmane.org; dkim=pass (test mode) header.i=@luispedro.org
Precedence: list
Mailing-list: list pythonvision-/***@public.gmane.org; contact pythonvision+owners-/***@public.gmane.org
List-ID: <pythonvision.googlegroups.com>
X-Google-Group-Id: 1008694279917
List-Post: <http://groups.google.com/group/pythonvision/post?hl=en-US>, <mailto:pythonvision-/***@public.gmane.org>
List-Help: <http://groups.google.com/support/?hl=en-US>, <mailto:pythonvision+help-/***@public.gmane.org>
List-Archive: <http://groups.google.com/group/pythonvision?hl=en-US>
Sender: pythonvision-/***@public.gmane.org
List-Subscribe: <http://groups.google.com/group/pythonvision/subscribe?hl=en-US>,
<mailto:pythonvision+subscribe-/***@public.gmane.org>
List-Unsubscribe: <http://groups.google.com/group/pythonvision/subscribe?hl=en-US>,
<mailto:googlegroups-manage+1008694279917+unsubscribe-/***@public.gmane.org>
Archived-At: <http://permalink.gmane.org/gmane.comp.python.pythonvision/115>
Post by Andreas Mueller
Depending on how you measure similarity,
I think this is the clincher.

The problem is really undefined if you just say similarity. Do you want
similar colours, similar objects, everything similar?

HTH.
Luis

--
Leandro Vasco da Rocha
2012-11-22 00:47:49 UTC
Permalink
I think similar objects. An example: I take a picture of a shoe and search
in my database what model of this shoe.

I hope I have explained properly what I need.

Thanks!
Post by Luis Pedro Coelho
Post by Andreas Mueller
Depending on how you measure similarity,
I think this is the clincher.
The problem is really undefined if you just say similarity. Do you want
similar colours, similar objects, everything similar?
HTH.
Luis
--
--
Andreas Mueller
2012-11-22 08:21:16 UTC
Permalink
Post by Leandro Vasco da Rocha
I think similar objects. An example: I take a picture of a shoe and
search in my database what model of this shoe.
If that is possible will depend a lot on how normalized the images are.
If these are product pictures,
you might have a chance.
Google goggles is trying to do recognize products in image for a couple
of years now, with a
dedicated research team. It's not really working yet.

--

Loading...