Skip to content

About

Fast, lightweight PyTorch CNN that reads 5-digit dot-matrix captchas — ~5ms/image on CPU, ~100% accuracy, fully offline (no API).

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

🔢 Dot-Matrix Captcha Solver — CNN

A tiny, fast Convolutional Neural Network that reads 5-digit dot-matrix captchas — the noisy, dotted, line-obscured kind that defeats ordinary OCR and general vision models.

Trained from scratch on a custom-collected, self-labeled dataset. ~5 ms per image on CPU, ~100% accuracy, zero API cost.


🎯 Demo

The network reads the digits straight from the raw, distorted captcha image:

Input captcha CNN prediction
ex1 74372 ✅
ex2 53945 ✅
ex3 45747 ✅

Each image is 180×50 px, the digits drawn in a dot-matrix / LED style and buried under random colored lines and dots.


⚡ Why a custom CNN?

This dotted, line-obscured captcha breaks almost every general-purpose tool — they are either too slow, paid, rate-limited, or simply inaccurate on it. A small model trained only for this one captcha wins on every axis.

Solver Type Speed / image Accuracy Cost
⭐ This CNN Custom model ~5 ms ~100% Free, offline
Google Gemini 2.x Flash-Lite Cloud vision LLM ~2 s ~70–85% Free tier (rate-limited)
OpenAI GPT-4o / GPT-4o-mini Cloud vision LLM ~3–5 s ~60–80% Paid
Anthropic Claude (vision) Cloud vision LLM ~3–5 s ~60–80% Paid
Qwen3-VL 27B / 35B Cloud vision LLM ~40–90 s low (over-reasons) Free but unusable
Ollama qwen2.5-vl:3b (local) Local vision LLM ~20 s (CPU) ~17% Free but slow/weak
Ollama llava / moondream Local vision LLM ~10–30 s (CPU) low Free but slow
2Captcha Human/AI service ~12 s ~95% ~$1 / 1000
Anti-Captcha Human/AI service ~10 s ~95% Paid
CapMonster Cloud AI service ~5–10 s ~90% Paid
CapSolver AI service ~5 s ~90% Paid
Tesseract Classic OCR ~50 ms ~0% (dies on noise) Free
EasyOCR / PaddleOCR Classic OCR ~200 ms low on noisy captcha Free

Takeaway: a specialized ~1M-parameter CNN beats billion-parameter general models and paid services on this task — ~400× faster than vision LLMs, more accurate than human-solver services, no API keys, no rate limits, runs offline on a plain CPU.

🧠 How it works

  • Architecture: 4 conv blocks (Conv→BatchNorm→ReLU→MaxPool), 48×160 → 3×10 feature map, then a fully-connected head producing 5 positions × 10 classes (one softmax per digit).
  • Preprocessing: grayscale → resize 48×160 → normalize. That's it — the CNN learns the dot patterns directly.
  • Training: ~600 self-labeled images + data augmentation (small shifts, scale, translation) → 100% validation accuracy by epoch 30.
  • Size: 8.6 MB, ~1M params. No GPU needed.

🔧 Install

git clone https://github.com/LazizbekDeveloper/dotmatrix-captcha-cnn.git
cd dotmatrix-captcha-cnn

python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
# CPU-only PyTorch (lighter):
# pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu

🚀 Usage

Test on the bundled examples (accuracy + speed):

python test.py
# -> Accuracy: 3/3 (100%)   avg: 5ms/image

Read one image:

python model.py my_captcha.jpg      # -> 74372

In your code:

import model

code = model.read_code("captcha.jpg")     # path or raw bytes
print(code)                                # "74372"

Retrain (on your own labeled data):

# put images named  {5digits}_{anything}.jpg  into  dataset/
python train.py            # -> captcha_cnn.pt

📂 Files

dotmatrix-captcha-cnn/
├── model.py          # CNN architecture + inference (read_code)
├── captcha_cnn.pt    # trained weights (8.6 MB)
├── train.py          # training script
├── test.py           # accuracy + speed benchmark
├── examples/         # sample captchas
└── requirements.txt

👤 Author

Built by LazizbekDev — ML / automation engineer.

📩 Telegram: t.me/LazizbekDev

If this helped you, a ⭐ on the repo is appreciated!

About

Fast, lightweight PyTorch CNN that reads 5-digit dot-matrix captchas — ~5ms/image on CPU, ~100% accuracy, fully offline (no API).

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages