opencv-js
opencv-js copied to clipboard
Remove unsupported scalar-by-array overload from cv.divide type definition
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 fromcore_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>
![]()
</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.