mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Expose point data from Contours
Add in a Point method to the Contours class to access the underlying point coordinates from the JavaScript side.
This commit is contained in:
parent
e64b558bbd
commit
a197586673
@ -23,6 +23,7 @@ Contour::Init(Handle<Object> target) {
|
|||||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||||
|
|
||||||
|
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(constructor, "point", Point);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "size", Size);
|
NODE_SET_PROTOTYPE_METHOD(constructor, "size", Size);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "cornerCount", CornerCount);
|
NODE_SET_PROTOTYPE_METHOD(constructor, "cornerCount", CornerCount);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "area", Area);
|
NODE_SET_PROTOTYPE_METHOD(constructor, "area", Area);
|
||||||
@ -53,6 +54,23 @@ Contour::Contour(): ObjectWrap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Handle<Value>
|
||||||
|
Contour::Point(const Arguments &args) {
|
||||||
|
HandleScope scope;
|
||||||
|
|
||||||
|
Contour *self = ObjectWap::Unwrap<Contour>(args.This());
|
||||||
|
int pos = args[0]->NumberValue();
|
||||||
|
int index = args[1]->NumberValue();
|
||||||
|
|
||||||
|
cv::Point point = self->contours[pos][index];
|
||||||
|
|
||||||
|
Local<Object> 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
|
// 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
|
// also, this would allow to use ``Size`` for the function returning the number of corners
|
||||||
// in the contour for better consistency with OpenCV.
|
// in the contour for better consistency with OpenCV.
|
||||||
|
|||||||
@ -14,6 +14,7 @@ class Contour: public node::ObjectWrap {
|
|||||||
Contour();
|
Contour();
|
||||||
|
|
||||||
//JSFUNC(Size)
|
//JSFUNC(Size)
|
||||||
|
static Handle<Value> Point(const v8::Arguments&);
|
||||||
static Handle<Value> Size(const v8::Arguments&);
|
static Handle<Value> Size(const v8::Arguments&);
|
||||||
static Handle<Value> CornerCount(const v8::Arguments&);
|
static Handle<Value> CornerCount(const v8::Arguments&);
|
||||||
static Handle<Value> Area(const v8::Arguments&);
|
static Handle<Value> Area(const v8::Arguments&);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user