mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #169 from emallson/master
Implement `new cv.Matrix(rows, cols, type)` constructor
This commit is contained in:
commit
88aecbb4e7
14
binding.gyp
14
binding.gyp
@ -1,7 +1,7 @@
|
||||
{
|
||||
"targets": [{
|
||||
"targets": [{
|
||||
"target_name": "opencv"
|
||||
, "sources": [
|
||||
, "sources": [
|
||||
"src/init.cc"
|
||||
, "src/Matrix.cc"
|
||||
, "src/OpenCV.cc"
|
||||
@ -13,16 +13,17 @@
|
||||
, "src/HighGUI.cc"
|
||||
, "src/FaceRecognizer.cc"
|
||||
, "src/BackgroundSubtractor.cc"
|
||||
, "src/Constants.cc"
|
||||
]
|
||||
, 'libraries': [
|
||||
'<!@(pkg-config --libs opencv)'
|
||||
]
|
||||
|
||||
|
||||
# For windows
|
||||
,'include_dirs': [
|
||||
'<!@(pkg-config --cflags opencv)'
|
||||
]
|
||||
|
||||
|
||||
, 'cflags': [
|
||||
'<!@(pkg-config --cflags "opencv >= 2.3.1" )'
|
||||
, '-Wall'
|
||||
@ -42,9 +43,8 @@
|
||||
, "GCC_ENABLE_CPP_RTTI": "YES"
|
||||
, "GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
||||
}
|
||||
}]
|
||||
|
||||
}]
|
||||
|
||||
]
|
||||
}]
|
||||
}
|
||||
|
||||
|
||||
58
src/Constants.cc
Normal file
58
src/Constants.cc
Normal file
@ -0,0 +1,58 @@
|
||||
#include "OpenCV.h"
|
||||
#include "Constants.h"
|
||||
|
||||
#define CONST(C) inner->Set(String::NewSymbol(#C), Integer::New(C));
|
||||
|
||||
void
|
||||
Constants::Init(Handle<Object> target) {
|
||||
|
||||
Persistent<Object> inner = Persistent<Object>::New(Object::New());
|
||||
|
||||
CONST(CV_8U);
|
||||
CONST(CV_8S);
|
||||
CONST(CV_16U);
|
||||
CONST(CV_16S);
|
||||
CONST(CV_32S);
|
||||
CONST(CV_32F);
|
||||
CONST(CV_64F);
|
||||
CONST(CV_USRTYPE1);
|
||||
|
||||
CONST(CV_8UC1);
|
||||
CONST(CV_8UC2);
|
||||
CONST(CV_8UC3);
|
||||
CONST(CV_8UC4);
|
||||
|
||||
CONST(CV_8SC1);
|
||||
CONST(CV_8SC2);
|
||||
CONST(CV_8SC3);
|
||||
CONST(CV_8SC4);
|
||||
|
||||
CONST(CV_16UC1);
|
||||
CONST(CV_16UC2);
|
||||
CONST(CV_16UC3);
|
||||
CONST(CV_16UC4);
|
||||
|
||||
CONST(CV_16SC1);
|
||||
CONST(CV_16SC2);
|
||||
CONST(CV_16SC3);
|
||||
CONST(CV_16SC4);
|
||||
|
||||
CONST(CV_32SC1);
|
||||
CONST(CV_32SC2);
|
||||
CONST(CV_32SC3);
|
||||
CONST(CV_32SC4);
|
||||
|
||||
CONST(CV_32FC1);
|
||||
CONST(CV_32FC2);
|
||||
CONST(CV_32FC3);
|
||||
CONST(CV_32FC4);
|
||||
|
||||
CONST(CV_64FC1);
|
||||
CONST(CV_64FC2);
|
||||
CONST(CV_64FC3);
|
||||
CONST(CV_64FC4);
|
||||
|
||||
target->Set(String::NewSymbol("Constants"), inner);
|
||||
}
|
||||
|
||||
#undef CONST
|
||||
6
src/Constants.h
Normal file
6
src/Constants.h
Normal file
@ -0,0 +1,6 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class Constants: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
};
|
||||
@ -104,8 +104,8 @@ Matrix::Init(Handle<Object> target) {
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "pushBack", PushBack);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "putText", PutText);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "getPerspectiveTransform", GetPerspectiveTransform);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "getPerspectiveTransform", GetPerspectiveTransform);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "warpPerspective", WarpPerspective);
|
||||
|
||||
NODE_SET_METHOD(constructor, "Eye", Eye);
|
||||
@ -132,7 +132,9 @@ Matrix::New(const Arguments &args) {
|
||||
if (args.Length() == 0){
|
||||
mat = new Matrix;
|
||||
} else if (args.Length() == 2 && args[0]->IsInt32() && args[1]->IsInt32()){
|
||||
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||
} else if (args.Length() == 3 && args[0]->IsInt32() && args[1]->IsInt32() && args[2]->IsInt32()) {
|
||||
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue());
|
||||
} else if (args.Length() == 5) {
|
||||
Matrix *other = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
int x = args[1]->IntegerValue();
|
||||
@ -156,6 +158,10 @@ Matrix::Matrix(int rows, int cols): ObjectWrap() {
|
||||
mat = cv::Mat(rows, cols, CV_32FC3);
|
||||
}
|
||||
|
||||
Matrix::Matrix(int rows, int cols, int type): ObjectWrap() {
|
||||
mat = cv::Mat(rows, cols, type);
|
||||
}
|
||||
|
||||
Matrix::Matrix(cv::Mat m, cv::Rect roi): ObjectWrap() {
|
||||
mat = cv::Mat(m, roi);
|
||||
}
|
||||
@ -444,7 +450,7 @@ Matrix::ToBuffer(const v8::Arguments& args){
|
||||
if ((args.Length() > 0) && (args[0]->IsFunction())) {
|
||||
return Matrix::ToBufferAsync(args);
|
||||
}
|
||||
|
||||
|
||||
// SergeMv changes
|
||||
// img.toBuffer({ext: ".png", pngCompression: 9}); // default png compression is 3
|
||||
// img.toBuffer({ext: ".jpg", jpegQuality: 80});
|
||||
@ -474,7 +480,7 @@ Matrix::ToBuffer(const v8::Arguments& args){
|
||||
int compression = options->Get(v8::String::New("pngCompression"))->IntegerValue();
|
||||
params.push_back(CV_IMWRITE_PNG_COMPRESSION);
|
||||
params.push_back(compression);
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------
|
||||
|
||||
@ -539,7 +545,7 @@ Matrix::ToBufferAsync(const v8::Arguments& args){
|
||||
int compression = options->Get(v8::String::New("pngCompression"))->IntegerValue();
|
||||
baton->params.push_back(CV_IMWRITE_PNG_COMPRESSION);
|
||||
baton->params.push_back(compression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
baton->ext = ext;
|
||||
@ -658,11 +664,11 @@ Matrix::Ellipse(const v8::Arguments& args){
|
||||
y = args[1]->Uint32Value();
|
||||
width = args[2]->Uint32Value();
|
||||
height = args[3]->Uint32Value();
|
||||
|
||||
|
||||
if(args[4]->IsArray()) {
|
||||
Local<Object> objColor = args[4]->ToObject();
|
||||
color = setColor(objColor);
|
||||
}
|
||||
}
|
||||
|
||||
if(args[5]->IntegerValue())
|
||||
thickness = args[5]->IntegerValue();
|
||||
@ -747,7 +753,7 @@ Matrix::Save(const v8::Arguments& args) {
|
||||
if (args.Length() > 1) {
|
||||
return SaveAsync(args);
|
||||
}
|
||||
|
||||
|
||||
if (!args[0]->IsString())
|
||||
return v8::ThrowException(v8::Exception::TypeError(String::New("filename required")));
|
||||
|
||||
@ -955,7 +961,7 @@ Matrix::BilateralFilter(const v8::Arguments &args) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cv::bilateralFilter(self->mat, filtered, d, sigmaColor, sigmaSpace, borderType);
|
||||
filtered.copyTo(self->mat);
|
||||
|
||||
@ -1351,7 +1357,7 @@ Matrix::Resize(const v8::Arguments& args){
|
||||
CV_INTER_LANCZOS4 =4
|
||||
*/
|
||||
int interpolation = (args.Length() < 3) ? (int)cv::INTER_LINEAR : args[2]->Uint32Value();
|
||||
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
cv::Mat res = cv::Mat(x, y, CV_32FC3);
|
||||
cv::resize(self->mat, res, cv::Size(x, y), 0, 0, interpolation);
|
||||
@ -1392,18 +1398,18 @@ Matrix::Rotate(const v8::Arguments& args){
|
||||
// Now flip the image
|
||||
int mode = -1; // flip around both axes
|
||||
// If counterclockwise, flip around the x-axis
|
||||
if (angle2 == 90) { mode = 0; }
|
||||
if (angle2 == 90) { mode = 0; }
|
||||
// If clockwise, flip around the y-axis
|
||||
if (angle2 == 270) { mode = 1; }
|
||||
if (angle2 == 270) { mode = 1; }
|
||||
cv::flip(self->mat, self->mat, mode);
|
||||
|
||||
|
||||
return scope.Close(Undefined());
|
||||
}
|
||||
//-------------
|
||||
|
||||
int x = args[1]->IsUndefined() ? round(self->mat.size().width / 2) : args[1]->Uint32Value();
|
||||
int y = args[1]->IsUndefined() ? round(self->mat.size().height / 2) : args[2]->Uint32Value();
|
||||
|
||||
|
||||
cv::Point center = cv::Point(x,y);
|
||||
rotMatrix = getRotationMatrix2D(center, angle, 1.0);
|
||||
|
||||
@ -1474,7 +1480,7 @@ Matrix::AdjustROI(const v8::Arguments& args) {
|
||||
Handle<Value>
|
||||
Matrix::LocateROI(const v8::Arguments& args) {
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
|
||||
cv::Size wholeSize;
|
||||
cv::Point ofs;
|
||||
|
||||
@ -1583,7 +1589,7 @@ Matrix::CopyTo(const v8::Arguments& args) {
|
||||
Matrix * self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
int width = self->mat.size().width;
|
||||
int height = self->mat.size().height;
|
||||
|
||||
|
||||
// param 0 - destination image:
|
||||
Matrix *dest = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
// param 1 - x coord of the destination
|
||||
@ -1615,7 +1621,7 @@ Matrix::CvtColor(const v8::Arguments& args) {
|
||||
//
|
||||
if (!strcmp(sTransform, "CV_BGR2GRAY")) { iTransform = CV_BGR2GRAY; }
|
||||
else if (!strcmp(sTransform, "CV_GRAY2BGR")) { iTransform = CV_GRAY2BGR; }
|
||||
//
|
||||
//
|
||||
else if (!strcmp(sTransform, "CV_BGR2XYZ")) { iTransform = CV_BGR2XYZ; }
|
||||
else if (!strcmp(sTransform, "CV_XYZ2BGR")) { iTransform = CV_XYZ2BGR; }
|
||||
//
|
||||
@ -1638,7 +1644,7 @@ Matrix::CvtColor(const v8::Arguments& args) {
|
||||
else if (!strcmp(sTransform, "CV_BayerGB2BGR")) { iTransform = CV_BayerGB2BGR; }
|
||||
else if (!strcmp(sTransform, "CV_BayerRG2BGR")) { iTransform = CV_BayerRG2BGR; }
|
||||
else if (!strcmp(sTransform, "CV_BayerGR2BGR")) { iTransform = CV_BayerGR2BGR; }
|
||||
else {
|
||||
else {
|
||||
iTransform = 0; // to avoid compiler warning
|
||||
return v8::ThrowException(Exception::TypeError(String::New(
|
||||
"Conversion code is unsupported")));
|
||||
@ -1705,7 +1711,7 @@ Matrix::Merge(const v8::Arguments& args) {
|
||||
Handle<Value>
|
||||
Matrix::EqualizeHist(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
|
||||
Matrix * self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
|
||||
cv::equalizeHist(self->mat, self->mat);
|
||||
@ -1760,7 +1766,7 @@ Matrix::MatchTemplate(const v8::Arguments& args) {
|
||||
TM_CCOEFF =4
|
||||
TM_CCOEFF_NORMED =5
|
||||
*/
|
||||
|
||||
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
@ -1837,7 +1843,7 @@ Matrix::PutText(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
|
||||
|
||||
v8::String::AsciiValue textString(args[0]);
|
||||
char *text = (char *) malloc(textString.length() + 1);
|
||||
strcpy(text, *textString);
|
||||
@ -1928,7 +1934,7 @@ Matrix::WarpPerspective(const v8::Arguments& args) {
|
||||
Handle<Value>
|
||||
Matrix::CopyWithMask(const v8::Arguments& args) {
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
|
||||
// param 0 - destination image:
|
||||
Matrix *dest = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
// param 1 - mask. same size as src and dest
|
||||
@ -1943,7 +1949,7 @@ Matrix::CopyWithMask(const v8::Arguments& args) {
|
||||
Handle<Value>
|
||||
Matrix::SetWithMask(const v8::Arguments& args) {
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
|
||||
// param 0 - target value:
|
||||
Local<Object> valArray = args[0]->ToObject();
|
||||
cv::Scalar newvals;
|
||||
@ -1962,7 +1968,7 @@ Matrix::SetWithMask(const v8::Arguments& args) {
|
||||
Handle<Value>
|
||||
Matrix::MeanWithMask(const v8::Arguments& args) {
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
|
||||
// param 0 - mask. same size as src and dest
|
||||
Matrix *mask = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
|
||||
@ -2007,4 +2013,4 @@ Matrix::Shift(const v8::Arguments& args){
|
||||
self->mat = res;
|
||||
|
||||
return scope.Close(Undefined());
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ class Matrix: public node::ObjectWrap {
|
||||
Matrix();
|
||||
Matrix(cv::Mat other, cv::Rect roi);
|
||||
Matrix(int rows, int cols);
|
||||
Matrix(int rows, int cols, int typ);
|
||||
Matrix(int rows, int cols, int type);
|
||||
|
||||
static double DblGet(cv::Mat mat, int i, int j);
|
||||
|
||||
@ -98,7 +98,7 @@ class Matrix: public node::ObjectWrap {
|
||||
JSFUNC(PushBack)
|
||||
|
||||
JSFUNC(PutText)
|
||||
JSFUNC(GetPerspectiveTransform)
|
||||
JSFUNC(GetPerspectiveTransform)
|
||||
JSFUNC(WarpPerspective)
|
||||
|
||||
JSFUNC(CopyWithMask)
|
||||
@ -138,4 +138,3 @@ class Matrix: public node::ObjectWrap {
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "CamShift.h"
|
||||
#include "HighGUI.h"
|
||||
#include "FaceRecognizer.h"
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
extern "C" void
|
||||
@ -20,6 +21,8 @@ init(Handle<Object> target) {
|
||||
Contour::Init(target);
|
||||
TrackedObject::Init(target);
|
||||
NamedWindow::Init(target);
|
||||
Constants::Init(target);
|
||||
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
FaceRecognizerWrap::Init(target);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user