Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

SWT (Stroke Width Transform) from OpenCV's text module is in opencv_contrib, not the main opencv repository. The default opencv.js build excludes contrib modules.

Changes

Build workflow (.github/workflows/build-opencv-js.yml)

  • Added enable_contrib boolean input to trigger opencv_contrib integration
  • Clones opencv_contrib repository matching OpenCV version
  • Passes --extra_modules path and text module config to build script
  • Uses bash arrays for argument construction (prevents shell injection)

Module configuration (opencv_js_text.config.py)

  • Whitelists text module functions for JavaScript export
  • Exports detectTextSWT and extensibility stubs for other text functions

Type definitions (src/types/opencv/text.ts)

  • TypeScript declarations for detectTextSWT function
  • Leverages existing RectVector type from _hacks.ts

Documentation

  • README: Build instructions and basic usage
  • doc/SWT_USAGE.md: Complete examples for Node.js, Browser, TypeScript
  • doc/SWT_IMPLEMENTATION.md: Technical implementation details

Usage

Build with contrib enabled via Actions workflow (set enable_contrib=true), then:

const cv = await cvModule;
const img = cv.imread('imageId');
const results = new cv.RectVector();
const draw = new cv.Mat();

// Detect dark text on light background
cv.detectTextSWT(img, results, true, draw);

console.log(`Found ${results.size()} text regions`);

results.delete();
draw.delete();
img.delete();

Default builds remain unchanged for backward compatibility.

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:

  • docs.opencv.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Can SWT work with it?</issue_title>
<issue_description>https://docs.opencv.org/4.7.0/d8/de7/namespacecv_1_1text.html#a9370f4e7849c94fb418eebd915a6839d</issue_description>

<agent_instructions>any chance to change the compiling option to make SWT work in the opencv.js library?</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 27, 2026 06:18
Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com>
…xt detection

Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com>
Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com>
Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com>
Copilot AI changed the title [WIP] Update compiling option for SWT compatibility in opencv.js Enable SWT text detection via opencv_contrib build option Jan 27, 2026
Copilot AI requested a review from ttt43ttt January 27, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can SWT work with it?

2 participants