mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
- migration of OpenCV.h/.cc done
- migration of init.cc done - migration of Matrix.cc about half done - migration of Contours.cc in progress
This commit is contained in:
parent
cd303829de
commit
d0351f336f
@ -1,5 +1,6 @@
|
|||||||
#include "Contours.h"
|
#include "Contours.h"
|
||||||
#include "OpenCV.h"
|
#include "OpenCV.h"
|
||||||
|
#include <nan.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -8,56 +9,63 @@ v8::Persistent<FunctionTemplate> Contour::constructor;
|
|||||||
|
|
||||||
void
|
void
|
||||||
Contour::Init(Handle<Object> target) {
|
Contour::Init(Handle<Object> target) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
//Class
|
//Class
|
||||||
v8::Local<v8::FunctionTemplate> m = v8::FunctionTemplate::New(New);
|
/*v8::Local<v8::FunctionTemplate> m = v8::FunctionTemplate::New(New);
|
||||||
m->SetClassName(v8::String::NewSymbol("Contours"));
|
m->SetClassName(v8::String::NewSymbol("Contours"));
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
constructor = Persistent<FunctionTemplate>::New(m);
|
constructor = Persistent<FunctionTemplate>::New(m);
|
||||||
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
constructor->SetClassName(String::NewSymbol("Contours"));
|
constructor->SetClassName(String::NewSymbol("Contours"));*/
|
||||||
|
|
||||||
|
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Contour::New);
|
||||||
|
NanAssignPersistent(constructor, ctor);
|
||||||
|
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
|
ctor->SetClassName(NanNew("Contours"));
|
||||||
|
|
||||||
|
|
||||||
// Prototype
|
// Prototype
|
||||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||||
|
|
||||||
|
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "point", Point);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "point", Point);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "size", Size);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "size", Size);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "cornerCount", CornerCount);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "cornerCount", CornerCount);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "area", Area);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "area", Area);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "arcLength", ArcLength);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "arcLength", ArcLength);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "approxPolyDP", ApproxPolyDP);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "approxPolyDP", ApproxPolyDP);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "convexHull", ConvexHull);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "convexHull", ConvexHull);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "boundingRect", BoundingRect);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "boundingRect", BoundingRect);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "minAreaRect", MinAreaRect);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "minAreaRect", MinAreaRect);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "isConvex", IsConvex);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "isConvex", IsConvex);
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "moments", Moments);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "moments", Moments);
|
||||||
target->Set(String::NewSymbol("Contours"), m->GetFunction());
|
//target->Set(String::NewSymbol("Contours"), m->GetFunction());
|
||||||
|
|
||||||
|
target->Set(NanNew("Contours"), ctor->GetFunction());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(Contour::New() {
|
NAN_METHOD(Contour::New) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
if (args.This()->InternalFieldCount() == 0)
|
if (args.This()->InternalFieldCount() == 0)
|
||||||
return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Cannot instantiate without new")));
|
NanThrowTypeError("Cannot instantiate without new");
|
||||||
|
|
||||||
Contour *contours;
|
Contour *contours;
|
||||||
contours = new Contour;
|
contours = new Contour;
|
||||||
|
|
||||||
contours->Wrap(args.Holder());
|
contours->Wrap(args.Holder());
|
||||||
return scope.Close(args.Holder());
|
NanReturnValue(args.Holder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Contour::Contour(): ObjectWrap() {
|
Contour::Contour(): ObjectWrap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAN_METHOD(Contour::Point) {
|
||||||
NAN_METHOD(Contour::Point() {
|
NanScope();
|
||||||
HandleScope scope;
|
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -72,19 +80,20 @@ NAN_METHOD(Contour::Point() {
|
|||||||
return scope.Close(data);
|
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.
|
||||||
NAN_METHOD(Contour::Size() {
|
NAN_METHOD(Contour::Size) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
|
|
||||||
return scope.Close(Number::New(self->contours.size()));
|
return scope.Close(Number::New(self->contours.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
NAN_METHOD(Contour::CornerCount() {
|
NAN_METHOD(Contour::CornerCount) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -92,8 +101,8 @@ NAN_METHOD(Contour::CornerCount() {
|
|||||||
return scope.Close(Number::New(self->contours[pos].size()));
|
return scope.Close(Number::New(self->contours[pos].size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
NAN_METHOD(Contour::Area() {
|
NAN_METHOD(Contour::Area) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -103,8 +112,8 @@ NAN_METHOD(Contour::Area() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(Contour::ArcLength() {
|
NAN_METHOD(Contour::ArcLength) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -114,8 +123,8 @@ NAN_METHOD(Contour::ArcLength() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(Contour::ApproxPolyDP() {
|
NAN_METHOD(Contour::ApproxPolyDP) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -130,8 +139,8 @@ NAN_METHOD(Contour::ApproxPolyDP() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(Contour::ConvexHull() {
|
NAN_METHOD(Contour::ConvexHull) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
|
|
||||||
@ -146,8 +155,8 @@ NAN_METHOD(Contour::ConvexHull() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(Contour::BoundingRect() {
|
NAN_METHOD(Contour::BoundingRect) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -164,8 +173,8 @@ NAN_METHOD(Contour::BoundingRect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(Contour::MinAreaRect() {
|
NAN_METHOD(Contour::MinAreaRect) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -202,8 +211,8 @@ NAN_METHOD(Contour::MinAreaRect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(Contour::IsConvex() {
|
NAN_METHOD(Contour::IsConvex) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -211,8 +220,8 @@ NAN_METHOD(Contour::IsConvex() {
|
|||||||
return scope.Close(Boolean::New(isContourConvex(cv::Mat(self->contours[pos]))));
|
return scope.Close(Boolean::New(isContourConvex(cv::Mat(self->contours[pos]))));
|
||||||
}
|
}
|
||||||
|
|
||||||
NAN_METHOD(Contour::Moments() {
|
NAN_METHOD(Contour::Moments) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||||
int pos = args[0]->NumberValue();
|
int pos = args[0]->NumberValue();
|
||||||
@ -229,4 +238,4 @@ NAN_METHOD(Contour::Moments() {
|
|||||||
|
|
||||||
return scope.Close(res);
|
return scope.Close(res);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|||||||
1274
src/Matrix.cc
1274
src/Matrix.cc
File diff suppressed because it is too large
Load Diff
@ -1,30 +1,29 @@
|
|||||||
#include "OpenCV.h"
|
#include "OpenCV.h"
|
||||||
#include "Matrix.h"
|
#include "Matrix.h"
|
||||||
|
#include <nan.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
OpenCV::Init(Handle<Object> target) {
|
OpenCV::Init(Handle<Object> target) {
|
||||||
HandleScope scope;
|
NanScope();
|
||||||
|
|
||||||
|
|
||||||
// Version string.
|
// Version string.
|
||||||
char out [21];
|
char out [21];
|
||||||
int n = sprintf(out, "%i.%i", CV_MAJOR_VERSION, CV_MINOR_VERSION);
|
int n = sprintf(out, "%i.%i", CV_MAJOR_VERSION, CV_MINOR_VERSION);
|
||||||
target->Set(String::NewSymbol("version"), String::New(out, n));
|
target->Set(NanNew<String>("version"), NanNew<String>(out, n));
|
||||||
|
|
||||||
NODE_SET_METHOD(target, "readImage", ReadImage);
|
NODE_SET_METHOD(target, "readImage", ReadImage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NAN_METHOD(OpenCV::ReadImage) {
|
||||||
Handle<Value>
|
NanEscapableScope();
|
||||||
OpenCV::ReadImage() {
|
|
||||||
HandleScope scope;
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
Local<Object> im_h = Matrix::constructor->GetFunction()->NewInstance();
|
Local<Object> im_h = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
|
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
|
||||||
|
|
||||||
cv::Mat mat;
|
cv::Mat mat;
|
||||||
|
|
||||||
REQ_FUN_ARG(1, cb);
|
REQ_FUN_ARG(1, cb);
|
||||||
@ -38,7 +37,7 @@ OpenCV::ReadImage() {
|
|||||||
|
|
||||||
} else if (args[0]->IsString()) {
|
} else if (args[0]->IsString()) {
|
||||||
|
|
||||||
std::string filename = std::string(*v8::String::AsciiValue(args[0]->ToString()));
|
std::string filename = std::string(*NanAsciiString(args[0]->ToString()));
|
||||||
mat = cv::imread(filename);
|
mat = cv::imread(filename);
|
||||||
|
|
||||||
} else if (Buffer::HasInstance(args[0])){
|
} else if (Buffer::HasInstance(args[0])){
|
||||||
@ -49,7 +48,7 @@ OpenCV::ReadImage() {
|
|||||||
mat = cv::imdecode(*mbuf, -1);
|
mat = cv::imdecode(*mbuf, -1);
|
||||||
|
|
||||||
if (mat.empty()){
|
if (mat.empty()){
|
||||||
return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Error loading file")));
|
NanThrowTypeError("Error loading file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,23 +56,21 @@ OpenCV::ReadImage() {
|
|||||||
|
|
||||||
Local<Value> argv[2];
|
Local<Value> argv[2];
|
||||||
|
|
||||||
argv[0] = Local<Value>::New(Null());
|
argv[0] = NanNull();
|
||||||
argv[1] = im_h;
|
argv[1] = im_h;
|
||||||
|
|
||||||
TryCatch try_catch;
|
TryCatch try_catch;
|
||||||
|
|
||||||
cb->Call(Context::GetCurrent()->Global(), 2, argv);
|
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
|
||||||
|
|
||||||
if (try_catch.HasCaught()) {
|
if (try_catch.HasCaught()) {
|
||||||
FatalException(try_catch);
|
FatalException(try_catch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Undefined();
|
NanReturnUndefined();
|
||||||
|
|
||||||
} catch( cv::Exception& e ){
|
} catch( cv::Exception& e ){
|
||||||
const char* err_msg = e.what();
|
const char* err_msg = e.what();
|
||||||
return v8::ThrowException(v8::Exception::Error(v8::String::New(err_msg)));
|
NanThrowError(err_msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
10
src/OpenCV.h
10
src/OpenCV.h
@ -16,8 +16,7 @@ using namespace node;
|
|||||||
|
|
||||||
#define REQ_FUN_ARG(I, VAR) \
|
#define REQ_FUN_ARG(I, VAR) \
|
||||||
if (args.Length() <= (I) || !args[I]->IsFunction()) \
|
if (args.Length() <= (I) || !args[I]->IsFunction()) \
|
||||||
return v8::ThrowException(v8::Exception::TypeError( \
|
return NanThrowTypeError("Argument " #I " must be a function"); \
|
||||||
String::New("Argument " #I " must be a function"))); \
|
|
||||||
Local<Function> VAR = Local<Function>::Cast(args[I]);
|
Local<Function> VAR = Local<Function>::Cast(args[I]);
|
||||||
|
|
||||||
|
|
||||||
@ -27,13 +26,13 @@ using namespace node;
|
|||||||
|
|
||||||
#define JSFUNC(NAME) \
|
#define JSFUNC(NAME) \
|
||||||
static NAN_METHOD(NAME);
|
static NAN_METHOD(NAME);
|
||||||
//static Handle<Value> NAME(const Arguments& args);
|
|
||||||
|
|
||||||
#define JSTHROW_TYPE(ERR) \
|
#define JSTHROW_TYPE(ERR) \
|
||||||
return v8::ThrowException(v8::Exception::TypeError(v8::String::New(ERR)));
|
NanThrowTypeError( ERR );
|
||||||
|
|
||||||
|
|
||||||
#define JSTHROW(ERR) \
|
#define JSTHROW(ERR) \
|
||||||
return v8::ThrowException(v8::Exception::Error(v8::String::New(ERR)));
|
NanThrowError( ERR );
|
||||||
|
|
||||||
|
|
||||||
#define INT_FROM_ARGS(NAME, IND) \
|
#define INT_FROM_ARGS(NAME, IND) \
|
||||||
@ -51,7 +50,6 @@ class OpenCV: public node::ObjectWrap{
|
|||||||
static void Init(Handle<Object> target);
|
static void Init(Handle<Object> target);
|
||||||
|
|
||||||
static NAN_METHOD(ReadImage);
|
static NAN_METHOD(ReadImage);
|
||||||
//static Handle<Value> ReadImage(const v8::Arguments&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
#include "OpenCV.h"
|
#include "OpenCV.h"
|
||||||
#include "Point.h"
|
/*#include "Point.h"
|
||||||
#include "Matrix.h"
|
#include "Matrix.h"
|
||||||
#include "CascadeClassifierWrap.h"
|
#include "CascadeClassifierWrap.h"
|
||||||
#include "VideoCaptureWrap.h"
|
#include "VideoCaptureWrap.h"
|
||||||
#include "Contours.h"
|
#include "Contours.h"
|
||||||
#include "CamShift.h"
|
#include "CamShift.h"
|
||||||
#include "HighGUI.h"
|
#include "HighGUI.h"
|
||||||
#include "FaceRecognizer.h"
|
#include "FaceRecognizer.h"*/
|
||||||
|
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
@ -14,7 +14,7 @@ init(Handle<Object> target) {
|
|||||||
//HandleScope scope;
|
//HandleScope scope;
|
||||||
NanScope();
|
NanScope();
|
||||||
OpenCV::Init(target);
|
OpenCV::Init(target);
|
||||||
Point::Init(target);
|
/*Point::Init(target);
|
||||||
Matrix::Init(target);
|
Matrix::Init(target);
|
||||||
CascadeClassifierWrap::Init(target);
|
CascadeClassifierWrap::Init(target);
|
||||||
VideoCaptureWrap::Init(target);
|
VideoCaptureWrap::Init(target);
|
||||||
@ -24,7 +24,7 @@ init(Handle<Object> target) {
|
|||||||
|
|
||||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||||
FaceRecognizerWrap::Init(target);
|
FaceRecognizerWrap::Init(target);
|
||||||
#endif
|
#endif*/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user