A Convolutional Neural Network solving Captcha
To do this, this code first generates its own dataset. Using claptcha and a variety of fonts.
You can see that claptcha inputs a arbitrary font, and the base font plays an important role. On left, there's the base font, and on the right, the corresponding distorted image created by claptcha:
Using Convolutional Neural Network, it learns each digit. (Only one digit)
After a Captcha is given to the program, first it converts to to Black and White, then it reduces the noise of the Captcha by replacing the dim and pale pixels with complete white, and then, replacing the remaining dark pixels with complete black. Let's assume the left below is the Original Captcha; The program converts it to Black and white (The right below):
In the stage of reducing the noise, the factor that matters the most, is the definition of the “Pale Pixel” that is mentioned above. If we scale the brightness of a B/W pixel from 0 to 255, 0 being completely black and 255 being completely white, from what point to 255, a pixel is considered a pale pixel? After that, we’ll edit the picture in such a way that there are only back and white pixels (No gray pixels,) so each pixel is either completely back or completely white.
Below are few more examples of this process being done on some other Captchas:
After reducing the noise of the picture, the program will chop the image in a few slices(!) so that in each slice, there’s only one digit. How does the program do that? The program has 3 functions that calculate the density of black pixels in an area. function does this differently; For instance one function just counts the number of black pixels in the given area and returns it, while the other function will find the largest sub-rectangle that all of its pixels are black, and returns the area of that rectanglesquared; The other function does something similar to this function. Combining these three functions, we can find the areas that the digits are placed; Then we can easily crop them. Consider the first example, we’ll graph the combination of these density function:
So the program can easily find the positions of the digits, and crops each digit individually:
Now the program will resize each digit to the standard input size of its Neural Network (which is 40×20) and give it to its CNN:
Some other examples:














