Merge pull request #260 from paulmorrishill/master

Add support for fitEllipse method on contours
This commit is contained in:
Peter Braden 2015-06-15 13:01:33 +02:00
commit 9c318373d0
3 changed files with 33 additions and 0 deletions

View File

@ -194,6 +194,7 @@ contours.arcLength(index, isClosed);
contours.boundingRect(index);
contours.minAreaRect(index);
contours.isConvex(index);
contours.fitEllipse(index);
// Destructively alter contour `index`
contours.approxPolyDP(index, epsilon, isClosed);

View File

@ -29,6 +29,7 @@ Contour::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(ctor, "convexHull", ConvexHull);
NODE_SET_PROTOTYPE_METHOD(ctor, "boundingRect", BoundingRect);
NODE_SET_PROTOTYPE_METHOD(ctor, "minAreaRect", MinAreaRect);
NODE_SET_PROTOTYPE_METHOD(ctor, "fitEllipse", FitEllipse);
NODE_SET_PROTOTYPE_METHOD(ctor, "isConvex", IsConvex);
NODE_SET_PROTOTYPE_METHOD(ctor, "moments", Moments);
NODE_SET_PROTOTYPE_METHOD(ctor, "hierarchy", Hierarchy);
@ -224,6 +225,36 @@ NAN_METHOD(Contour::MinAreaRect) {
}
NAN_METHOD(Contour::FitEllipse) {
NanScope();
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
int pos = args[0]->NumberValue();
if(self->contours[pos].size() >= 5){ //Minimum number for an ellipse
cv::RotatedRect ellipse = cv::fitEllipse(cv::Mat(self->contours[pos]));
Local<Object> jsEllipse = NanNew<Object>();
jsEllipse->Set(NanNew("angle"), NanNew<Number>(ellipse.angle));
Local<Object> size = NanNew<Object>();
size->Set(NanNew("height"), NanNew<Number>(ellipse.size.height));
size->Set(NanNew("width"), NanNew<Number>(ellipse.size.width));
jsEllipse->Set(NanNew("size"), size);
Local<Object> center = NanNew<Object>();
center->Set(NanNew("x"), NanNew<Number>(ellipse.center.x));
center->Set(NanNew("y"), NanNew<Number>(ellipse.center.y));
jsEllipse->Set(NanNew("center"), center);
NanReturnValue(jsEllipse);
}
NanReturnNull();
}
NAN_METHOD(Contour::IsConvex) {
NanScope();

View File

@ -25,6 +25,7 @@ class Contour: public node::ObjectWrap {
JSFUNC(ConvexHull)
JSFUNC(BoundingRect)
JSFUNC(MinAreaRect)
JSFUNC(FitEllipse)
JSFUNC(IsConvex)
JSFUNC(Moments)
JSFUNC(Hierarchy)