preface
Environment module
Code display
Complete code
prefaceWhen we collect data , Too fast or frequently visited , Or you can pop up the verification code as soon as you visit , And then the clam bead ~
Today, I will give you a simple method to deal with the verification code
Environment moduleThere needs to be a ddddocr modular , This is something that someone else has written open source , Simple and easy to use , But the accuracy is a little poor , But it is still very easy to use .
If you want precision , You can call some written by others API .
Let's just win+r Enter... After the search box pops up cmd , Click OK to pop up the command prompt window , Input pip install ddddocr You can install .
If not, please refer to my top article for detailed explanation .
Code displayNot much code , It's simple .
After the module is installed, let's import it :
import ddddocr
Then instantiate , Use one cor Receive this data .
ocr = ddddocr.DdddOcr()
I have prepared four verification codes here :
First of all, we use with open To read this file , The read mode uses rb , If it is a picture, read its binary data
with open('img_3.png', 'rb') as f:
Use f.read() Read the data out , Then customize a variable to receive .
img_bytes = f.read()
And then we passed classification Pass it in , Just print out the results .
result = ocr.classification(img_bytes)print(result)
Realization effect :
Pure digital
Letter + Digital
You can see that they are completely identified , Even if there are some fancy horizontal lines on it .
Complete codeimport ddddocrocr = ddddocr.DdddOcr()with open('img_3.png', 'rb') as f: img_bytes = f.read()result = ocr.classification(img_bytes)print(result)
You can try it yourself , It can also be directly applied to the practice of data collection ~
This is about using Python This is the end of the article on simple verification code processing , More about Python For the content of verification code processing, please search the previous articles of software development network or continue to browse the relevant articles below. I hope you can support software development network more in the future !