SoFunction
Updated on 2024-11-13

Very simple Python to recognize the image verification code implementation process

Once a long time ago, a Python code implementation of CAPTCHA recognition was shared.

At that time the use of pillow + pytesseract, the advantage is free, easier to use. But its recognition accuracy is general, if you want to higher requirements for CAPTCHA recognition, beginners will have to choose to use the Baidu API interface.

But in fact, Baidu API interface and pytesseract actually require pre-configuration, which is not so friendly for beginners.

And Baidu API must be connected to the Internet, for some machines can not be connected to the friends, you have to pass!

Recently a group of friends in the group shared a new library, try it out and find it very useful, specially today to share it with you.

Github address:/sml2h3/ddddocr

The name of the library is also very interesting -- ddddocr (harmonized with band with brother OCR)

Environmental requirements:

python >= 3.8Windows/Linux/Macox..

It can be installed with the following command

pip install ddddocr

Parameter Description:

5行Python实现验证码识别,太稳了

Randomly looking for a CAPTCHA image on the Internet, use this library to practice a little. So want to learn students, it is necessary to listen to the teacher's class, receive python welfare O, want to learn students can go to Meng Ya teacher's Wei Xin (homophonic): the front row is: 762, the middle row is: 459, the back row of a group is: 510 , the above three groups of letters in order to combine can, she will arrange to learn.

5行Python实现验证码识别,太稳了

Source: Baidu Search

import ddddocr
ocr = ()
with open(‘', ‘rb') as f:
img_bytes = ()
res = (img_bytes)
print(res)

5行Python实现验证码识别,太稳了

The captcha text was successfully recognized!

And the advantages are also very obvious: first of all, the code is very streamlined, compared to the two methods mentioned earlier, do not need to set additional environment variables and so on, 5 lines of code can easily recognize the CAPTCHA picture. On the other hand, we use the magic command %%time also tested out ?this code recognition speed is very fast.

Continue testing with more captcha images below:

5行Python实现验证码识别,太稳了

I found 6 more CAPTCHA images to test, and observed the results, and found that this type of simple CAPTCHA can basically perform quick recognition. However, some of the results are problematic - the letters are not case sensitive (e.g. the 6th image).

All in all, if you need to do CAPTCHA recognition and the accuracy requirement is not too high.

Well, the library with the brother OCR (ddddocr) is a good choice~

Above is a very simple Python CAPTCHA recognition implementation process in detail, more information about Python CAPTCHA recognition please pay attention to my other related articles!