diff --git a/src/Contours.cc b/src/Contours.cc index 3eb6040..1038220 100755 --- a/src/Contours.cc +++ b/src/Contours.cc @@ -11,14 +11,7 @@ void Contour::Init(Handle target) { NanScope(); - //Class - /*v8::Local m = v8::FunctionTemplate::New(New); - m->SetClassName(v8::String::NewSymbol("Contours")); - - // Constructor - constructor = Persistent::New(m); - constructor->InstanceTemplate()->SetInternalFieldCount(1); - constructor->SetClassName(String::NewSymbol("Contours"));*/ + //Class/contructor Local ctor = NanNew(Contour::New); NanAssignPersistent(constructor, ctor); @@ -41,7 +34,6 @@ Contour::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(ctor, "minAreaRect", MinAreaRect); NODE_SET_PROTOTYPE_METHOD(ctor, "isConvex", IsConvex); NODE_SET_PROTOTYPE_METHOD(ctor, "moments", Moments); - //target->Set(String::NewSymbol("Contours"), m->GetFunction()); target->Set(NanNew("Contours"), ctor->GetFunction()); }; @@ -73,14 +65,14 @@ NAN_METHOD(Contour::Point) { 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)); + Local data = NanNew(); + data->Set(NanNew("x"), NanNew(point.x)); + data->Set(NanNew("y"), NanNew(point.y)); - return scope.Close(data); + NanReturnValue(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. @@ -89,26 +81,28 @@ NAN_METHOD(Contour::Size) { Contour *self = ObjectWrap::Unwrap(args.This()); - return scope.Close(Number::New(self->contours.size())); + NanReturnValue(NanNew(self->contours.size())); } + NAN_METHOD(Contour::CornerCount) { NanScope(); Contour *self = ObjectWrap::Unwrap(args.This()); int pos = args[0]->NumberValue(); - return scope.Close(Number::New(self->contours[pos].size())); + NanReturnValue(NanNew(self->contours[pos].size())); } + NAN_METHOD(Contour::Area) { NanScope(); Contour *self = ObjectWrap::Unwrap(args.This()); int pos = args[0]->NumberValue(); - //return scope.Close(Number::New(contourArea(self->contours))); - return scope.Close(Number::New(contourArea(cv::Mat(self->contours[pos])))); + //NanReturnValue(NanNew(contourArea(self->contours))); + NanReturnValue(NanNew(contourArea(cv::Mat(self->contours[pos])))); } @@ -119,7 +113,7 @@ NAN_METHOD(Contour::ArcLength) { int pos = args[0]->NumberValue(); bool isClosed = args[1]->BooleanValue(); - return scope.Close(Number::New(arcLength(cv::Mat(self->contours[pos]), isClosed))); + NanReturnValue(NanNew(arcLength(cv::Mat(self->contours[pos]), isClosed))); } @@ -135,7 +129,7 @@ NAN_METHOD(Contour::ApproxPolyDP) { approxPolyDP(cv::Mat(self->contours[pos]), approxed, epsilon, isClosed); approxed.copyTo(self->contours[pos]); - return scope.Close(v8::Null()); + NanReturnNull(); } @@ -151,7 +145,7 @@ NAN_METHOD(Contour::ConvexHull) { cv::convexHull(cv::Mat(self->contours[pos]), hull, clockwise); hull.copyTo(self->contours[pos]); - return scope.Close(v8::Null()); + NanReturnNull(); } @@ -162,14 +156,14 @@ NAN_METHOD(Contour::BoundingRect) { int pos = args[0]->NumberValue(); cv::Rect bounding = cv::boundingRect(cv::Mat(self->contours[pos])); - Local rect = Object::New(); + Local rect = NanNew(); - rect->Set(String::NewSymbol("x"), Number::New(bounding.x)); - rect->Set(String::NewSymbol("y"), Number::New(bounding.y)); - rect->Set(String::NewSymbol("width"), Number::New(bounding.width)); - rect->Set(String::NewSymbol("height"), Number::New(bounding.height)); + rect->Set(NanNew("x"), NanNew(bounding.x)); + rect->Set(NanNew("y"), NanNew(bounding.y)); + rect->Set(NanNew("width"), NanNew(bounding.width)); + rect->Set(NanNew("height"), NanNew(bounding.height)); - return scope.Close(rect); + NanReturnValue(rect); } @@ -181,33 +175,33 @@ NAN_METHOD(Contour::MinAreaRect) { cv::RotatedRect minimum = cv::minAreaRect(cv::Mat(self->contours[pos])); - Local rect = Object::New(); - rect->Set(String::NewSymbol("angle"), Number::New(minimum.angle)); + Local rect = NanNew(); + rect->Set(NanNew("angle"), NanNew(minimum.angle)); - Local size = Object::New(); - size->Set(String::NewSymbol("height"), Number::New(minimum.size.height)); - size->Set(String::NewSymbol("width"), Number::New(minimum.size.width)); - rect->Set(String::NewSymbol("size"), size); + Local size = NanNew(); + size->Set(NanNew("height"), NanNew(minimum.size.height)); + size->Set(NanNew("width"), NanNew(minimum.size.width)); + rect->Set(NanNew("size"), size); - Local center = Object::New(); - center->Set(String::NewSymbol("x"), Number::New(minimum.center.x)); - center->Set(String::NewSymbol("y"), Number::New(minimum.center.y)); + Local center = NanNew(); + center->Set(NanNew("x"), NanNew(minimum.center.x)); + center->Set(NanNew("y"), NanNew(minimum.center.y)); - v8::Local points = v8::Array::New(4); + v8::Local points = NanNew(4); cv::Point2f rect_points[4]; minimum.points(rect_points); for (unsigned int i=0; i<4; i++){ - Local point = Object::New(); - point->Set(String::NewSymbol("x"), Number::New(rect_points[i].x)); - point->Set(String::NewSymbol("y"), Number::New(rect_points[i].y)); + Local point = NanNew(); + point->Set(NanNew("x"), NanNew(rect_points[i].x)); + point->Set(NanNew("y"), NanNew(rect_points[i].y)); points->Set(i, point); } - rect->Set(String::NewSymbol("points"), points); + rect->Set(NanNew("points"), points); - return scope.Close(rect); + NanReturnValue(rect); } @@ -217,7 +211,7 @@ NAN_METHOD(Contour::IsConvex) { Contour *self = ObjectWrap::Unwrap(args.This()); int pos = args[0]->NumberValue(); - return scope.Close(Boolean::New(isContourConvex(cv::Mat(self->contours[pos])))); + NanReturnValue(NanNew(isContourConvex(cv::Mat(self->contours[pos])))); } NAN_METHOD(Contour::Moments) { @@ -229,13 +223,13 @@ NAN_METHOD(Contour::Moments) { /// Get the moments cv::Moments mu = moments( self->contours[pos], false ); - Local res = Object::New(); + Local res = NanNew(); - res->Set(String::NewSymbol("m00"), Number::New(mu.m00)); - res->Set(String::NewSymbol("m10"), Number::New(mu.m10)); - res->Set(String::NewSymbol("m01"), Number::New(mu.m01)); - res->Set(String::NewSymbol("m11"), Number::New(mu.m11)); + res->Set(NanNew("m00"), NanNew(mu.m00)); + res->Set(NanNew("m10"), NanNew(mu.m10)); + res->Set(NanNew("m01"), NanNew(mu.m01)); + res->Set(NanNew("m11"), NanNew(mu.m11)); - return scope.Close(res); + NanReturnValue(res); } -*/ +