Ask Your Question
0

templateMatch example not working?

asked 2012-08-18 05:17:47 -0500

joek gravatar image
from SimpleCV import *
import sys, time, socket

source = Image("templatetest.png", sample=True) # the image to search
template = Image("template.png", sample=True) # the template to search the image for
t = 5

methods = ["SQR_DIFF","SQR_DIFF_NORM","CCOEFF","CCOEFF_NORM","CCORR","CCORR_NORM"] # the various types of template matching available
for m in methods:
    print "current method:", m # print the method being used
    result = Image("templatetest.png", sample=True)
    dl = DrawingLayer((source.width,source.height))
    fs = source.findTemplate(template,threshold=t,method=m)
    for match in fs:
        dl.rectangle((match.x,match.y),(match.width(),match.height()),color=Color.RED)
    result.addDrawingLayer(dl)
    result.applyLayers()
    result.show()
    result.save()
    time.sleep(3)

I can see the images showing but no red rectangle is displayed.

http://postimage.org/image/aws6r74ij/ <-- source image.
http://postimage.org/image/j59qmqw8j/ <-- image to search
edit retag flag offensive close merge delete

Comments

I'm getting rectangles for CCOEFF, CCOEFF_NORM methods only.

jayrambhia gravatar imagejayrambhia ( 2012-08-19 02:25:54 -0500 )edit

it doesn't seem to be saving the red rectangle to the image file.

joek gravatar imagejoek ( 2012-08-19 03:38:59 -0500 )edit

in result.save(), you have to give a filename.

jayrambhia gravatar imagejayrambhia ( 2012-08-19 05:06:10 -0500 )edit

@jayrambia: you should respond below so we can mark it as an answer.

xamox gravatar imagexamox ( 2012-08-19 07:00:10 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-08-20 11:07:51 -0500

kscottz gravatar image

Just a follow on. With the find template method you are not always guaranteed a match. Template matching just returns a value of match quality for every pixel in the image. If your thresholds are too high you will not get any results. You need to monkey with parameters to determine the sensitivity of your correlation method. I suggest you read up on the topic of template matching.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-08-18 05:17:47 -0500

Seen: 3,107 times

Last updated: Aug 20 '12