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

Remove unsupported scalar-by-array overload from cv.divide type definition

Open Copilot opened this issue 3 months ago • 0 comments

TypeScript types incorrectly advertised a divide(scale, src2, dst, dtype?) overload that doesn't exist in the OpenCV.js WASM binary, causing runtime failures:

// TypeScript accepted this, but failed at runtime with "Cannot pass number as a Mat"
cv.divide(1 / srcStd, sourceNormalized, sourceNormalized);

Changes

  • Removed non-existent divide(scale: double, src2: InputArray, dst: OutputArray, dtype?: int) overload from core_array.ts
  • Added documentation note explaining C++ OpenCV vs OpenCV.js differences and workaround pattern
  • Added test suite validating correct usage and TypeScript type checking

Workaround

// Use Mat.ones with scale parameter for scalar division
const ones = cv.Mat.ones(3, 3, cv.CV_32F);
cv.divide(ones, sourceNormalized, dst, 1 / srcStd);

TypeScript now correctly rejects scalar-first parameter at compile time: Argument of type 'number' is not assignable to parameter of type 'Mat'

Original prompt

This section details on the original issue you should resolve

<issue_title>cv.divide overloading doesn't work</issue_title> <issue_description>image image </issue_description>

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

  • Fixes TechStark/opencv-js#65

💡 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 Nov 09 '25 13:11 Copilot