diff --git a/src/Contours.cc b/src/Contours.cc index 69f80d2..018a1e0 100755 --- a/src/Contours.cc +++ b/src/Contours.cc @@ -25,6 +25,7 @@ Contour::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor, "size", Size); NODE_SET_PROTOTYPE_METHOD(constructor, "area", Area); + NODE_SET_PROTOTYPE_METHOD(constructor, "arcLength", ArcLength); target->Set(String::NewSymbol("Contours"), m->GetFunction()); }; @@ -55,7 +56,6 @@ Contour::Size(const Arguments &args) { Contour *self = ObjectWrap::Unwrap(args.This()); return scope.Close(Number::New(self->contours.size())); - } @@ -68,6 +68,16 @@ Contour::Area(const Arguments &args) { //return scope.Close(Number::New(contourArea(self->contours))); return scope.Close(Number::New(contourArea(cv::Mat(self->contours[pos])))); - - +} + + +Handle +Contour::ArcLength(const Arguments &args) { + HandleScope scope; + + Contour *self = ObjectWrap::Unwrap(args.This()); + int pos = args[0]->NumberValue(); + bool isClosed = args[1]->BooleanValue(); + + return scope.Close(Number::New(arcLength(cv::Mat(self->contours[pos]), isClosed))); } diff --git a/src/Contours.h b/src/Contours.h index 3e4d21a..9cb3f4c 100755 --- a/src/Contours.h +++ b/src/Contours.h @@ -11,10 +11,11 @@ class Contour: public node::ObjectWrap { static void Init(Handle target); static Handle New(const Arguments &args); - Contour(); + Contour(); //JSFUNC(Size) static Handle Size(const v8::Arguments&); static Handle Area(const v8::Arguments&); + static Handle ArcLength(const v8::Arguments&); };