Still trying to track down why cv::imread isn't working...

This commit is contained in:
Peter Braden 2012-01-15 18:40:28 -08:00
parent 428bfb6784
commit 388dbcec23
4 changed files with 29 additions and 12 deletions

2
smoketest.js Normal file → Executable file
View File

@ -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"))
console.log(new opencv.Image("./examples/mona.jpg").width, "!!")

View File

@ -15,11 +15,12 @@ Image::Init(Handle<Object> target) {
// Prototype
Local<ObjectTemplate> 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<Object> target) {
Handle<Value>
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<Value>
Image::GetWidth(Local<String>, const AccessorInfo &info) {
HandleScope scope;
return scope.Close(Number::New(5));
}
Handle<Value>
Image::GetHeight(Local<String>, const AccessorInfo &info) {
HandleScope scope;
return scope.Close(Number::New(5));
}

View File

@ -2,8 +2,8 @@
class Image: public node::ObjectWrap {
public:
std::string filename;
cv::Mat image;
std::string filename;
cv::Mat image;
static Persistent<FunctionTemplate> constructor;
static void Init(Handle<Object> target);

View File

@ -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();
}