Skip to content

Commit

Permalink
fixed draw functions in examples + fixed draw functions optional params
Browse files Browse the repository at this point in the history
  • Loading branch information
justadudewhohacks committed Jan 18, 2018
1 parent 38f395f commit e44bfd4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
15 changes: 8 additions & 7 deletions cc/core/MatImgproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,8 @@ struct MatImgproc::DrawWorker : public SimpleWorker {
}

bool hasOptArgsObject(Nan::NAN_METHOD_ARGS_TYPE info) {
return FF_ARG_IS_OBJECT(getDrawParamsIndex());
return FF_ARG_IS_OBJECT(getDrawParamsIndex())
&& !Vec3::Converter::hasInstance(info[getDrawParamsIndex()]);
}

bool unwrapOptionalArgsFromOpts(Nan::NAN_METHOD_ARGS_TYPE info) {
Expand Down Expand Up @@ -1448,10 +1449,10 @@ struct MatImgproc::DrawEllipseWorker : public MatImgproc::DrawWorker {

cv::RotatedRect box;

cv::Point2d center;
cv::Size2d axes;
double angle;
double startAngle;
cv::Point2d center;
cv::Size2d axes;
double angle;
double startAngle;
double endAngle;

bool isArgBox = false;
Expand Down Expand Up @@ -1594,7 +1595,7 @@ NAN_METHOD(MatImgproc::DrawFillConvexPoly) {
}

struct MatImgproc::PutTextWorker : public MatImgproc::DrawWorker {
PutTextWorker(cv::Mat self) : DrawWorker(self, false) {
PutTextWorker(cv::Mat self) : DrawWorker(self) {
}

std::string text;
Expand All @@ -1604,7 +1605,7 @@ struct MatImgproc::PutTextWorker : public MatImgproc::DrawWorker {
bool bottomLeftOrigin = false;

const char* execute() {
cv::putText(self, text, org, fontFace, fontScale, color, lineType, shift, bottomLeftOrigin);
cv::putText(self, text, org, fontFace, fontScale, color, thickness, lineType, bottomLeftOrigin);
return "";
}

Expand Down
12 changes: 8 additions & 4 deletions examples/faceRecognition1.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ faces.forEach((faceRect) => {
twoFacesImg.drawRectangle(
upperLeftLarge,
bottomRight,
new cv.Vec(255, 0, 0),
{ thickness }
{
color: new cv.Vec(255, 0, 0),
thickness
}
);

// label the rectangle with prediction result
Expand All @@ -69,8 +71,10 @@ faces.forEach((faceRect) => {
upperLeftLarge.add(new cv.Point(0, 140)),
cv.FONT_ITALIC,
1.2,
new cv.Vec(0, 0, 255),
{ thickness }
{
color: new cv.Vec(0, 0, 255),
thickness
}
);
});

Expand Down
18 changes: 6 additions & 12 deletions examples/handGestureRecognition0.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,20 @@ grabFrames('../data/hand-gesture.mp4', delay, (frame) => {
resizedImg.drawLine(
v.pt,
v.d1,
green,
{ thickness: 2 }
{ color: green, thickness: 2 }
);
resizedImg.drawLine(
v.pt,
v.d2,
green,
{ thickness: 2 }
{ color: green, thickness: 2 }
);
resizedImg.drawEllipse(
new cv.RotatedRect(v.pt, new cv.Size(20, 20), 0),
red,
{ thickness: 2 }
{ color: red, thickness: 2 }
);
result.drawEllipse(
new cv.RotatedRect(v.pt, new cv.Size(20, 20), 0),
red,
{ thickness: 2 }
{ color: red, thickness: 2 }
);
});

Expand All @@ -173,8 +169,7 @@ grabFrames('../data/hand-gesture.mp4', delay, (frame) => {
result.drawRectangle(
new cv.Point(10, 10),
new cv.Point(70, 70),
green,
{ thickness: 2 }
{ color: green, thickness: 2 }
);

const fontScale = 2;
Expand All @@ -183,8 +178,7 @@ grabFrames('../data/hand-gesture.mp4', delay, (frame) => {
new cv.Point(20, 60),
cv.FONT_ITALIC,
fontScale,
green,
{ thickness: 2 }
{ color: green, thickness: 2 }
);

const { rows, cols } = result;
Expand Down
9 changes: 4 additions & 5 deletions examples/templateMatching.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ const findWaldo = async () => {

// Draw bounding rectangle
originalMat.drawRectangle(
new cv.Point(x, y),
new cv.Point(x + waldoMat.cols, y + waldoMat.rows),
new cv.Rect(x, y, waldoMat.cols, waldoMat.rows),
new cv.Vec(0, 255, 0),
cv.LINE_8,
2
2,
cv.LINE_8
);

// Open result in new window
cv.imshow('We\'ve found Waldo!', originalMat);
cv.waitKey(7000);
cv.waitKey();
};

// noinspection JSIgnoredPromiseFromCall
Expand Down
7 changes: 3 additions & 4 deletions examples/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ exports.drawRectAroundBlobs = (binaryImg, dstImg, minPxSize, fixedRectWidth) =>

const drawRect = (image, rect, color, opts = { thickness: 2 }) =>
image.drawRectangle(
new cv.Point(rect.x, rect.y),
new cv.Point(rect.x + rect.width, rect.y + rect.height),
rect,
color,
cv.LINE_8,
opts.thickness
opts.thickness,
cv.LINE_8
);

exports.drawRect = drawRect;
Expand Down

0 comments on commit e44bfd4

Please sign in to comment.