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.1.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.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: npboxdetect-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 62f7bb6f32f5cbad467030dada818ad4b7bd05af058ebf0291ba934970198f58
MD5 e8139fb2cb1fdb6b5c039a5bd2a1ee30
BLAKE2b-256 df80798cf6805b54e5787dfe8b80c0761d74267e6b0248c0d07381f07e3d008e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: npboxdetect-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 155d9ec0d144b625f203e161143d4fc0f605d09cb56e7cf11d9046d7aab472c5
MD5 87a77ab387449311d519daa2027351bd
BLAKE2b-256 a09e22a03fac2b936578d2d55f69869284f95f89354f12fe0cfb8f688b95ac00

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