Skip to main content

Edge-based object matching using Chamfer distance for CAPTCHA solving

Project description

Shape Matcher

Edge-based object matching using Chamfer distance. Finds the most similar pair of objects in an image.

Algorithm

  1. LAB Chroma Mask - Separates colored objects from background (catches faint colors, ignores shadows)
  2. Binary Patch Normalization - Converts each object contour to a square binary patch
  3. Edge Extraction - Gets silhouette edge from binary patch (no fake edges from shading)
  4. Chamfer Distance - Compares edges with rotation sweep for rotation invariance

Installation

pip install -r requirements.txt

Usage

CLI

# Basic usage
python -m shape_matcher --image examples/image.png --out result.png

# With options
python -m shape_matcher -i examples/image.png -o result.png --chroma_thr 5.0 --angles_step 10 --debug

Python API

from shape_matcher import Config, MatcherFactory
import cv2

# Load image
img = cv2.imread("examples/image.png")

# Create matcher
config = Config.default()
matcher = MatcherFactory.create(config)

# Process
objects, best_match, result_img = matcher.process(img)

if best_match:
    print(f"Best match: Object {best_match.idx1} <-> Object {best_match.idx2}")
    print(f"Chamfer distance: {best_match.chamfer_distance:.4f}")

Options

Option Default Description
--chroma_thr 6.0 LAB chroma threshold (lower = catch fainter colors)
--min_area 300 Minimum contour area
--min_wh 20 Minimum bbox width/height
--min_hole_area_ratio 0.02 Minimum hole area ratio vs parent contour
--hole_mismatch_penalty 2.0 Penalty per hole-count mismatch
--hole_area_weight 1.0 Weight for hole area ratio difference
--hu_weight 0.6 Weight for Hu moment distance
--angles_step 15 Rotation step in degrees (smaller = more accurate)
--patch 96 Normalized patch size
--debug False Enable debug logging

Project Structure

TikTok-Captcha-Solver/
├── shape_matcher/          # Main package
│   ├── __init__.py         # Package exports
│   ├── __main__.py         # CLI runner
│   ├── config.py           # Configuration classes
│   ├── models.py           # DetectedObject, MatchResult
│   ├── protocols.py        # Abstract interfaces
│   ├── mask.py             # LABChromaMaskGenerator
│   ├── patch.py            # PatchProcessor
│   ├── chamfer.py          # ChamferDistance
│   ├── extractor.py        # ContourObjectExtractor
│   ├── similarity.py       # EdgeChamferSimilarity
│   ├── renderer.py         # DefaultResultRenderer
│   ├── factory.py          # MatcherFactory
│   └── service.py          # MatcherService
├── examples/               # Test images
├── requirements.txt
└── README.md

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shape_matcher-3.0.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shape_matcher-3.0.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file shape_matcher-3.0.0.tar.gz.

File metadata

  • Download URL: shape_matcher-3.0.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for shape_matcher-3.0.0.tar.gz
Algorithm Hash digest
SHA256 e230f6dca7dd823d1aba80d4572342d3061bdf70bd305dd62e7348b0e9e11f2d
MD5 cde02fd1c5ff68047b4d6d8f3e112175
BLAKE2b-256 52f45c7d3389b0b6bf655af5a58fd0a54c99dc5f3d31d37756b59dec371d015a

See more details on using hashes here.

File details

Details for the file shape_matcher-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: shape_matcher-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for shape_matcher-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5b7280e2483ba3c5df6557cb4e13e01e378b12598bbdb5656ae745823d710ec
MD5 00b182ce02e934843fe0bc47e33d0b62
BLAKE2b-256 6b95ba237fcc72fd751d2739131a54db24a44c734d948e9e619573d7c722fc31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page