mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #455 from BBB/drawContour-args
Add support for lineType and offset for drawContours
This commit is contained in:
commit
ffc3625c26
@ -25,13 +25,16 @@ cv.readImage('./files/stuff.png', function(err, im) {
|
|||||||
im_canny.dilate(nIters);
|
im_canny.dilate(nIters);
|
||||||
|
|
||||||
contours = im_canny.findContours();
|
contours = im_canny.findContours();
|
||||||
|
const lineType = 8;
|
||||||
|
const maxLevel = 0;
|
||||||
|
const thickness = 1;
|
||||||
|
|
||||||
for(i = 0; i < contours.size(); i++) {
|
for(i = 0; i < contours.size(); i++) {
|
||||||
if(contours.area(i) > maxArea) {
|
if(contours.area(i) > maxArea) {
|
||||||
var moments = contours.moments(i);
|
var moments = contours.moments(i);
|
||||||
var cgx = Math.round(moments.m10 / moments.m00);
|
var cgx = Math.round(moments.m10 / moments.m00);
|
||||||
var cgy = Math.round(moments.m01 / moments.m00);
|
var cgy = Math.round(moments.m01 / moments.m00);
|
||||||
big.drawContour(contours, i, GREEN);
|
big.drawContour(contours, i, GREEN, thickness, lineType, maxLevel, [0, 0]);
|
||||||
big.line([cgx - 5, cgy], [cgx + 5, cgy], RED);
|
big.line([cgx - 5, cgy], [cgx + 5, cgy], RED);
|
||||||
big.line([cgx, cgy - 5], [cgx, cgy + 5], RED);
|
big.line([cgx, cgy - 5], [cgx, cgy + 5], RED);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1486,7 +1486,16 @@ NAN_METHOD(Matrix::DrawContour) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int thickness = info.Length() < 4 ? 1 : info[3]->NumberValue();
|
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 = info.Length() < 6 ? 0 : info[5]->NumberValue();
|
||||||
|
|
||||||
|
cv::Point offset;
|
||||||
|
if (info.Length() == 6) {
|
||||||
|
Local<Array> _offset = Local<Array>::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, cont->hierarchy, maxLevel, offset);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user