Skip to content

Commit 703bbfe

Browse files
committed
Merge pull request #330 from vargad/master
Added Sobel operator
2 parents a7cc7e8 + 38ff7a9 commit 703bbfe

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/Constants.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ void Constants::Init(Local<Object> target) {
6262
CONST_DOUBLE(CV_PI);
6363
CONST(CV_FILLED);
6464

65+
CONST_ENUM(BORDER_DEFAULT);
66+
CONST_ENUM(BORDER_REPLICATE);
67+
CONST_ENUM(BORDER_REFLECT);
68+
CONST_ENUM(BORDER_REFLECT_101);
69+
CONST_ENUM(BORDER_WRAP);
70+
CONST_ENUM(BORDER_CONSTANT);
71+
6572
CONST_ENUM(INTER_NEAREST);
6673
CONST_ENUM(INTER_LINEAR);
6774
CONST_ENUM(INTER_AREA);

src/Matrix.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void Matrix::Init(Local<Object> target) {
5959
Nan::SetPrototypeMethod(ctor, "gaussianBlur", GaussianBlur);
6060
Nan::SetPrototypeMethod(ctor, "medianBlur", MedianBlur);
6161
Nan::SetPrototypeMethod(ctor, "bilateralFilter", BilateralFilter);
62+
Nan::SetPrototypeMethod(ctor, "sobel", Sobel);
6263
Nan::SetPrototypeMethod(ctor, "copy", Copy);
6364
Nan::SetPrototypeMethod(ctor, "flip", Flip);
6465
Nan::SetPrototypeMethod(ctor, "roi", ROI);
@@ -1155,6 +1156,36 @@ NAN_METHOD(Matrix::BilateralFilter) {
11551156
info.GetReturnValue().Set(Nan::Null());
11561157
}
11571158

1159+
NAN_METHOD(Matrix::Sobel) {
1160+
Nan::HandleScope scope;
1161+
1162+
if (info.Length() < 3)
1163+
Nan::ThrowError("Need more arguments: sobel(ddepth, xorder, yorder, ksize=3, scale=1.0, delta=0.0, borderType=CV_BORDER_DEFAULT)");
1164+
1165+
int ddepth = info[0]->IntegerValue();
1166+
int xorder = info[1]->IntegerValue();
1167+
int yorder = info[2]->IntegerValue();
1168+
1169+
int ksize = 3;
1170+
if (info.Length() > 3) ksize = info[3]->IntegerValue();
1171+
double scale = 1;
1172+
if (info.Length() > 4) scale = info[4]->NumberValue();
1173+
double delta = 0;
1174+
if (info.Length() > 5) delta = info[5]->NumberValue();
1175+
int borderType = cv::BORDER_DEFAULT;
1176+
if (info.Length() > 6) borderType = info[6]->IntegerValue();
1177+
1178+
Matrix *self = Nan::ObjectWrap::Unwrap<Matrix>(info.This());
1179+
1180+
Local<Object> result_to_return =
1181+
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
1182+
Matrix *result = Nan::ObjectWrap::Unwrap<Matrix>(result_to_return);
1183+
1184+
cv::Sobel(self->mat, result->mat, ddepth, xorder, yorder, ksize, scale, delta, borderType);
1185+
1186+
info.GetReturnValue().Set(result_to_return);
1187+
}
1188+
11581189
NAN_METHOD(Matrix::Copy) {
11591190
Nan::HandleScope scope;
11601191

src/Matrix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Matrix: public node_opencv::Matrix{
6262
JSFUNC(GaussianBlur)
6363
JSFUNC(MedianBlur)
6464
JSFUNC(BilateralFilter)
65+
JSFUNC(Sobel)
6566
JSFUNC(Copy)
6667
JSFUNC(Flip)
6768
JSFUNC(ROI)

0 commit comments

Comments
 (0)