From c4573104976b90ea7591ee1ee160b325c302695d Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 20 Jan 2016 20:42:41 -0800 Subject: [PATCH 1/2] Define a native interface for unwrapping the cv:Mat from a Matrix object --- inc/Matrix.h | 28 ++++++++++++++++++++++++++++ include_dirs.js | 14 ++++++++++++++ src/Matrix.cc | 8 ++++---- src/Matrix.h | 6 +++--- 4 files changed, 49 insertions(+), 7 deletions(-) create mode 100755 inc/Matrix.h create mode 100644 include_dirs.js diff --git a/inc/Matrix.h b/inc/Matrix.h new file mode 100755 index 0000000..beed998 --- /dev/null +++ b/inc/Matrix.h @@ -0,0 +1,28 @@ +/* + This file defines the public native interface into an node-opencv Matrix + object. This is used to retrieve the wrapped OpenCV cv:Mat object from other + native code: + + NAN_METHOD(UnwrapMatrix) { + cv::Mat mat = Nan::ObjectWrap::Unwrap(info[0]->ToObject())->mat; + // ... + } + + */ +#ifndef NODE_OPENCV_MATRIX_H +#define NODE_OPENCV_MATRIX_H +#include +#include + +namespace node_opencv { + +class Matrix: public Nan::ObjectWrap { +public: + cv::Mat mat; +protected: + Matrix(): Nan::ObjectWrap() {}; +}; + +} + +#endif // NODE_OPENCV_MATRIX_H diff --git a/include_dirs.js b/include_dirs.js new file mode 100644 index 0000000..8d72392 --- /dev/null +++ b/include_dirs.js @@ -0,0 +1,14 @@ +// Outputs the path to public node-opencv header files. This is used when +// building other native node modules that require access to the +// node-opencv Matrix base class. +// +// To use this file, add something like the following to your binding.gyp: +// +// "include_dirs": [ +// " constructor; static void Init(Local target); static NAN_METHOD(New); From 38d19a62369c16a27c8167580ae41fa3a05f1eef Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 27 Jan 2016 22:50:00 -0800 Subject: [PATCH 2/2] Add test for inc/Matrix.h --- binding.gyp | 57 +++++++++++++++++++++++++++++++++++++++++++++++ test/nativemat.cc | 20 +++++++++++++++++ test/unit.js | 10 +++++++++ 3 files changed, 87 insertions(+) create mode 100644 test/nativemat.cc diff --git a/binding.gyp b/binding.gyp index 8cde338..240f8d1 100755 --- a/binding.gyp +++ b/binding.gyp @@ -72,6 +72,63 @@ }] ] }, + { + "target_name": "test_nativemat", + + "sources": [ + "test/nativemat.cc", + ], + + "libraries": [ + "= 2.3.1\" )", + "-Wall" + ] + }], + [ "OS==\"win\"", { + "cflags": [ + "-Wall" + ], + "defines": [ + "WIN" + ], + "msvs_settings": { + "VCCLCompilerTool": { + "ExceptionHandling": "2", + "DisableSpecificWarnings": [ "4530", "4506", "4244" ], + }, + } + }], + [ # cflags on OS X are stupid and have to be defined like this + "OS==\"mac\"", { + "xcode_settings": { + "OTHER_CFLAGS": [ + "-mmacosx-version-min=10.7", + "-std=c++11", + "-stdlib=libc++", + " +#include + +void Size(const Nan::FunctionCallbackInfo& info) { + // Unwrap the node-opencv Matrix object into a normal cv::Mat + cv::Mat mat = Nan::ObjectWrap::Unwrap(info[0]->ToObject())->mat; + + v8::Local < v8::Array > arr = Nan::New(2); + arr->Set(0, Nan::New(mat.size().height)); + arr->Set(1, Nan::New(mat.size().width)); + + info.GetReturnValue().Set(arr); +} + +void Init(v8::Local exports) { + exports->Set(Nan::New("size").ToLocalChecked(), + Nan::New(Size)->GetFunction()); +} + +NODE_MODULE(test_nativemat, Init) diff --git a/test/unit.js b/test/unit.js index b271ec4..8cd5ea4 100755 --- a/test/unit.js +++ b/test/unit.js @@ -326,6 +326,16 @@ test('LDA Wrap', function(assert) { assert.end(); }) + +test('Native Matrix', function(assert) { + var nativemat = require('../build/Release/test_nativemat.node'); + var mat = new cv.Matrix(42, 8); + + assert.deepEqual(mat.size(), nativemat.size(mat), 'nativemat'); + assert.end(); +}) + + // Test the examples folder. require('./examples')()