Add OpenCV contrib module support with ximgproc.thinning TypeScript definitions
This PR adds comprehensive support for OpenCV contrib modules, specifically addressing the missing cv.ximgproc.thinning() function that users need for image skeletonization.
What's Added
TypeScript Definitions
- Complete TypeScript definitions for the
ximgprocmodule including:-
cv.ximgproc.thinning(src, dst, thinningType)function with proper parameter types -
cv.ximgproc.THINNING_ZHANGSUENandcv.ximgproc.THINNING_GUOHALLconstants - Full JSDoc documentation with usage examples
-
Build Infrastructure
- Updated GitHub Actions workflow to build OpenCV.js with opencv_contrib modules
- Added
scripts/build-contrib.shfor local contrib builds - Added
npm run build:contribcommand for easy building
Developer Tools
-
src/contrib-utils.tswith functions to detect contrib module availability - Comprehensive example in
examples/ximgproc-thinning.ts - Test suite that gracefully handles missing contrib modules
Usage Example
With this PR, developers now get full TypeScript support for contrib modules:
import cv from "@techstark/opencv-js";
cv.onRuntimeInitialized = () => {
const src = cv.imread('input');
const dst = new cv.Mat();
// Full TypeScript autocomplete and type checking
cv.ximgproc.thinning(src, dst, cv.ximgproc.THINNING_ZHANGSUEN);
dst.delete();
src.delete();
};
Building with Contrib Modules
To use the contrib functions, users need to build OpenCV.js with contrib modules:
# Using the provided script
npm run build:contrib
# Or manually
./scripts/build-contrib.sh
The build script automatically:
- Clones OpenCV and opencv_contrib repositories
- Sets up Emscripten
- Builds OpenCV.js with
-DOPENCV_EXTRA_MODULES_PATHand-DBUILD_opencv_ximgproc=ON
Documentation
Added comprehensive documentation in README.md explaining:
- How to build OpenCV.js with contrib modules
- Usage examples for
cv.ximgproc.thinning() - Clear instructions for replacing the default opencv.js build
The TypeScript definitions provide immediate developer value with autocomplete and type safety, while the build infrastructure ensures users can easily create contrib-enabled builds when needed.
Fixes #84.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
build.opencv.org
- Triggering command:
curl -s REDACTED(dns block)docs.opencv.org
- Triggering command:
curl -s REDACTED(dns block)- Triggering command:
curl -I REDACTED(dns block)https://api.github.com/search/code
- Triggering command:
curl -s REDACTED(http block)https://api.github.com/search/repositories
- Triggering command:
curl -s REDACTED(http block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.