diff --git a/src/Constants.cc b/src/Constants.cc index 4b7f578..f2bd76a 100644 --- a/src/Constants.cc +++ b/src/Constants.cc @@ -62,6 +62,13 @@ void Constants::Init(Local target) { CONST_DOUBLE(CV_PI); CONST(CV_FILLED); + CONST_ENUM(BORDER_DEFAULT); + CONST_ENUM(BORDER_REPLICATE); + CONST_ENUM(BORDER_REFLECT); + CONST_ENUM(BORDER_REFLECT_101); + CONST_ENUM(BORDER_WRAP); + CONST_ENUM(BORDER_CONSTANT); + CONST_ENUM(INTER_NEAREST); CONST_ENUM(INTER_LINEAR); CONST_ENUM(INTER_AREA); diff --git a/src/Matrix.cc b/src/Matrix.cc index 6d9eaca..51525ff 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -59,6 +59,7 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "gaussianBlur", GaussianBlur); Nan::SetPrototypeMethod(ctor, "medianBlur", MedianBlur); Nan::SetPrototypeMethod(ctor, "bilateralFilter", BilateralFilter); + Nan::SetPrototypeMethod(ctor, "sobel", Sobel); Nan::SetPrototypeMethod(ctor, "copy", Copy); Nan::SetPrototypeMethod(ctor, "flip", Flip); Nan::SetPrototypeMethod(ctor, "roi", ROI); @@ -1155,6 +1156,36 @@ NAN_METHOD(Matrix::BilateralFilter) { info.GetReturnValue().Set(Nan::Null()); } +NAN_METHOD(Matrix::Sobel) { + Nan::HandleScope scope; + + if (info.Length() < 3) + Nan::ThrowError("Need more arguments: sobel(ddepth, xorder, yorder, ksize=3, scale=1.0, delta=0.0, borderType=CV_BORDER_DEFAULT)"); + + int ddepth = info[0]->IntegerValue(); + int xorder = info[1]->IntegerValue(); + int yorder = info[2]->IntegerValue(); + + int ksize = 3; + if (info.Length() > 3) ksize = info[3]->IntegerValue(); + double scale = 1; + if (info.Length() > 4) scale = info[4]->NumberValue(); + double delta = 0; + if (info.Length() > 5) delta = info[5]->NumberValue(); + int borderType = cv::BORDER_DEFAULT; + if (info.Length() > 6) borderType = info[6]->IntegerValue(); + + Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); + + Local result_to_return = + Nan::New(Matrix::constructor)->GetFunction()->NewInstance(); + Matrix *result = Nan::ObjectWrap::Unwrap(result_to_return); + + cv::Sobel(self->mat, result->mat, ddepth, xorder, yorder, ksize, scale, delta, borderType); + + info.GetReturnValue().Set(result_to_return); +} + NAN_METHOD(Matrix::Copy) { Nan::HandleScope scope; diff --git a/src/Matrix.h b/src/Matrix.h index 5669b4f..2d48a59 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -62,6 +62,7 @@ public: JSFUNC(GaussianBlur) JSFUNC(MedianBlur) JSFUNC(BilateralFilter) + JSFUNC(Sobel) JSFUNC(Copy) JSFUNC(Flip) JSFUNC(ROI)