See :
https://blog.csdn.net/lijiamingccc/article/details/119459775
stay pycharm Under the terminal , install pytesseract, As shown in the figure
pip install pytesseract
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
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 .