From 388dbcec239912082e951b93d33bb129f7d88f24 Mon Sep 17 00:00:00 2001 From: Peter Braden Date: Sun, 15 Jan 2012 18:40:28 -0800 Subject: [PATCH] Still trying to track down why cv::imread isn't working... --- smoketest.js | 2 +- src/Image.cc | 33 +++++++++++++++++++++++++-------- src/Image.h | 4 ++-- src/Point.cc | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) mode change 100644 => 100755 smoketest.js diff --git a/smoketest.js b/smoketest.js old mode 100644 new mode 100755 index ee2f142..7d091fd --- a/smoketest.js +++ b/smoketest.js @@ -11,4 +11,4 @@ assert.equal(Math.round(new opencv.Point(1.2, 2.75).y *100), 275) -console.log(opencv.Image("./examples/mona.jpg")) \ No newline at end of file +console.log(new opencv.Image("./examples/mona.jpg").width, "!!") \ No newline at end of file diff --git a/src/Image.cc b/src/Image.cc index 2c8fa0e..37cd8db 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -15,11 +15,12 @@ Image::Init(Handle target) { // Prototype Local proto = constructor->PrototypeTemplate(); + proto->SetAccessor(String::NewSymbol("width"), GetWidth); + proto->SetAccessor(String::NewSymbol("height"), GetHeight); /*proto->SetAccessor(String::NewSymbol("source"), GetSource, SetSource); proto->SetAccessor(String::NewSymbol("complete"), GetComplete); - proto->SetAccessor(String::NewSymbol("width"), GetWidth); - proto->SetAccessor(String::NewSymbol("height"), GetHeight); + proto->SetAccessor(String::NewSymbol("onload"), GetOnload, SetOnload); proto->SetAccessor(String::NewSymbol("onerror"), GetOnerror, SetOnerror);*/ target->Set(String::NewSymbol("Image"), constructor->GetFunction()); @@ -27,18 +28,20 @@ Image::Init(Handle target) { Handle Image::New(const Arguments &args) { + HandleScope scope; + Image *img; int width, height; if (args[0]->IsNumber() && args[1]->IsNumber()){ - width = args[0]->Uint32Value(); - height = args[1]->Uint32Value(); - img = new Image(width, height); + width = args[0]->Uint32Value(); + height = args[1]->Uint32Value(); + img = new Image(width, height); } else { - img = new Image(*args[0]); + img = new Image(*args[0]); } - + img->Wrap(args.This()); return args.This(); }; @@ -50,8 +53,22 @@ Image::Image(int width, int height): ObjectWrap() { }; + Image::Image(v8::Value* fileName): ObjectWrap() { filename = std::string(*v8::String::AsciiValue(fileName->ToString())); - image = cv::imread(filename, -1); + //image = cv::imread(filename, -1); }; + +Handle +Image::GetWidth(Local, const AccessorInfo &info) { + HandleScope scope; + return scope.Close(Number::New(5)); +} + +Handle +Image::GetHeight(Local, const AccessorInfo &info) { + HandleScope scope; + return scope.Close(Number::New(5)); +} + diff --git a/src/Image.h b/src/Image.h index d781e70..81b37a6 100644 --- a/src/Image.h +++ b/src/Image.h @@ -2,8 +2,8 @@ class Image: public node::ObjectWrap { public: - std::string filename; - cv::Mat image; + std::string filename; + cv::Mat image; static Persistent constructor; static void Init(Handle target); diff --git a/src/Point.cc b/src/Point.cc index aa14db9..3d86c14 100644 --- a/src/Point.cc +++ b/src/Point.cc @@ -34,7 +34,7 @@ Point::New(const Arguments &args) { double x = 0, y = 0; if (args[0]->IsNumber()) x = args[0]->NumberValue(); if (args[1]->IsNumber()) y = args[1]->NumberValue(); - Point *pt = new Point(x, y); + Point *pt = new Point(x, y); pt->Wrap(args.This()); return args.This(); }