From c80577f039c29ae6269d9d04a3bcd5e87c933ed5 Mon Sep 17 00:00:00 2001 From: Ollie Relph Date: Thu, 20 Oct 2016 11:19:45 +0100 Subject: [PATCH 1/4] Add support for lineType and offset for drawContours --- src/Matrix.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index faff68d..a70c125 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -1486,7 +1486,16 @@ NAN_METHOD(Matrix::DrawContour) { } int thickness = info.Length() < 4 ? 1 : info[3]->NumberValue(); - cv::drawContours(self->mat, cont->contours, pos, color, thickness); + int lineType = info.Length() < 5 ? 8 : info[4]->NumberValue(); + int maxLevel = 0; + + cv::Point offset; + if (info.Length() == 6) { + Local _offset = Local::Cast(info[5]); + offset = cv::Point(_offset->Get(0)->ToNumber()->Value(), _offset->Get(1)->ToNumber()->Value()); + } + + cv::drawContours(self->mat, cont->contours, pos, color, thickness, lineType, cv::noArray(), maxLevel, offset); return; } From d3c18389c6f3c5bc8f5c64c95dea841f504beaa6 Mon Sep 17 00:00:00 2001 From: Ollie Relph Date: Thu, 20 Oct 2016 11:39:25 +0100 Subject: [PATCH 2/4] Add an example --- examples/contours.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/contours.js b/examples/contours.js index 43bb0ac..238ca04 100755 --- a/examples/contours.js +++ b/examples/contours.js @@ -25,13 +25,15 @@ cv.readImage('./files/stuff.png', function(err, im) { im_canny.dilate(nIters); contours = im_canny.findContours(); + const lineType = 8; + const thickness = 1; for(i = 0; i < contours.size(); i++) { if(contours.area(i) > maxArea) { var moments = contours.moments(i); var cgx = Math.round(moments.m10 / moments.m00); var cgy = Math.round(moments.m01 / moments.m00); - big.drawContour(contours, i, GREEN); + big.drawContour(contours, i, GREEN, thickness, lineType, [0, 0]); big.line([cgx - 5, cgy], [cgx + 5, cgy], RED); big.line([cgx, cgy - 5], [cgx, cgy + 5], RED); } From 79da65d9a56ca5f2a860a7f3e26e45651beeb2f6 Mon Sep 17 00:00:00 2001 From: Ollie Relph Date: Tue, 25 Oct 2016 11:28:34 +0100 Subject: [PATCH 3/4] Add support for maxLevel --- examples/contours.js | 3 ++- src/Matrix.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/contours.js b/examples/contours.js index 238ca04..dcbf48a 100755 --- a/examples/contours.js +++ b/examples/contours.js @@ -26,6 +26,7 @@ cv.readImage('./files/stuff.png', function(err, im) { contours = im_canny.findContours(); const lineType = 8; + const maxLevel = 0; const thickness = 1; for(i = 0; i < contours.size(); i++) { @@ -33,7 +34,7 @@ cv.readImage('./files/stuff.png', function(err, im) { var moments = contours.moments(i); var cgx = Math.round(moments.m10 / moments.m00); var cgy = Math.round(moments.m01 / moments.m00); - big.drawContour(contours, i, GREEN, thickness, lineType, [0, 0]); + big.drawContour(contours, i, GREEN, thickness, lineType, maxLevel, [0, 0]); big.line([cgx - 5, cgy], [cgx + 5, cgy], RED); big.line([cgx, cgy - 5], [cgx, cgy + 5], RED); } diff --git a/src/Matrix.cc b/src/Matrix.cc index a70c125..3d5db2d 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -1487,7 +1487,7 @@ NAN_METHOD(Matrix::DrawContour) { int thickness = info.Length() < 4 ? 1 : info[3]->NumberValue(); int lineType = info.Length() < 5 ? 8 : info[4]->NumberValue(); - int maxLevel = 0; + int maxLevel = info.Length() < 6 ? 0 : info[5]->NumberValue(); cv::Point offset; if (info.Length() == 6) { From 74c8f4e347ec8bc70bab95bbbde769c212594792 Mon Sep 17 00:00:00 2001 From: Ollie Relph Date: Tue, 25 Oct 2016 11:36:07 +0100 Subject: [PATCH 4/4] Use the contour hierarchy that's been passed --- src/Matrix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index 3d5db2d..170c913 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -1495,7 +1495,7 @@ NAN_METHOD(Matrix::DrawContour) { offset = cv::Point(_offset->Get(0)->ToNumber()->Value(), _offset->Get(1)->ToNumber()->Value()); } - cv::drawContours(self->mat, cont->contours, pos, color, thickness, lineType, cv::noArray(), maxLevel, offset); + cv::drawContours(self->mat, cont->contours, pos, color, thickness, lineType, cont->hierarchy, maxLevel, offset); return; }