Skip to main content

Fastest checkbox/box detector — NumPy + Numba, 3-4x faster than boxdetect

Project description

checkboxer / npboxdetect

Fastest checkbox detector. NumPy + Numba. No deep learning.

Benchmark

Approach p50 (ms) boxes vs npboxdetect
npboxdetect 34ms 69 baseline
boxdetect 60ms 67 1.8x slower
opencv_contours 33ms 179 ~same (but noisy)
morphology 34ms 25 ~same (misses many)

50-run p50, full pipeline including imread, on 2200×1700 document images.

Pure processing (imread excluded):

Image npboxdetect boxdetect Speedup
lc_application1.png 6.5ms 25.5ms 3.9x
lc_application2.png 7.1ms 18.6ms 2.6x

Usage

from npboxdetect.detector import get_boxes

boxes = get_boxes("form.png")
# [(x, y, w, h), ...]

How it works

Five steps, all near-hardware-limit:

downsample 2x        ~0ms   stride view, zero copy
otsu + threshold      1.4ms  fused numba: histogram → binarize in one shot
morph open            1.3ms  numba parallel run-length scan (rows+cols)
connected components  1.3ms  cv2.connectedComponentsWithStats
NMS                   0.2ms  vectorized pairwise IoU matrix
─────────────────────────────
processing total      ~6ms

Key ideas:

  • 2x downsample before processing — free stride view, halves pixel count
  • Fused numba otsu+threshold — one serial histogram pass + one parallel binarize pass, no cv2 call
  • Run-length morph open — each row/column independent → prange parallelism, no cumsum overhead
  • Filter before NMS — size/ratio filter drops 1000+ blobs to ~70 before NMS

Install

git clone https://github.com/santhoshkammari/checkboxer
cd checkboxer
pip install numba opencv-python numpy

Journey

See JOURNEY.md (v0→v6, 4248ms→37ms) and JOURNEY2.md (v7→v10, 37ms→6ms).

Author

santhoshkammari

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

npboxdetect-0.1.2.tar.gz (17.3 MB view details)

Uploaded Source

Built Distribution

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

npboxdetect-0.1.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file npboxdetect-0.1.2.tar.gz.

File metadata

  • Download URL: npboxdetect-0.1.2.tar.gz
  • Upload date:
  • Size: 17.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for npboxdetect-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d72a50c6db53b6670e1e89e157c932dfb54b814d06f2a60f9f6fe4ea4a840689
MD5 48367863337d7b6a640a0b03ab913510
BLAKE2b-256 03268f4c6c07914e46e5effaa5410b91983f5466a59b8b92a95ef56f5349d3a5

See more details on using hashes here.

File details

Details for the file npboxdetect-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: npboxdetect-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for npboxdetect-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 15c7dcd07ebdc9e15ffc1c2c7d2ef69505cdc659134e2cf95ae941466d0a5545
MD5 2a774ee2ce372870969d51063295e8a9
BLAKE2b-256 472fb40d82c7ae31c271569448cfa229def726ef95acdada709df4769d8c265f

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