mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #359 from mvines/pubmat
Define a native interface for unwrapping the cv:Mat from a Matrix object
This commit is contained in:
commit
a7cc7e8761
57
binding.gyp
57
binding.gyp
@ -72,6 +72,63 @@
|
|||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"target_name": "test_nativemat",
|
||||||
|
|
||||||
|
"sources": [
|
||||||
|
"test/nativemat.cc",
|
||||||
|
],
|
||||||
|
|
||||||
|
"libraries": [
|
||||||
|
"<!@(node utils/find-opencv.js --libs)"
|
||||||
|
],
|
||||||
|
# For windows
|
||||||
|
|
||||||
|
"include_dirs": [
|
||||||
|
"<!@(node utils/find-opencv.js --cflags)",
|
||||||
|
"<!(node -e \"require('nan')\")",
|
||||||
|
"<!(node -e \"require('./include_dirs')\")"
|
||||||
|
],
|
||||||
|
|
||||||
|
"cflags!" : [ "-fno-exceptions"],
|
||||||
|
"cflags_cc!": [ "-fno-rtti", "-fno-exceptions"],
|
||||||
|
|
||||||
|
"conditions": [
|
||||||
|
[ "OS==\"linux\"", {
|
||||||
|
"cflags": [
|
||||||
|
"<!@(pkg-config --cflags \"opencv >= 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++",
|
||||||
|
"<!@(pkg-config --cflags opencv)"
|
||||||
|
],
|
||||||
|
"GCC_ENABLE_CPP_RTTI": "YES",
|
||||||
|
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"target_name": "action_after_build",
|
"target_name": "action_after_build",
|
||||||
"type": "none",
|
"type": "none",
|
||||||
|
|||||||
28
inc/Matrix.h
Executable file
28
inc/Matrix.h
Executable 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
14
include_dirs.js
Normal 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')));
|
||||||
@ -145,22 +145,22 @@ NAN_METHOD(Matrix::New) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Matrix::Matrix() :
|
Matrix::Matrix() :
|
||||||
Nan::ObjectWrap() {
|
node_opencv::Matrix() {
|
||||||
mat = cv::Mat();
|
mat = cv::Mat();
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix::Matrix(int rows, int cols) :
|
Matrix::Matrix(int rows, int cols) :
|
||||||
Nan::ObjectWrap() {
|
node_opencv::Matrix() {
|
||||||
mat = cv::Mat(rows, cols, CV_32FC3);
|
mat = cv::Mat(rows, cols, CV_32FC3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix::Matrix(int rows, int cols, int type) :
|
Matrix::Matrix(int rows, int cols, int type) :
|
||||||
Nan::ObjectWrap() {
|
node_opencv::Matrix() {
|
||||||
mat = cv::Mat(rows, cols, type);
|
mat = cv::Mat(rows, cols, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix::Matrix(cv::Mat m, cv::Rect roi) :
|
Matrix::Matrix(cv::Mat m, cv::Rect roi) :
|
||||||
Nan::ObjectWrap() {
|
node_opencv::Matrix() {
|
||||||
mat = cv::Mat(m, roi);
|
mat = cv::Mat(m, roi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
#include "OpenCV.h"
|
#include "OpenCV.h"
|
||||||
|
#include "../inc/Matrix.h"
|
||||||
|
|
||||||
class Matrix: public Nan::ObjectWrap {
|
class Matrix: public node_opencv::Matrix{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cv::Mat mat;
|
|
||||||
static Nan::Persistent<FunctionTemplate> constructor;
|
static Nan::Persistent<FunctionTemplate> constructor;
|
||||||
static void Init(Local<Object> target);
|
static void Init(Local<Object> target);
|
||||||
static NAN_METHOD(New);
|
static NAN_METHOD(New);
|
||||||
|
|||||||
20
test/nativemat.cc
Normal file
20
test/nativemat.cc
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <nan.h>
|
||||||
|
#include <Matrix.h>
|
||||||
|
|
||||||
|
void Size(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
||||||
|
// Unwrap the node-opencv Matrix object into a normal cv::Mat
|
||||||
|
cv::Mat mat = Nan::ObjectWrap::Unwrap<node_opencv::Matrix>(info[0]->ToObject())->mat;
|
||||||
|
|
||||||
|
v8::Local < v8::Array > arr = Nan::New<v8::Array>(2);
|
||||||
|
arr->Set(0, Nan::New<v8::Number>(mat.size().height));
|
||||||
|
arr->Set(1, Nan::New<v8::Number>(mat.size().width));
|
||||||
|
|
||||||
|
info.GetReturnValue().Set(arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init(v8::Local<v8::Object> exports) {
|
||||||
|
exports->Set(Nan::New("size").ToLocalChecked(),
|
||||||
|
Nan::New<v8::FunctionTemplate>(Size)->GetFunction());
|
||||||
|
}
|
||||||
|
|
||||||
|
NODE_MODULE(test_nativemat, Init)
|
||||||
10
test/unit.js
10
test/unit.js
@ -326,6 +326,16 @@ test('LDA Wrap', function(assert) {
|
|||||||
assert.end();
|
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.
|
// Test the examples folder.
|
||||||
require('./examples')()
|
require('./examples')()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user