问题
I want to see if I can solve captchas with PHP for a bit of a personal challenge. Nothing too hard; words in the same line, words always in same colour, etc. Here's an example.
http://www.simplyshows.com/img.jpg
Just wanted to see how hard would it be. My question is, are there PHP based function which I can use to check pixel by pixel for colour etc? I want to divide the letters and then do a load of checks to determine if the letter is upper case, lower case, and what it can be (depending on coordinates on colours)
回答1:
If you're really interested in solving it from the ground up like this, start with libraries like GD and ImageMagick.
If you're interested in getting it done faster by leveraging the work of others, use Google or StackOverflow to see if there's a usable OCR library/project for PHP.
Lastly, I know you said you just want to do it for fun. Still, PHP has many strengths, but I don't think I would choose it for heavy-duty image processing and AI. You may wish to consider other languages with more robust and rich support for those sorts of things if you find yourself getting serious about this. But if it's just for fun, well, have fun!
回答2:
imagecolorat (http://php.net/manual/en/function.imagecolorat.php) is what you want.
回答3:
I have done something similar , although it seems pretty hard there is a solution: As you can see the letters in your image are written with a spefic color, that means that your php script will look for pixels with a specific hex color value. Now imagine that you have your captcha image zoomed x100 You will see the letters pixelated, imagine also a big 2 dimensional square array each block has an id ( i x j). In the image that I have attached that I have managed to create the letter "T" in a 10x10 array, using the id of each square i can make patterns for each letter and number. Using gd library you can achieve many things, don't bother to ask any other questions, I have just vage you the main frame GD Library manual

回答4:
Using PHP to do this kind of thing is a very good way to turn your server into a grill ;) Your best bet if you want something that is realistically usable then you probably want call a binary using exec() - write it in C or whatever and then call that from PHP. The only direct way using vanilla PHP I can think of is to read the hex from the image and use the resulting "text file" to do the analysis on, but it won't be pretty.
来源:https://stackoverflow.com/questions/8282919/solving-captcha-with-php-personal-challenge