From a1975866737743f04a87db654446155d7f70a139 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 10 Feb 2013 14:58:06 -0800 Subject: [PATCH] Expose point data from Contours Add in a Point method to the Contours class to access the underlying point coordinates from the JavaScript side. --- src/Contours.cc | 18 ++++++++++++++++++ src/Contours.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/Contours.cc b/src/Contours.cc index c5818e0..a3cd6a0 100755 --- a/src/Contours.cc +++ b/src/Contours.cc @@ -23,6 +23,7 @@ Contour::Init(Handle target) { //Local proto = constructor->PrototypeTemplate(); + NODE_SET_PROTOTYPE_METHOD(constructor, "point", Point); NODE_SET_PROTOTYPE_METHOD(constructor, "size", Size); NODE_SET_PROTOTYPE_METHOD(constructor, "cornerCount", CornerCount); NODE_SET_PROTOTYPE_METHOD(constructor, "area", Area); @@ -53,6 +54,23 @@ Contour::Contour(): ObjectWrap() { } +Handle +Contour::Point(const Arguments &args) { + HandleScope scope; + + Contour *self = ObjectWap::Unwrap(args.This()); + int pos = args[0]->NumberValue(); + int index = args[1]->NumberValue(); + + cv::Point point = self->contours[pos][index]; + + Local data = Object::New(); + data->Set(String::NewSymbol("x"), Number::New(point.x)); + data->Set(String::NewSymbol("y"), Number::New(point.y)); + + return scope.Close(data); +} + // FIXME: this sould better be called "Length" as ``Contours`` is an Array like structure // also, this would allow to use ``Size`` for the function returning the number of corners // in the contour for better consistency with OpenCV. diff --git a/src/Contours.h b/src/Contours.h index 259503a..0d69726 100755 --- a/src/Contours.h +++ b/src/Contours.h @@ -14,6 +14,7 @@ class Contour: public node::ObjectWrap { Contour(); //JSFUNC(Size) + static Handle Point(const v8::Arguments&); static Handle Size(const v8::Arguments&); static Handle CornerCount(const v8::Arguments&); static Handle Area(const v8::Arguments&);