r/Python • u/AutoModerator • Oct 04 '26
Showcase Showcase Thread
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
23
Upvotes
r/Python • u/AutoModerator • Oct 04 '26
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
1
u/runout77 Oct 09 '26
Contrek: A lightweight, multithreaded alternative to OpenCV's `findContours`
What my project does
I developed Contrek, an open-source C++ library with bindings for Python and Ruby, designed primarily to extract polygons from raster images.
Its features include:
Selectable 4-point or 8-point connectivity.
Polygon extraction including both outer and inner contours.
Multithreaded processing based on independent image tiles.
Topological polygon merging across tile boundaries.
Progressive raster decoding and streaming SVG output.
Merging of geometries produced by other extractors (like OpenCV).
The Python bindings release the GIL during the C++ polygon extraction phase, enabling simultaneous processing of multiple image tiles.
I recently added a benchmark for progressive streaming using an 81,920 × 81,920 pixel (6.71 billion pixels) PNG image.
On an AMD Ryzen 7 3700X system, using 4 workers and 4-point connectivity, the results were:
23,556,642 polygons
267.8 seconds (4 min 28 sec)
5.73 GiB peak RSS (resident memory)
10.89 GiB SVG output
There is never a need to keep the entire decoded raster and the complete polygon output in memory simultaneously.
Target audience
Python developers working on image processing, raster-to-vector conversion, geographic data, or large binary images.
Comparison
OpenCV's `findContours` function is a well-established solution for contour extraction.
Contrek takes a different approach, focusing specifically on:
Parallel extraction and merging of polygon topology.
Progressive processing of raster images that exceed available working memory. It is not intended to replace OpenCV entirely, but rather to offer an alternative for this specific task.
Source code: https://github.com/runout77/contrek
Python bindings: https://github.com/runout77/contrek-python
Examples and reproducible tests: https://github.com/runout77/test_contrek
In the latter repository, you can try out the progressive streaming Python program mentioned above.