preamble
There are many types of CAPTCHA, which is commonly used as a means of anti-climbing, including: image CAPTCHA, slider CAPTCHA, and some other common CAPTCHA scenarios.
Recognize the CAPTCHA python library has a lot to use and is not simple, here is a simple and practical to recognize the CAPTCHA library ddddocr (with a younger brother ocr) library.
environmental preparation
The python version required is less than or equal to python version 3.9.
pip install
pip install ddddocr
Download the installation package is relatively large, generally use the domestic download source can speed up the download speed
pip install ddddocr -i /simple
github address/sml2h3/ddddocr
Quick Start
First, find a random English captcha, keep it to
code example
import ddddocr # Import ddddocr ocr = () # Instantiation with open('', 'rb') as f: # Open the picture img_bytes = () # Read the picture res = (img_bytes) # Identify print(res)
running result
has been able to recognize xnen, but there will be "welcome to use ddddocr, this project focuses on driving the industry volume ..." prompt, can add a parametershow_ad=False
import ddddocr # Import ddddocr ocr = (show_ad=False) # Instantiation with open('', 'rb') as f: # Open the picture img_bytes = () # Read the picture res = (img_bytes) # Identify print(res)
CAPTCHA
Recognize the three types of CAPTCHA
code example
import ddddocr # Import ddddocr ocr = (show_ad=False) # Instantiation with open('', 'rb') as f: # Open the picture img_bytes = () # Read the picture res2 = (img_bytes) # Identify print(res2) with open('', 'rb') as f: # Open the picture img_bytes = () # Read the picture res3 = (img_bytes) # Identify print(res3) with open('', 'rb') as f: # Open the picture img_bytes = () # Read the picture res4 = (img_bytes) # Identify print(res4)
running result
giv6j
zppk
4Tskh
Slider CAPTCHA
The slider CAPTCHA scenario is the following scenario example
Start by keying out 2 images, namely and
Problem solving focuses on calculating the location of the gap
import ddddocr det = (det=False, ocr=False, show_ad=False) with open('', 'rb') as f: target_bytes = () with open('', 'rb') as f: background_bytes = () res = det.slide_match(target_bytes, background_bytes, simple_target=True) print(res)
running result
{'target_y': 0, 'target': [184, 58, 246, 120]}
The four values of target are the upper-left and lower-right corners of the notch position to the left.
Recognize Chinese
Recognize text on pictures
import ddddocr import cv2 det = (det=True) with open("", 'rb') as f: image = () poses = (image) im = ("") for box in poses: x1, y1, x2, y2 = box im = (im, (x1, y1), (x2, y2), color=(0, 0, 255), thickness=2) ("", im)
Saved images
To this point this article on Python to recognize the picture/slider CAPTCHA very high accuracy ddddocr library details of the article is introduced to this, more related Python ddddocr library content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future!