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

Uploaded Python 3

File details

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

File metadata

  • Download URL: npboxdetect-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4b7f05242ffdd57a9f96fb9655695fccf71f5e418839324c9b7bbdf9c8c787b7
MD5 8d93a29b5ccdfb685b7f253f37cc6a0a
BLAKE2b-256 270c4c52a67e690d312a58a9f251d10d6d7f07dc19719a3c8c8badc704c450e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: npboxdetect-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a671be0a44489cda405c6fa02d9274835a215233f0f5976dc0e258c34984508
MD5 e13cdc5b2c8beb3affc2c2c79a2d2db9
BLAKE2b-256 af1ff76c67bfc54c59a0526195fa010f19081d8bf83e4de56ac2b7c196db770a

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