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.1.0.tar.gz (14.8 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.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shape_matcher-3.1.0.tar.gz
  • Upload date:
  • Size: 14.8 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.1.0.tar.gz
Algorithm Hash digest
SHA256 7f8ab8211b6a09a44735115dc7bc0a22081819c80eafde83798529f57397df3c
MD5 454c85a00b751c5819662db1413b6384
BLAKE2b-256 e3f87b73c77f6c0d47855c4df130af037f762505d52778ba2ba46392899a4288

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shape_matcher-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91a421a551633c316430fd45b8d700a4ba8029494c9c8d6a2a8b2390a96ff488
MD5 ab6fc11b0c226c74c6dde5abb5e81112
BLAKE2b-256 8031dc9c0df36319c87b3a652e46ab4f6238c944656275107e89495fa3f1b3d9

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