How do I find Wally with Python? How do I find Wally with Python? python python

How do I find Wally with Python?


Here's an implementation with mahotas

from pylab import imshowimport numpy as npimport mahotaswally = mahotas.imread('DepartmentStore.jpg')wfloat = wally.astype(float)r,g,b = wfloat.transpose((2,0,1))

Split into red, green, and blue channels. It's better to use floating point arithmetic below, so we convert at the top.

w = wfloat.mean(2)

w is the white channel.

pattern = np.ones((24,16), float)for i in xrange(2):    pattern[i::4] = -1

Build up a pattern of +1,+1,-1,-1 on the vertical axis. This is wally's shirt.

v = mahotas.convolve(r-w, pattern)

Convolve with red minus white. This will give a strong response where the shirt is.

mask = (v == v.max())mask = mahotas.dilate(mask, np.ones((48,24)))

Look for the maximum value and dilate it to make it visible. Now, we tone down the whole image, except the region or interest:

wally -= .8*wally * ~mask[:,:,None]imshow(wally)

And we get waldo!


You could try template matching, and then taking down which produced the highest resemblance, and then using machine learning to narrow it more. That is also very difficult, and with the accuracy of template matching, it may just return every face or face-like image. I am thinking you will need more than just machine learning if you hope to do this consistently.


maybe you should start with breaking the problem into two smaller ones:

  1. create an algorithm that separates people from the background.
  2. train a neural network classifier with as many positive and negative examples as possible.

those are still two very big problems to tackle...

BTW, I would choose c++ and open CV, it seems much more suited for this.