Lightweight CAPTCHA predictor for Vietcombank using ONNX
Project description
vietcombank-captcha
A lightweight Python library for solving Vietcombank CAPTCHA images using ONNX runtime. This project is purely educational. Using synthetic data from various sources.
Features
- 🚀 Fast inference using ONNX runtime
- 🎯 High accuracy (>95% on test set)
- 🔧 Simple API with minimal dependencies
- 📦 Lightweight package (~2.2MB model)
- 🖼️ Supports multiple input formats (file path, PIL Image, numpy array)
- 🔢 Batch prediction support
- 🍎 Optimized for Apple M Chip
Installation
Using pip
pip install vietcombank-captcha
Using UV (recommended)
uv pip install vietcombank-captcha
Quick Start
Basic Usage
from vietcombank_captcha import predict
# Predict from image file
captcha_code = predict("captcha.png")
print(f"Predicted code: {captcha_code}")
Advanced Usage
from vietcombank_captcha import VietcombankCaptcha
# Initialize predictor
predictor = VietcombankCaptcha()
# Predict single image with confidence scores
code, confidences = predictor.predict_with_confidence("captcha.png")
print(f"Code: {code}")
print(f"Confidence per digit: {confidences}")
# Batch prediction
images = ["captcha1.png", "captcha2.png", "captcha3.png"]
results = predictor.predict_batch(images)
print(f"Results: {results}")
# With confidence scores
results_with_conf = predictor.predict_batch(images, return_confidence=True)
for code, conf in results_with_conf:
print(f"Code: {code}, Avg confidence: {sum(conf)/len(conf):.2f}")
Using PIL Image
from PIL import Image
from vietcombank_captcha import predict
# Load image with PIL
img = Image.open("captcha.png")
code = predict(img)
print(f"Code: {code}")
Using numpy array
import numpy as np
from vietcombank_captcha import predict
# From numpy array (H, W, 3) RGB format
img_array = np.array(...) # Your image array
code = predict(img_array)
print(f"Code: {code}")
Command Line Interface
# Predict single image
vietcombank-captcha predict image.png
# Predict with confidence scores
vietcombank-captcha predict image.png --confidence
# Batch prediction
vietcombank-captcha predict-batch ./captcha_folder/
# Use custom model
vietcombank-captcha predict image.png --model custom_model.onnx
API Reference
VietcombankCaptcha
Main predictor class.
__init__(model_path: Optional[str] = None)
Initialize the predictor with an optional custom model path.
predict(image) -> str
Predict CAPTCHA code from an image.
predict_with_confidence(image) -> Tuple[str, List[float]]
Predict with confidence scores for each digit.
predict_batch(images, return_confidence=False)
Predict multiple images at once.
predict(image, model_path=None) -> str
Convenience function for single prediction.
Requirements
- Python >= 3.8
- numpy >= 1.20.0
- Pillow >= 9.0.0
- onnxruntime >= 1.16.0
Model Information
- Input: RGB image (155x50 pixels)
- Output: 5-digit code (0-9)
- Model size: ~2.2MB
- Architecture: Multi-output CNN optimized for CAPTCHA recognition
Performance
- Inference time: ~5-10ms per image (CPU)
- Accuracy: >95% on test dataset
- Memory usage: <100MB
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and questions, please use the GitHub issue tracker.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vietcombank_captcha-0.1.0.tar.gz.
File metadata
- Download URL: vietcombank_captcha-0.1.0.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a235aacedb663c29fb195f7c1844d5aaf5e366b8c6687dd781558c90e782e5d
|
|
| MD5 |
e2f59208152477128435e4f2d8f7b29e
|
|
| BLAKE2b-256 |
ad5263e6dcbb9fb533243991245135921cff947b83777a8b48c9e2bba9dd5254
|
File details
Details for the file vietcombank_captcha-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vietcombank_captcha-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fec03cb60e412a409b29bd0e517359cd94b4533a15225ada879eb79042c4397
|
|
| MD5 |
05b86f7f2b4756e7f1fe7a6ca1bc3068
|
|
| BLAKE2b-256 |
6d10233d133991566fcc36ba57d2c13d949cae30f99d13eca286eeee246cf734
|