opencv-js icon indicating copy to clipboard operation
opencv-js copied to clipboard

Add OpenCV contrib module support with ximgproc.thinning TypeScript definitions

Open Copilot opened this issue 5 months ago • 0 comments

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 ximgproc module including:
    • cv.ximgproc.thinning(src, dst, thinningType) function with proper parameter types
    • cv.ximgproc.THINNING_ZHANGSUEN and cv.ximgproc.THINNING_GUOHALL constants
    • Full JSDoc documentation with usage examples

Build Infrastructure

  • Updated GitHub Actions workflow to build OpenCV.js with opencv_contrib modules
  • Added scripts/build-contrib.sh for local contrib builds
  • Added npm run build:contrib command for easy building

Developer Tools

  • src/contrib-utils.ts with 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:

  1. Clones OpenCV and opencv_contrib repositories
  2. Sets up Emscripten
  3. Builds OpenCV.js with -DOPENCV_EXTRA_MODULES_PATH and -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:


💡 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.

Copilot avatar Sep 05 '25 03:09 Copilot