preface

Originally, the plan is to talk about how to obtain the source code generated verification code to reverse obtain verification code, after all, tesserocr recognition rate is a bit touching, but also need to adjust two values, once the website has done the test, such as the same verification code retry several times not successful is blocked or replace the new verification code, then GG; But still can’t put the image recognition, these things, is obviously a way to make money, and there must be a solution, otherwise how can there be a code platform? The top2 advertising Spaces are baidu and Tencent. Scroll down that day, and there are other unknown ones. For the sake of safety, I will introduce BAT’s.

1. Baidu Cloud OCR

Official access documentation: Text recognition -Python SDK access documentation

Key points: free universal identification service (including ID card, bank card) 500 times/day, high precision 50 times/day, driving license, driving license, ticket, business license, general bills are all 200 times/day

For scripts used for debugging, 500 times is sufficient ~

By the way, 2.7.+ and 3.+ are supported.

1.2 Configuration Process:

1) Open a Baidu account first; On the opening of character recognition service 2), click on the immediate use: https://cloud.baidu.com/product/ocr.html click on the step 2, 3) should have a confirmation, after confirmation, will enter to the users’ personal home page, downward slide, just click text recognition;

API Key
Secret Key

pip

pip install baidu-aip
Copy the code

See success, good~

1.3 Experience:

From aip import AipOcr """ your APPID AK SK "" APP_ID = 'your APPID' API_KEY = 'your API KEY' SECRET_KEY =' your SECRET KEY' Def get_file_content(filePath): with open(filePath, 'rb') as fp: def get_file_content(filePath, 'rb') as fp: Return fp.read() image = get_file_content('juejin. JPG ') "" "" result = client.basicGeneral(image) if 'words_result' in result: print(result)Copy the code

The verified images are as follows:

Results go a wave:

Words_result_num = words_result_num words_result_num = words_result_num words_result_num = words_result_num words_result_num = words_result_num Words_result is an array of locating and identifying results; Words is the recognition result string

So if we want to extract, then the last print needs to process ~

# return format {'log_id': 8443096175124270990, 'words_result_num': 2, 'words_result': [{'words': 'nuggets '}, {'words': Join ([w['words'] for w in result['words_result']]) # Key = [] if 'words_result' in result: for w in result["words_result"]: Key. Append (w["words"]) # print("".join(key))Copy the code

Ok, to make it look nice, I’ll simply encapsulate it, but there’s a problem:

The APP_ID parameter is not available, which is incorrect because the name is an example of the official website. The official website is the way to pass the parameter, and we are encapsulated, the only possibility, the source code is really not called APP_ID;

Change the parameters to appId,apiKey and secretKey. The overall code is as follows:

From aip import AipOcr """ your APPID AK SK "" config = {" APPID ": "" def get_file_content(filePath): """ "def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() def get_image_str(image_path): Image = get_file_content(image_path) """ "" result = client.basicGeneral(image) # if 'words_result' in result: return ''.join([w['words'] for w in result['words_result']]) if __name__ == "__main__": print(get_image_str("juejin.jpg"))Copy the code

The source code is here, then we have a look, the last micro blog that verification code can be identified?

1.4 Verification code in one wave

Figure 1:

Sure enough, high precision is accurate, no wonder only 50 free times a day;

Figure 2:

Network picture interface:

Figure 3:

High precision interface:

Try other interfaces, display content is not edge; Hollow verification code, is to god ~

Finally, a skin:

High precision interface:

Content is not correct, already in the expected, but, it seems that the output result, no concept of layout??

With instinct, want to see how the source code is implemented, hanging fried days, a look at the results:

The image becomes a string processed by BASE64, the request is made, and then the response is returned:

1.5 Baidu Cloud OCR summary

It’s only free for a limited number of times a day, and it’s 500 times a day, which is attractive; Provide high precision interface, Chinese identification can also; However, graphic verification codes, especially hollow verification codes, are basically invalid.

About the principle, looked for a long time also did not find any information, after all, the family is to charge ~

2 Ali Cloud OCR

The official document access: https://help.aliyun.com/document_detail/50191.html?spm=a2c4g.11186623.6.618.UdvRRo

Ali also has free, every month 3K;

Python versions later than 2.7 are supported

2.2 Configuration Process

1) open ali cloud account 2) open content detection API: https://www.aliyun.com/product/cdi/ after 3) opened, the login web site: https://home.console.aliyun.com/new?spm=a2c4g.11186623.2.3.tZ4rrv#/, click on the upper right corner of the user center, click accesskeys, open can


PIP install aliyun-python-sdk-core-v PIP install aliyun-python-sdk-green==3.1.0Copy the code

Well, I will not introduce the following, the reason is that the official website information is confusing, and there is no good distinction between 2.X and 3.X, resulting in a lot of problems and a waste of hours.

3 Tencent Cloud OCR

Free 1K each month, regardless of type, only regular ID card, business card, driver’s license, etc.;

Website access documents: https://cloud.tencent.com/document/product/641/12440

3.2 Configuration Process

1) Apply for Tencent cloud account; 2) open the character recognition OCR permissions: https://cloud.tencent.com/product/ocr after 3) opened, log in the link below, click new key: https://console.cloud.tencent.com/cam/capi


pip3 install qcloud_image
Copy the code

At the beginning of 3.3 experience

from qcloud_image import Client from qcloud_image import CIUrl, CIFile, CIBuffer, CIUrls, CIFiles, CIBuffers appID = 'your appID' secret_id = 'your secret_id' secret_key =' your secret_id' bucket = 'your secret_id' client = Client(appid, secret_id, secret_key, bucket) client.use_http() client.set_timeout(30) print (client.namecard_detect(CIFiles(['ok.jpg'])))Copy the code

Well, it works, the background returns:

{'result_list': [{'code': -5201, 'message': 'OCR_NOT_ENOUGH_TEXTLINES', 'filename': 'ok.jpg', 'data': {}}], 'httpcode': 400}
Copy the code

But did not find a more detailed API document, can not analyze, look at the official website information, it seems to write their own request?? Also toss a lot of time, do not want to toss down, time is precious;

summary

This paper ended the CHARGING OCR of BAT3 platforms, of which only Baidu successfully accessed and used; Tencent can access and run successfully because the API information is not very good, but they don’t know how to deal with it. Ali can’t run smoothly because the documentation still uses 2.x and doesn’t explain how to use 3.x, etc

From the free point of view, or Baidu atmosphere, 300 free every day, Tencent and Ali relative, less very right; But I have to say, Baidu’s handling of Chinese is too good, basic can recognize;

The problem

Since it is Baidu, for hollow verification code, still helpless; And this is a fee-based platform, can’t it be fixed?

Thank you.