# Breaking the MintEye image CAPTCHA in 34 lines of Python

Several people have suggested that importing OpenCV is cheating and as such the claim that MintEye was broken in 23 lines of Python is disingenuous. So, here’s a solution in 34 lines of Python:

```import sys
import os
import matplotlib.pyplot as plt
import math
from PIL import Image

for dir in range(1,14):
dir = str(dir)

total_images = len(os.listdir(dir))+1

points_sob = []
for i in xrange(1,total_images):
image = Image.open(dir+'/'+str(i)+'.jpg')

#convert to grayscale (ITU-R 601-2 luma transform)
grey = [[None for _ in range(image.size)] for _ in range(image.size)]
for x in xrange(image.size):
for y in xrange(image.size):
grey[x][y] = im[x,y]*299/1000 + im[x,y]*587/1000 + im[x,y]*114/1000

#sobel
sum_of_sob = 0
for x in xrange(1,image.size-1):
for y in xrange(1,image.size-1):
gx = -grey[x-1][y-1] + grey[x+1][y-1] - 2*grey[x-1][y] + 2*grey[x+1][y] - grey[x-1][y+1] + grey[x+1][y+1]
gy = -grey[x-1][y-1] - 2*grey[x][y-1] - grey[x+1][y-1] + grey[x-1][y+1] + 2*grey[x][y+1] + grey[x+1][y+1]
sum_of_sob = sum_of_sob + math.sqrt(gx*gx + gy*gy)

print sum_of_sob
points_sob.append(sum_of_sob)

res = points_sob.index(min(points_sob)) + 1
x = xrange(1,total_images)
plt.plot(res,points_sob[res-1], marker='o', color='r', ls='')
plt.plot(x, points_sob)

#plt.savefig(dir+'.png')
plt.show()
```

The point I’m trying to make is that Sobel is a very simple operator – that’s why it was created, as a crude approximation of the derivative of a 2D signal. In fact, the only non-trivial maths imported from OpenCV previously are the DCTs to decode the JPEGs.

## One thought on “Breaking the MintEye image CAPTCHA in 34 lines of Python”

1. RolexStrider on said:

Yes, Sobel is pretty simple – but IMHO in this case, Canny operator is more suitable.