Skip to content

Commit 6d4c621

Browse files
authored
Merge pull request #118 from s-g-1/issue-50-s-g-1
feat: add cv.magnitude
2 parents 54a267b + 7de7de6 commit 6d4c621

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

cc/core/core.cc

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ NAN_MODULE_INIT(Core::Init) {
6565
Nan::SetMethod(target, "solve", Solve);
6666
Nan::SetMethod(target, "solveAsync", SolveAsync);
6767

68+
Nan::SetMethod(target, "magnitude", Magnitude);
69+
Nan::SetMethod(target, "magnitudeAsync", MagnitudeAsync);
70+
6871
Nan::SetMethod(target, "getTickFrequency", GetTickFrequency);
6972
Nan::SetMethod(target, "getTickCount", GetTickCount);
7073
#if CV_VERSION_GREATER_EQUAL(3, 4, 2)
@@ -404,6 +407,14 @@ NAN_METHOD(Core::SolveAsync) {
404407
FF::asyncBinding<CoreBindings::Solve>("Core", "Solve", info);
405408
}
406409

410+
NAN_METHOD(Core::Magnitude) {
411+
FF::syncBinding<CoreBindings::Magnitude>("Core", "Magnitude", info);
412+
}
413+
414+
NAN_METHOD(Core::MagnitudeAsync) {
415+
FF::asyncBinding<CoreBindings::Magnitude>("Core", "Magnitude", info);
416+
}
417+
407418
NAN_METHOD(Core::GetTickFrequency) {
408419
info.GetReturnValue().Set(FF::IntConverter::wrap(cv::getTickFrequency()));
409420
}

cc/core/core.h

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Core : public Nan::ObjectWrap {
6363
static NAN_METHOD(EigenAsync);
6464
static NAN_METHOD(Solve);
6565
static NAN_METHOD(SolveAsync);
66+
static NAN_METHOD(Magnitude);
67+
static NAN_METHOD(MagnitudeAsync);
6668

6769
static NAN_METHOD(GetTickFrequency);
6870
static NAN_METHOD(GetTickCount);

cc/core/coreBindings.h

+13
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@ namespace CoreBindings {
285285
};
286286
};
287287

288+
class Magnitude : public CvBinding {
289+
public:
290+
void setup() {
291+
auto x = req<Mat::Converter>();
292+
auto y = req<Mat::Converter>();
293+
auto magnitude = ret<Mat::Converter>("magnitude");
294+
295+
executeBinding = [=]() {
296+
cv::magnitude(x->ref(), y->ref(), magnitude->ref());
297+
};
298+
};
299+
};
300+
288301
}
289302

290303
#endif

test/tests/core/coreTests.ts

+24
Original file line numberDiff line numberDiff line change
@@ -763,4 +763,28 @@ export default function (args: TestContext) {
763763
describe('Solve y = x equation on Id = X Id', makeTest([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[1, 0, 0], [0, 1, 0], [0, 0, 1]], cv.DECOMP_LU, [[1, 0, 0], [0, 1, 0], [0, 0, 1]]));
764764
describe('Solve y = x equation on Id = X Id', makeTest([[1, 2], [3, 4]], [[5, 6], [7, 8]], cv.DECOMP_LU, [[-3, -4], [4, 5]]));
765765
});
766+
767+
describe('magnitude', () => {
768+
const x = new cv.Mat([[2,0],[0,-2]], cv.CV_32F);
769+
const y = new cv.Mat([[0,1],[-1,0]], cv.CV_32F);
770+
771+
const expectOutput = (res: Mat) => {
772+
expect(res).to.be.instanceOf(cv.Mat);
773+
// Yields: [[2, 1],[1, 2]]
774+
expect(res.at(0,0)).to.equal(2)
775+
expect(res.at(0,1)).to.equal(1)
776+
expect(res.at(1,1)).to.equal(2)
777+
};
778+
779+
generateAPITests({
780+
getDut: () => cv,
781+
hasAsync: true,
782+
methodName: 'magnitude',
783+
getRequiredArgs: () => ([
784+
x, y,
785+
]),
786+
expectOutput,
787+
});
788+
});
789+
766790
}

typings/cv.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,6 @@ export function minAsync(src1: Mat, src2: Mat, dst: Mat): Promise<Mat>;
220220

221221
export function max(src1: Mat, src2: Mat, dst: Mat): Mat;
222222
export function maxAsync(src1: Mat, src2: Mat, dst: Mat): Promise<Mat>;
223+
224+
export function magnitude(x: Mat, y: Mat, magnitude: Mat): Mat;
225+
export function magnitudeAsync(x: Mat, y: Mat, magnitude: Mat): Promise<Mat>;

0 commit comments

Comments
 (0)