DDDDOCR

1.6.1 · active · verified Thu Apr 16

DdddOcr is a universal offline CAPTCHA recognition SDK that leverages deep learning models to identify various types of CAPTCHAs, including alphanumeric, Chinese characters, slider puzzles, and special character combinations. It is designed with minimal dependencies for ease of use and offers a simple API. The current version is 1.6.1 and is actively maintained with frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic text recognition using the DdddOcr class. It initializes the OCR engine once and then processes an image from bytes. Remember to initialize the `DdddOcr` object only once for performance.

import ddddocr
import os

# Create a dummy image file for demonstration
dummy_image_path = 'captcha_example.png'
from PIL import Image, ImageDraw, ImageFont

# Create a simple image with text
img = Image.new('RGB', (120, 40), color = (255, 255, 255))
d = ImageDraw.Draw(img)
try:
    # Try to use a common system font
    font = ImageFont.truetype('arial.ttf', 24)
except IOError:
    # Fallback if arial.ttf is not found
    font = ImageFont.load_default()
d.text((10,5), "test123", fill=(0,0,0), font=font)
img.save(dummy_image_path)

# Initialize DdddOcr for OCR recognition
# It's recommended to initialize the object once, not in a loop.
ocr = ddddocr.DdddOcr()

# Read the image bytes
with open(dummy_image_path, 'rb') as f:
    image_bytes = f.read()

# Perform OCR classification
result = ocr.classification(image_bytes)
print(f"OCR Result: {result}")

# Clean up the dummy image
os.remove(dummy_image_path)

view raw JSON →