Define a native interface for unwrapping the cv:Mat from a Matrix object

This commit is contained in:
Michael Vines 2016-01-20 20:42:41 -08:00
parent 3d06aefe75
commit c457310497
4 changed files with 49 additions and 7 deletions

28
inc/Matrix.h Executable file
View File

@ -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<node_opencv::Matrix>(info[0]->ToObject())->mat;
// ...
}
*/
#ifndef NODE_OPENCV_MATRIX_H
#define NODE_OPENCV_MATRIX_H
#include <opencv/cv.h>
#include <node_object_wrap.h>
namespace node_opencv {
class Matrix: public Nan::ObjectWrap {
public:
cv::Mat mat;
protected:
Matrix(): Nan::ObjectWrap() {};
};
}
#endif // NODE_OPENCV_MATRIX_H

14
include_dirs.js Normal file
View File

@ -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": [
// "<!@(pkg-config --cflags opencv)",
// "<!(node -e \"require('nan')\")",
// "<!(node -e \"require('opencv/include_dirs')\")"
// ],
//
var path = require('path');
console.log(path.relative('.', path.join(__dirname, 'inc')));

View File

@ -145,22 +145,22 @@ NAN_METHOD(Matrix::New) {
}
Matrix::Matrix() :
Nan::ObjectWrap() {
node_opencv::Matrix() {
mat = cv::Mat();
}
Matrix::Matrix(int rows, int cols) :
Nan::ObjectWrap() {
node_opencv::Matrix() {
mat = cv::Mat(rows, cols, CV_32FC3);
}
Matrix::Matrix(int rows, int cols, int type) :
Nan::ObjectWrap() {
node_opencv::Matrix() {
mat = cv::Mat(rows, cols, type);
}
Matrix::Matrix(cv::Mat m, cv::Rect roi) :
Nan::ObjectWrap() {
node_opencv::Matrix() {
mat = cv::Mat(m, roi);
}

View File

@ -1,9 +1,9 @@
#include "OpenCV.h"
#include "../inc/Matrix.h"
class Matrix: public Nan::ObjectWrap {
class Matrix: public node_opencv::Matrix{
public:
cv::Mat mat;
static Nan::Persistent<FunctionTemplate> constructor;
static void Init(Local<Object> target);
static NAN_METHOD(New);