程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Use of pyteseract | Python identification verification code

編輯:Python

Catalog

    • 1. install tesseract
    • 2. install pytesseract
    • 3. Modify some code in the package
    • 4. Code site test

1. install tesseract

 See :
https://blog.csdn.net/lijiamingccc/article/details/119459775

2. install pytesseract

stay pycharm Under the terminal , install pytesseract, As shown in the figure

pip install pytesseract

3. Modify some code in the package


This path in the file , Change the location of your installation in the first step , It is recommended to copy directly after finding
Add a front r, To show that this path is a string , Prevent escape

4. Code site test

Code :

You can find any website by yourself

 res = requests.get(url="x'x'x'x'x")
with open('image.jpg', 'wb') as fw:
fw.write(res.content)
img = cv2.imread("image.jpg")
# White all around Image noise reduction
def around_white(img):
w, h, s = img.shape
for _w in range(w):
for _h in range(h):
if (_w <= 5) or (_h <= 5) or (_w >= w-5) or (_h >= h-5):
img.itemset((_w, _h, 0), 255)
img.itemset((_w, _h, 1), 255)
img.itemset((_w, _h, 2), 255)
return img
img2 = around_white(img)
ret, img2 = cv2.threshold(img2, 150, 255, cv2.THRESH_BINARY)
# You need to add some image noise reduction operations
code = pytesseract.image_to_string(img2,config="--psm 6 digits")
code = re.findall('\d+',code)[0]
print(" The identification verification code is :{}".format(code))

effect :

The recognition effect does not necessarily guarantee that it is correct every time , But basically 5 You can succeed within one time , You can write a loop here , Until we succeed .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved