v3.1.1
What's new in v3.1.1
findRegions() — thresh option for resized binary images
The default thresh: 127 caused accuracy loss when running findRegions on a resized binary image. Resizing introduces anti-aliased border pixels (values 1–127) that the old threshold ignored, while OpenCV's findContours treats any non-zero pixel as foreground.
Use thresh: 0 to match OpenCV behaviour:
const regions = new CanvasProcessor(resizedBinaryCanvas).findRegions({
foreground: "light",
thresh: 0, // any non-zero pixel = foreground (matches OpenCV)
minArea: 20,
padding: { vertical: 0.4, horizontal: 0.6 },
scale: 1 / resizeRatio,
});With thresh: 0 + padding + scale, full-pipeline IoU vs OpenCV is 98.4% (all 21/21 boxes matched).
New findRegions() options
| Option | Default | Description |
|---|---|---|
thresh |
127 |
Foreground threshold. Use 0 to treat any non-zero pixel as foreground (matches OpenCV on resized binary images). |
padding |
— | { vertical?, horizontal? } — expand each bbox by a fraction of its height, mirroring applyPaddingToRect. |
scale |
1 |
Multiply all coordinates by this factor (use 1 / resizeRatio to map from processed→original image space). |
New example
examples/find-region-vs-get-contours.ts — side-by-side visual comparison of CanvasProcessor.findRegions vs OpenCV contours on a real receipt image, producing annotated PNG output files.
Type safety
All comparison.test.ts type errors resolved without as any. Canvas-to-canvas copies now route through CanvasProcessor.resize to avoid @napi-rs/canvas drawImage typing constraints.