diff --git a/cc/core/coreUtils.h b/cc/core/coreUtils.h index df19527fa..7976302f3 100644 --- a/cc/core/coreUtils.h +++ b/cc/core/coreUtils.h @@ -89,6 +89,7 @@ Nan::SetPrototypeMethod(ctor, "bitwiseXor", BitwiseXor); \ Nan::SetPrototypeMethod(ctor, "abs", Abs); \ Nan::SetPrototypeMethod(ctor, "transpose", Transpose); \ + Nan::SetPrototypeMethod(ctor, "inv", Inv); \ Nan::SetPrototypeMethod(ctor, "determinant", Determinant);\ Nan::SetPrototypeMethod(ctor, "matMul", MatMul); @@ -157,6 +158,9 @@ static NAN_METHOD(Transpose) { \ FF_SELF_OPERATOR(cv::transpose); \ } \ + static NAN_METHOD(Inv) { \ + FF_SELF_OPERATOR(cv::invert); \ + } \ static NAN_METHOD(MatMul) { \ FF_OPERATOR(*, FF_APPLY_OPERATOR, Mat, "MatMul"); \ } diff --git a/lib/typings/Mat.d.ts b/lib/typings/Mat.d.ts index 88bab5516..b8681e289 100644 --- a/lib/typings/Mat.d.ts +++ b/lib/typings/Mat.d.ts @@ -205,6 +205,7 @@ export class Mat { inRangeAsync(lower: Vec3, upper: Vec3): Promise; integral(sdepth?: number, sqdepth?: number): { sum: Mat, sqsum: Mat, tilted: Mat }; integralAsync(sdepth?: number, sqdepth?: number): Promise<{ sum: Mat, sqsum: Mat, tilted: Mat }>; + inv(): Mat; laplacian(ddepth: number, ksize?: number, scale?: number, delta?: number, borderType?: number): Mat; laplacianAsync(ddepth: number, ksize?: number, scale?: number, delta?: number, borderType?: number): Promise; matMul(B: Mat): Mat; diff --git a/test/tests/core/Mat/operatorTests.js b/test/tests/core/Mat/operatorTests.js index 5b9a8b01a..b22cf56eb 100644 --- a/test/tests/core/Mat/operatorTests.js +++ b/test/tests/core/Mat/operatorTests.js @@ -5,6 +5,7 @@ module.exports = function ({ cv, utils }) { const { assertError, assertDataDeepEquals, + assertDataAlmostDeepEquals, assertMetaData } = utils; @@ -353,7 +354,25 @@ module.exports = function ({ cv, utils }) { assertDataDeepEquals(res.getDataAsArray(), expectedResult); }); }); + + describe('inv', () => { + it('apply inverse to matrix', () => { + const mat0 = new cv.Mat([ + [4, 7], + [2, 6] + ], cv.CV_32F); + const expectedResult = [ + [0.6, -0.7], + [-0.2, 0.4] + ]; + const res = mat0.inv(); + assertMetaData(res)(2, 2, cv.CV_32F); + + assertDataAlmostDeepEquals(res.getDataAsArray(), expectedResult); + }); + }); + describe('matMul', () => { operatorRequiresArg('matMul');