mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Revert "conversion + build + test passed... so far"
This reverts commit ea69fcc10b73a191e1d3dc6c9decdc1ebc8bc714.
This commit is contained in:
parent
ad99fa17f2
commit
1974fd6d00
@ -5,60 +5,60 @@
|
||||
|
||||
#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
Nan::Persistent<FunctionTemplate> BackgroundSubtractorWrap::constructor;
|
||||
Persistent<FunctionTemplate> BackgroundSubtractorWrap::constructor;
|
||||
|
||||
void BackgroundSubtractorWrap::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(BackgroundSubtractorWrap::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(BackgroundSubtractorWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("BackgroundSubtractor").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("BackgroundSubtractor"));
|
||||
|
||||
Nan::SetMethod(ctor, "createMOG", CreateMOG);
|
||||
Nan::SetPrototypeMethod(ctor, "applyMOG", ApplyMOG);
|
||||
NODE_SET_METHOD(ctor, "createMOG", CreateMOG);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "applyMOG", ApplyMOG);
|
||||
|
||||
target->Set(Nan::New("BackgroundSubtractor").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("BackgroundSubtractor"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(BackgroundSubtractorWrap::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||
}
|
||||
|
||||
// Create MOG by default
|
||||
cv::Ptr<cv::BackgroundSubtractor> bg;
|
||||
BackgroundSubtractorWrap *pt = new BackgroundSubtractorWrap(bg);
|
||||
pt->Wrap(info.This());
|
||||
pt->Wrap(args.This());
|
||||
|
||||
info.GetReturnValue().Set(info.This());
|
||||
NanReturnValue(args.This());
|
||||
}
|
||||
|
||||
NAN_METHOD(BackgroundSubtractorWrap::CreateMOG) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
// int history = 200;
|
||||
// int nmixtures = 5;
|
||||
// double backgroundRatio = 0.7;
|
||||
// double noiseSigma = 0;
|
||||
//
|
||||
// if(info.Length() > 1){
|
||||
// if(args.Length() > 1){
|
||||
// INT_FROM_ARGS(history, 0)
|
||||
// INT_FROM_ARGS(nmixtures, 1)
|
||||
// DOUBLE_FROM_ARGS(backgroundRatio, 2)
|
||||
// DOUBLE_FROM_ARGS(noiseSigma, 3)
|
||||
// }
|
||||
|
||||
Local<Object> n = Nan::New(BackgroundSubtractorWrap::constructor)->GetFunction()->NewInstance();
|
||||
Local<Object> n = NanNew(BackgroundSubtractorWrap::constructor)->GetFunction()->NewInstance();
|
||||
|
||||
cv::Ptr<cv::BackgroundSubtractor> bg;
|
||||
BackgroundSubtractorWrap *pt = new BackgroundSubtractorWrap(bg);
|
||||
|
||||
pt->Wrap(n);
|
||||
info.GetReturnValue().Set( n );
|
||||
NanReturnValue( n );
|
||||
}
|
||||
|
||||
// Fetch foreground mask
|
||||
@ -67,32 +67,32 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
|
||||
REQ_FUN_ARG(1, cb);
|
||||
|
||||
Local<Value> argv[2];
|
||||
if (info.Length() == 0) {
|
||||
argv[0] = Nan::New("Input image missing").ToLocalChecked();
|
||||
argv[1] = Nan::Null();
|
||||
cb->Call(Nan::GetCurrentContext()->Global(), 2, argv);
|
||||
return;
|
||||
if (args.Length() == 0) {
|
||||
argv[0] = NanNew("Input image missing");
|
||||
argv[1] = NanNull();
|
||||
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
try {
|
||||
Local<Object> fgMask =
|
||||
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(fgMask);
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(fgMask);
|
||||
|
||||
cv::Mat mat;
|
||||
if (Buffer::HasInstance(info[0])) {
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(info[0]->ToObject());
|
||||
unsigned len = Buffer::Length(info[0]->ToObject());
|
||||
if (Buffer::HasInstance(args[0])) {
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
|
||||
unsigned len = Buffer::Length(args[0]->ToObject());
|
||||
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
|
||||
mat = cv::imdecode(*mbuf, -1);
|
||||
//mbuf->release();
|
||||
} else {
|
||||
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix *_img = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
mat = (_img->mat).clone();
|
||||
}
|
||||
|
||||
if (mat.empty()) {
|
||||
return Nan::ThrowTypeError("Error loading file");
|
||||
return NanThrowTypeError("Error loading file");
|
||||
}
|
||||
|
||||
cv::Mat _fgMask;
|
||||
@ -101,20 +101,20 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
|
||||
img->mat = _fgMask;
|
||||
mat.release();
|
||||
|
||||
argv[0] = Nan::Null();
|
||||
argv[0] = NanNull();
|
||||
argv[1] = fgMask;
|
||||
|
||||
TryCatch try_catch;
|
||||
cb->Call(Nan::GetCurrentContext()->Global(), 2, argv);
|
||||
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
FatalException(try_catch);
|
||||
}
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
} catch (cv::Exception& e) {
|
||||
const char* err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,11 +4,11 @@
|
||||
|
||||
#include <opencv2/video/background_segm.hpp>
|
||||
|
||||
class BackgroundSubtractorWrap: public Nan::ObjectWrap {
|
||||
class BackgroundSubtractorWrap: public node::ObjectWrap {
|
||||
public:
|
||||
cv::Ptr<cv::BackgroundSubtractor> subtractor;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
|
||||
264
src/Calib3D.cc
264
src/Calib3D.cc
@ -3,15 +3,15 @@
|
||||
|
||||
inline Local<Object> matrixFromMat(cv::Mat &input) {
|
||||
Local<Object> matrixWrap =
|
||||
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *matrix = Nan::ObjectWrap::Unwrap<Matrix>(matrixWrap);
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *matrix = ObjectWrap::Unwrap<Matrix>(matrixWrap);
|
||||
matrix->mat = input;
|
||||
|
||||
return matrixWrap;
|
||||
}
|
||||
|
||||
inline cv::Mat matFromMatrix(Handle<Value> matrix) {
|
||||
Matrix* m = Nan::ObjectWrap::Unwrap<Matrix>(matrix->ToObject());
|
||||
Matrix* m = ObjectWrap::Unwrap<Matrix>(matrix->ToObject());
|
||||
return m->mat;
|
||||
}
|
||||
|
||||
@ -38,8 +38,8 @@ inline std::vector<cv::Point2f> points2fFromArray(Handle<Value> array) {
|
||||
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
|
||||
Local<Object> pt = pointsArray->Get(i)->ToObject();
|
||||
points.push_back(
|
||||
cv::Point2f(pt->Get(Nan::New<String>("x").ToLocalChecked())->ToNumber()->Value(),
|
||||
pt->Get(Nan::New<String>("y").ToLocalChecked())->ToNumber()->Value()));
|
||||
cv::Point2f(pt->Get(NanNew<String>("x"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("y"))->ToNumber()->Value()));
|
||||
}
|
||||
} else {
|
||||
JSTHROW_TYPE("Points not a valid array");
|
||||
@ -56,9 +56,9 @@ inline std::vector<cv::Point3f> points3fFromArray(Handle<Value> array) {
|
||||
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
|
||||
Local<Object> pt = pointsArray->Get(i)->ToObject();
|
||||
points.push_back(
|
||||
cv::Point3f(pt->Get(Nan::New<String>("x").ToLocalChecked())->ToNumber()->Value(),
|
||||
pt->Get(Nan::New<String>("y").ToLocalChecked())->ToNumber()->Value(),
|
||||
pt->Get(Nan::New<String>("z").ToLocalChecked())->ToNumber()->Value()));
|
||||
cv::Point3f(pt->Get(NanNew<String>("x"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("y"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("z"))->ToNumber()->Value()));
|
||||
}
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass array of object points for each frame")
|
||||
@ -100,35 +100,35 @@ inline std::vector<std::vector<cv::Point3f> > points3fFromArrayOfArrays(
|
||||
}
|
||||
|
||||
void Calib3D::Init(Handle<Object> target) {
|
||||
Nan::Persistent<Object> inner;
|
||||
Local<Object> obj = Nan::New<Object>();
|
||||
inner.Reset(obj);
|
||||
Persistent<Object> inner;
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
NanAssignPersistent(inner, obj);
|
||||
|
||||
Nan::SetMethod(obj, "findChessboardCorners", FindChessboardCorners);
|
||||
Nan::SetMethod(obj, "drawChessboardCorners", DrawChessboardCorners);
|
||||
Nan::SetMethod(obj, "calibrateCamera", CalibrateCamera);
|
||||
Nan::SetMethod(obj, "solvePnP", SolvePnP);
|
||||
Nan::SetMethod(obj, "getOptimalNewCameraMatrix", GetOptimalNewCameraMatrix);
|
||||
Nan::SetMethod(obj, "stereoCalibrate", StereoCalibrate);
|
||||
Nan::SetMethod(obj, "stereoRectify", StereoRectify);
|
||||
Nan::SetMethod(obj, "computeCorrespondEpilines", ComputeCorrespondEpilines);
|
||||
Nan::SetMethod(obj, "reprojectImageTo3d", ReprojectImageTo3D);
|
||||
NODE_SET_METHOD(obj, "findChessboardCorners", FindChessboardCorners);
|
||||
NODE_SET_METHOD(obj, "drawChessboardCorners", DrawChessboardCorners);
|
||||
NODE_SET_METHOD(obj, "calibrateCamera", CalibrateCamera);
|
||||
NODE_SET_METHOD(obj, "solvePnP", SolvePnP);
|
||||
NODE_SET_METHOD(obj, "getOptimalNewCameraMatrix", GetOptimalNewCameraMatrix);
|
||||
NODE_SET_METHOD(obj, "stereoCalibrate", StereoCalibrate);
|
||||
NODE_SET_METHOD(obj, "stereoRectify", StereoRectify);
|
||||
NODE_SET_METHOD(obj, "computeCorrespondEpilines", ComputeCorrespondEpilines);
|
||||
NODE_SET_METHOD(obj, "reprojectImageTo3d", ReprojectImageTo3D);
|
||||
|
||||
target->Set(Nan::New("calib3d").ToLocalChecked(), obj);
|
||||
target->Set(NanNew("calib3d"), obj);
|
||||
}
|
||||
|
||||
// cv::findChessboardCorners
|
||||
NAN_METHOD(Calib3D::FindChessboardCorners) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments from javascript
|
||||
|
||||
// Arg 0 is the image
|
||||
cv::Mat mat = matFromMatrix(info[0]);
|
||||
cv::Mat mat = matFromMatrix(args[0]);
|
||||
|
||||
// Arg 1 is the pattern size
|
||||
cv::Size patternSize = sizeFromArray(info[1]);
|
||||
cv::Size patternSize = sizeFromArray(args[1]);
|
||||
|
||||
// Arg 2 would normally be the flags, ignoring this for now and using the
|
||||
// default flags
|
||||
@ -138,77 +138,77 @@ NAN_METHOD(Calib3D::FindChessboardCorners) {
|
||||
bool found = cv::findChessboardCorners(mat, patternSize, corners);
|
||||
|
||||
// Make the return value
|
||||
Local<Object> ret = Nan::New<Object>();
|
||||
ret->Set(Nan::New<String>("found").ToLocalChecked(), Nan::New<Boolean>(found));
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
ret->Set(NanNew<String>("found"), NanNew<Boolean>(found));
|
||||
|
||||
Local<Array> cornersArray = Nan::New<Array>(corners.size());
|
||||
Local<Array> cornersArray = NanNew<Array>(corners.size());
|
||||
for (unsigned int i = 0; i < corners.size(); i++) {
|
||||
Local<Object> point_data = Nan::New<Object>();
|
||||
point_data->Set(Nan::New<String>("x").ToLocalChecked(), Nan::New<Number>(corners[i].x));
|
||||
point_data->Set(Nan::New<String>("y").ToLocalChecked(), Nan::New<Number>(corners[i].y));
|
||||
Local<Object> point_data = NanNew<Object>();
|
||||
point_data->Set(NanNew<String>("x"), NanNew<Number>(corners[i].x));
|
||||
point_data->Set(NanNew<String>("y"), NanNew<Number>(corners[i].y));
|
||||
|
||||
cornersArray->Set(Nan::New<Number>(i), point_data);
|
||||
cornersArray->Set(NanNew<Number>(i), point_data);
|
||||
}
|
||||
|
||||
ret->Set(Nan::New<String>("corners").ToLocalChecked(), cornersArray);
|
||||
ret->Set(NanNew<String>("corners"), cornersArray);
|
||||
|
||||
info.GetReturnValue().Set(ret);
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::drawChessboardCorners
|
||||
NAN_METHOD(Calib3D::DrawChessboardCorners) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the image
|
||||
cv::Mat mat = matFromMatrix(info[0]);
|
||||
cv::Mat mat = matFromMatrix(args[0]);
|
||||
|
||||
// Arg 1 is the pattern size
|
||||
cv::Size patternSize = sizeFromArray(info[1]);
|
||||
cv::Size patternSize = sizeFromArray(args[1]);
|
||||
|
||||
// Arg 2 is the corners array
|
||||
std::vector<cv::Point2f> corners = points2fFromArray(info[2]);
|
||||
std::vector<cv::Point2f> corners = points2fFromArray(args[2]);
|
||||
|
||||
// Arg 3, pattern found boolean
|
||||
bool patternWasFound = info[3]->ToBoolean()->Value();
|
||||
bool patternWasFound = args[3]->ToBoolean()->Value();
|
||||
|
||||
// Draw the corners
|
||||
cv::drawChessboardCorners(mat, patternSize, corners, patternWasFound);
|
||||
|
||||
// Return the passed image, now with corners drawn on it
|
||||
info.GetReturnValue().Set(info[0]);
|
||||
NanReturnValue(args[0]);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::calibrateCamera
|
||||
NAN_METHOD(Calib3D::CalibrateCamera) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the array of object points, an array of arrays
|
||||
std::vector<std::vector<cv::Point3f> > objectPoints =
|
||||
points3fFromArrayOfArrays(info[0]);
|
||||
points3fFromArrayOfArrays(args[0]);
|
||||
|
||||
// Arg 1, the image points, another array of arrays
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints =
|
||||
points2fFromArrayOfArrays(info[1]);
|
||||
points2fFromArrayOfArrays(args[1]);
|
||||
|
||||
// Arg 2, the image size
|
||||
cv::Size imageSize = sizeFromArray(info[2]);
|
||||
cv::Size imageSize = sizeFromArray(args[2]);
|
||||
|
||||
// Arg 3, 4, input guesses for the camrea matrix and distortion coefficients,
|
||||
// skipping for now
|
||||
@ -223,48 +223,48 @@ NAN_METHOD(Calib3D::CalibrateCamera) {
|
||||
dist, rvecs, tvecs);
|
||||
|
||||
// make the return values
|
||||
Local<Object> ret = Nan::New<Object>();
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
// Reprojection error
|
||||
ret->Set(Nan::New<String>("reprojectionError").ToLocalChecked(), Nan::New<Number>(error));
|
||||
ret->Set(NanNew<String>("reprojectionError"), NanNew<Number>(error));
|
||||
|
||||
// K
|
||||
Local<Object> KMatrixWrap = matrixFromMat(K);
|
||||
ret->Set(Nan::New<String>("K").ToLocalChecked(), KMatrixWrap);
|
||||
ret->Set(NanNew<String>("K"), KMatrixWrap);
|
||||
|
||||
// dist
|
||||
Local<Object> distMatrixWrap = matrixFromMat(dist);
|
||||
ret->Set(Nan::New<String>("distortion").ToLocalChecked(), distMatrixWrap);
|
||||
ret->Set(NanNew<String>("distortion"), distMatrixWrap);
|
||||
|
||||
// Per frame R and t, skiping for now
|
||||
|
||||
// Return
|
||||
info.GetReturnValue().Set(ret);
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::solvePnP
|
||||
NAN_METHOD(Calib3D::SolvePnP) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the array of object points
|
||||
std::vector<cv::Point3f> objectPoints = points3fFromArray(info[0]);
|
||||
std::vector<cv::Point3f> objectPoints = points3fFromArray(args[0]);
|
||||
|
||||
// Arg 1, the image points
|
||||
std::vector<cv::Point2f> imagePoints = points2fFromArray(info[1]);
|
||||
std::vector<cv::Point2f> imagePoints = points2fFromArray(args[1]);
|
||||
|
||||
// Arg 2, the camera matrix
|
||||
cv::Mat K = matFromMatrix(info[2]);
|
||||
cv::Mat K = matFromMatrix(args[2]);
|
||||
|
||||
// Arg 3, the distortion coefficients
|
||||
cv::Mat dist = matFromMatrix(info[3]);
|
||||
cv::Mat dist = matFromMatrix(args[3]);
|
||||
|
||||
// Arg 4, use extrinsic guess, skipped for now
|
||||
|
||||
@ -276,47 +276,47 @@ NAN_METHOD(Calib3D::SolvePnP) {
|
||||
cv::solvePnP(objectPoints, imagePoints, K, dist, rvec, tvec);
|
||||
|
||||
// make the return values
|
||||
Local<Object> ret = Nan::New<Object>();
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
// rvec
|
||||
Local<Object> rMatrixWrap = matrixFromMat(rvec);
|
||||
ret->Set(Nan::New<String>("rvec").ToLocalChecked(), rMatrixWrap);
|
||||
ret->Set(NanNew<String>("rvec"), rMatrixWrap);
|
||||
|
||||
// tvec
|
||||
Local<Object> tMatrixWrap = matrixFromMat(tvec);
|
||||
ret->Set(Nan::New<String>("tvec").ToLocalChecked(), tMatrixWrap);
|
||||
ret->Set(NanNew<String>("tvec"), tMatrixWrap);
|
||||
|
||||
// Return
|
||||
info.GetReturnValue().Set(ret);
|
||||
NanReturnValue(ret);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::getOptimalNewCameraMAtrix
|
||||
NAN_METHOD(Calib3D::GetOptimalNewCameraMatrix) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the original camera matrix
|
||||
cv::Mat Kin = matFromMatrix(info[0]);
|
||||
cv::Mat Kin = matFromMatrix(args[0]);
|
||||
|
||||
// Arg 1 is the distortion coefficients
|
||||
cv::Mat dist = matFromMatrix(info[1]);
|
||||
cv::Mat dist = matFromMatrix(args[1]);
|
||||
|
||||
// Arg 2, the image size
|
||||
cv::Size imageSize = sizeFromArray(info[2]);
|
||||
cv::Size imageSize = sizeFromArray(args[2]);
|
||||
|
||||
// Arg 3 is the alpha free scaling parameter
|
||||
double alpha = info[3]->ToNumber()->Value();
|
||||
double alpha = args[3]->ToNumber()->Value();
|
||||
|
||||
// Arg 4, the new image size
|
||||
cv::Size newImageSize = sizeFromArray(info[4]);
|
||||
cv::Size newImageSize = sizeFromArray(args[4]);
|
||||
|
||||
// Arg 5, valid ROI, skip for now
|
||||
// Arg 6, center principal point, skip for now
|
||||
@ -329,46 +329,46 @@ NAN_METHOD(Calib3D::GetOptimalNewCameraMatrix) {
|
||||
Local<Object> KMatrixWrap = matrixFromMat(Kout);
|
||||
|
||||
// Return the new K matrix
|
||||
info.GetReturnValue().Set(KMatrixWrap);
|
||||
NanReturnValue(KMatrixWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::stereoCalibrate
|
||||
NAN_METHOD(Calib3D::StereoCalibrate) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the array of object points, an array of arrays
|
||||
std::vector<std::vector<cv::Point3f> > objectPoints =
|
||||
points3fFromArrayOfArrays(info[0]);
|
||||
points3fFromArrayOfArrays(args[0]);
|
||||
|
||||
// Arg 1, the image points1, another array of arrays
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints1 =
|
||||
points2fFromArrayOfArrays(info[1]);
|
||||
points2fFromArrayOfArrays(args[1]);
|
||||
|
||||
// Arg 2, the image points2, another array of arrays =(
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints2 =
|
||||
points2fFromArrayOfArrays(info[2]);
|
||||
points2fFromArrayOfArrays(args[2]);
|
||||
|
||||
// Arg 3 is the image size (follows the PYTHON api not the C++ api since all
|
||||
// following arguments are optional or outputs)
|
||||
cv::Size imageSize = sizeFromArray(info[3]);
|
||||
cv::Size imageSize = sizeFromArray(args[3]);
|
||||
|
||||
// Arg 4,5,6,7 is the camera matrix and distortion coefficients
|
||||
// (optional but must pass all 4 or none)
|
||||
cv::Mat k1, d1, k2, d2;
|
||||
if (info.Length() >= 8) {
|
||||
k1 = matFromMatrix(info[4]);
|
||||
d1 = matFromMatrix(info[5]);
|
||||
if (args.Length() >= 8) {
|
||||
k1 = matFromMatrix(args[4]);
|
||||
d1 = matFromMatrix(args[5]);
|
||||
|
||||
k2 = matFromMatrix(info[6]);
|
||||
d2 = matFromMatrix(info[7]);
|
||||
k2 = matFromMatrix(args[6]);
|
||||
d2 = matFromMatrix(args[7]);
|
||||
}
|
||||
|
||||
// Last argument is flags, skipping for now
|
||||
@ -381,7 +381,7 @@ NAN_METHOD(Calib3D::StereoCalibrate) {
|
||||
d2, imageSize, R, t, E, F);
|
||||
|
||||
// make the return value
|
||||
Local<Object> ret = Nan::New<Object>();
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
// Make the output arguments
|
||||
|
||||
@ -410,51 +410,51 @@ NAN_METHOD(Calib3D::StereoCalibrate) {
|
||||
Local<Object> FMatrixWrap = matrixFromMat(F);
|
||||
|
||||
// Add to return object
|
||||
ret->Set(Nan::New<String>("K1").ToLocalChecked(), K1MatrixWrap);
|
||||
ret->Set(Nan::New<String>("distortion1").ToLocalChecked(), d1MatrixWrap);
|
||||
ret->Set(Nan::New<String>("K2").ToLocalChecked(), K2MatrixWrap);
|
||||
ret->Set(Nan::New<String>("distortion2").ToLocalChecked(), d2MatrixWrap);
|
||||
ret->Set(Nan::New<String>("R").ToLocalChecked(), RMatrixWrap);
|
||||
ret->Set(Nan::New<String>("t").ToLocalChecked(), tMatrixWrap);
|
||||
ret->Set(Nan::New<String>("E").ToLocalChecked(), EMatrixWrap);
|
||||
ret->Set(Nan::New<String>("F").ToLocalChecked(), FMatrixWrap);
|
||||
ret->Set(NanNew<String>("K1"), K1MatrixWrap);
|
||||
ret->Set(NanNew<String>("distortion1"), d1MatrixWrap);
|
||||
ret->Set(NanNew<String>("K2"), K2MatrixWrap);
|
||||
ret->Set(NanNew<String>("distortion2"), d2MatrixWrap);
|
||||
ret->Set(NanNew<String>("R"), RMatrixWrap);
|
||||
ret->Set(NanNew<String>("t"), tMatrixWrap);
|
||||
ret->Set(NanNew<String>("E"), EMatrixWrap);
|
||||
ret->Set(NanNew<String>("F"), FMatrixWrap);
|
||||
|
||||
// Return
|
||||
info.GetReturnValue().Set(ret);
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::stereoRectify
|
||||
NAN_METHOD(Calib3D::StereoRectify) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg0, the first camera matrix
|
||||
cv::Mat K1 = matFromMatrix(info[0]);
|
||||
cv::Mat K1 = matFromMatrix(args[0]);
|
||||
|
||||
// Arg1, the first distortion coefficients
|
||||
cv::Mat d1 = matFromMatrix(info[1]);
|
||||
cv::Mat d1 = matFromMatrix(args[1]);
|
||||
|
||||
// Arg2, the second camera matrix
|
||||
cv::Mat K2 = matFromMatrix(info[2]);
|
||||
cv::Mat K2 = matFromMatrix(args[2]);
|
||||
|
||||
// Arg3, the second distortion coefficients
|
||||
cv::Mat d2 = matFromMatrix(info[3]);
|
||||
cv::Mat d2 = matFromMatrix(args[3]);
|
||||
|
||||
// Arg4, the image size
|
||||
cv::Size imageSize = sizeFromArray(info[4]);
|
||||
cv::Size imageSize = sizeFromArray(args[4]);
|
||||
|
||||
// arg5, the intercamera rotation matrix
|
||||
cv::Mat R = matFromMatrix(info[5]);
|
||||
cv::Mat R = matFromMatrix(args[5]);
|
||||
|
||||
// Arg6, the intercamera translation vector
|
||||
cv::Mat t = matFromMatrix(info[6]);
|
||||
cv::Mat t = matFromMatrix(args[6]);
|
||||
|
||||
// Arg8, flags, skipping for now
|
||||
|
||||
@ -469,76 +469,76 @@ NAN_METHOD(Calib3D::StereoRectify) {
|
||||
cv::stereoRectify(K1, d1, K2, d2, imageSize, R, t, R1, R2, P1, P2, Q);
|
||||
|
||||
// Make the return object
|
||||
Local<Object> ret = Nan::New<Object>();
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
ret->Set(Nan::New<String>("R1").ToLocalChecked(), matrixFromMat(R1));
|
||||
ret->Set(Nan::New<String>("R2").ToLocalChecked(), matrixFromMat(R2));
|
||||
ret->Set(Nan::New<String>("P1").ToLocalChecked(), matrixFromMat(P1));
|
||||
ret->Set(Nan::New<String>("P2").ToLocalChecked(), matrixFromMat(P2));
|
||||
ret->Set(Nan::New<String>("Q").ToLocalChecked(), matrixFromMat(Q));
|
||||
ret->Set(NanNew<String>("R1"), matrixFromMat(R1));
|
||||
ret->Set(NanNew<String>("R2"), matrixFromMat(R2));
|
||||
ret->Set(NanNew<String>("P1"), matrixFromMat(P1));
|
||||
ret->Set(NanNew<String>("P2"), matrixFromMat(P2));
|
||||
ret->Set(NanNew<String>("Q"), matrixFromMat(Q));
|
||||
|
||||
// Return the rectification parameters
|
||||
info.GetReturnValue().Set(ret);
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::computeCorrespondEpilines
|
||||
NAN_METHOD(Calib3D::ComputeCorrespondEpilines) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg0, the image points
|
||||
std::vector<cv::Point2f> points = points2fFromArray(info[0]);
|
||||
std::vector<cv::Point2f> points = points2fFromArray(args[0]);
|
||||
|
||||
// Arg1, the image index (1 or 2)
|
||||
int whichImage = int(info[1]->ToNumber()->Value());
|
||||
int whichImage = int(args[1]->ToNumber()->Value());
|
||||
|
||||
// Arg2, the fundamental matrix
|
||||
cv::Mat F = matFromMatrix(info[2]);
|
||||
cv::Mat F = matFromMatrix(args[2]);
|
||||
|
||||
// compute the lines
|
||||
std::vector<cv::Vec3f> lines;
|
||||
cv::computeCorrespondEpilines(points, whichImage, F, lines);
|
||||
|
||||
// Convert the lines to an array of objects (ax + by + c = 0)
|
||||
Local<Array> linesArray = Nan::New<Array>(lines.size());
|
||||
Local<Array> linesArray = NanNew<Array>(lines.size());
|
||||
for(unsigned int i = 0; i < lines.size(); i++)
|
||||
{
|
||||
Local<Object> line_data = Nan::New<Object>();
|
||||
line_data->Set(Nan::New<String>("a").ToLocalChecked(), Nan::New<Number>(lines[i][0]));
|
||||
line_data->Set(Nan::New<String>("b").ToLocalChecked(), Nan::New<Number>(lines[i][1]));
|
||||
line_data->Set(Nan::New<String>("c").ToLocalChecked(), Nan::New<Number>(lines[i][2]));
|
||||
Local<Object> line_data = NanNew<Object>();
|
||||
line_data->Set(NanNew<String>("a"), NanNew<Number>(lines[i][0]));
|
||||
line_data->Set(NanNew<String>("b"), NanNew<Number>(lines[i][1]));
|
||||
line_data->Set(NanNew<String>("c"), NanNew<Number>(lines[i][2]));
|
||||
|
||||
linesArray->Set(Nan::New<Number>(i), line_data);
|
||||
linesArray->Set(NanNew<Number>(i), line_data);
|
||||
}
|
||||
|
||||
// Return the lines
|
||||
info.GetReturnValue().Set(linesArray);
|
||||
NanReturnValue(linesArray);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::reprojectImageTo3D
|
||||
NAN_METHOD(Calib3D::ReprojectImageTo3D) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg0, the disparity image
|
||||
cv::Mat disparity = matFromMatrix(info[0]);
|
||||
cv::Mat disparity = matFromMatrix(args[0]);
|
||||
|
||||
// Arg1, the depth-to-disparity transformation Q
|
||||
cv::Mat Q = matFromMatrix(info[1]);
|
||||
cv::Mat Q = matFromMatrix(args[1]);
|
||||
|
||||
// Arg 2, handle missing values, skipped for now
|
||||
|
||||
@ -551,10 +551,10 @@ NAN_METHOD(Calib3D::ReprojectImageTo3D) {
|
||||
// Wrap the depth image
|
||||
Local<Object> depthImageMatrix = matrixFromMat(depthImage);
|
||||
|
||||
info.GetReturnValue().Set(depthImageMatrix);
|
||||
NanReturnValue(depthImageMatrix);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/**
|
||||
* Implementation of calib3d.hpp functions
|
||||
*/
|
||||
class Calib3D: public Nan::ObjectWrap {
|
||||
class Calib3D: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(FindChessboardCorners);
|
||||
|
||||
@ -8,38 +8,38 @@
|
||||
#define CHANNEL_VALUE 2
|
||||
|
||||
|
||||
Nan::Persistent<FunctionTemplate> TrackedObject::constructor;
|
||||
Persistent<FunctionTemplate> TrackedObject::constructor;
|
||||
|
||||
void TrackedObject::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(TrackedObject::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(TrackedObject::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("TrackedObject").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("TrackedObject"));
|
||||
|
||||
// Prototype
|
||||
// Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "track", Track);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "track", Track);
|
||||
|
||||
target->Set(Nan::New("TrackedObject").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("TrackedObject"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(TrackedObject::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||
}
|
||||
|
||||
Matrix* m = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix* m = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Rect r;
|
||||
int channel = CHANNEL_HUE;
|
||||
|
||||
if (info[1]->IsArray()) {
|
||||
Local<Object> v8rec = info[1]->ToObject();
|
||||
if (args[1]->IsArray()) {
|
||||
Local<Object> v8rec = args[1]->ToObject();
|
||||
r = cv::Rect(
|
||||
v8rec->Get(0)->IntegerValue(),
|
||||
v8rec->Get(1)->IntegerValue(),
|
||||
@ -49,11 +49,11 @@ NAN_METHOD(TrackedObject::New) {
|
||||
JSTHROW_TYPE("Must pass rectangle to track")
|
||||
}
|
||||
|
||||
if (info[2]->IsObject()) {
|
||||
Local<Object> opts = info[2]->ToObject();
|
||||
if (args[2]->IsObject()) {
|
||||
Local<Object> opts = args[2]->ToObject();
|
||||
|
||||
if (opts->Get(Nan::New("channel").ToLocalChecked())->IsString()) {
|
||||
v8::String::Utf8Value c(opts->Get(Nan::New("channel").ToLocalChecked())->ToString());
|
||||
if (opts->Get(NanNew("channel"))->IsString()) {
|
||||
v8::String::Utf8Value c(opts->Get(NanNew("channel"))->ToString());
|
||||
std::string cc = std::string(*c);
|
||||
|
||||
if (cc == "hue" || cc == "h") {
|
||||
@ -72,8 +72,8 @@ NAN_METHOD(TrackedObject::New) {
|
||||
|
||||
TrackedObject *to = new TrackedObject(m->mat, r, channel);
|
||||
|
||||
to->Wrap(info.This());
|
||||
info.GetReturnValue().Set(info.This());
|
||||
to->Wrap(args.This());
|
||||
NanReturnValue(args.This());
|
||||
}
|
||||
|
||||
void update_chann_image(TrackedObject* t, cv::Mat image) {
|
||||
@ -117,17 +117,17 @@ TrackedObject::TrackedObject(cv::Mat image, cv::Rect rect, int chan) {
|
||||
NAN_METHOD(TrackedObject::Track) {
|
||||
SETUP_FUNCTION(TrackedObject)
|
||||
|
||||
if (info.Length() != 1) {
|
||||
Nan::ThrowTypeError("track takes an image param");
|
||||
return;
|
||||
if (args.Length() != 1) {
|
||||
NanThrowTypeError("track takes an image param");
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
Matrix *im = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::RotatedRect r;
|
||||
|
||||
if ((self->prev_rect.x < 0) || (self->prev_rect.y < 0)
|
||||
|| (self->prev_rect.width <= 1) || (self->prev_rect.height <= 1)) {
|
||||
return Nan::ThrowTypeError("OPENCV ERROR: prev rectangle is illogical");
|
||||
return NanThrowTypeError("OPENCV ERROR: prev rectangle is illogical");
|
||||
}
|
||||
|
||||
update_chann_image(self, im->mat);
|
||||
@ -155,21 +155,21 @@ NAN_METHOD(TrackedObject::Track) {
|
||||
self->prev_rect = backup_prev_rect;
|
||||
}
|
||||
|
||||
v8::Local<v8::Array> arr = Nan::New<Array>(4);
|
||||
v8::Local<v8::Array> arr = NanNew<Array>(4);
|
||||
|
||||
arr->Set(0, Nan::New<Number>(bounds.x));
|
||||
arr->Set(1, Nan::New<Number>(bounds.y));
|
||||
arr->Set(2, Nan::New<Number>(bounds.x + bounds.width));
|
||||
arr->Set(3, Nan::New<Number>(bounds.y + bounds.height));
|
||||
arr->Set(0, NanNew<Number>(bounds.x));
|
||||
arr->Set(1, NanNew<Number>(bounds.y));
|
||||
arr->Set(2, NanNew<Number>(bounds.x + bounds.width));
|
||||
arr->Set(3, NanNew<Number>(bounds.y + bounds.height));
|
||||
|
||||
/*
|
||||
cv::Point2f pts[4];
|
||||
r.points(pts);
|
||||
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
arr->Set(i, Nan::New<Number>(pts[i].x));
|
||||
arr->Set(i + 1, Nan::New<Number>(pts[i].y));
|
||||
arr->Set(i, NanNew<Number>(pts[i].x));
|
||||
arr->Set(i + 1, NanNew<Number>(pts[i].y));
|
||||
} */
|
||||
|
||||
info.GetReturnValue().Set(arr);
|
||||
NanReturnValue(arr);
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
|
||||
class TrackedObject: public Nan::ObjectWrap {
|
||||
class TrackedObject: public node::ObjectWrap {
|
||||
public:
|
||||
int channel;
|
||||
cv::Mat hsv;
|
||||
@ -12,7 +12,7 @@ public:
|
||||
cv::Mat hist;
|
||||
cv::Rect prev_rect;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
|
||||
82
src/CascadeClassifierWrap.cc
Normal file → Executable file
82
src/CascadeClassifierWrap.cc
Normal file → Executable file
@ -3,50 +3,50 @@
|
||||
#include "Matrix.h"
|
||||
#include <nan.h>
|
||||
|
||||
Nan::Persistent<FunctionTemplate> CascadeClassifierWrap::constructor;
|
||||
Persistent<FunctionTemplate> CascadeClassifierWrap::constructor;
|
||||
|
||||
void CascadeClassifierWrap::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate> (CascadeClassifierWrap::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate> (CascadeClassifierWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("CascadeClassifier").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("CascadeClassifier"));
|
||||
|
||||
// Prototype
|
||||
// Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "detectMultiScale", DetectMultiScale);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "detectMultiScale", DetectMultiScale);
|
||||
|
||||
target->Set(Nan::New("CascadeClassifier").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("CascadeClassifier"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(CascadeClassifierWrap::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
Nan::ThrowTypeError("Cannot instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
}
|
||||
|
||||
CascadeClassifierWrap *pt = new CascadeClassifierWrap(*info[0]);
|
||||
pt->Wrap(info.This());
|
||||
info.GetReturnValue().Set( info.This() );
|
||||
CascadeClassifierWrap *pt = new CascadeClassifierWrap(*args[0]);
|
||||
pt->Wrap(args.This());
|
||||
NanReturnValue( args.This() );
|
||||
}
|
||||
|
||||
CascadeClassifierWrap::CascadeClassifierWrap(v8::Value* fileName) {
|
||||
std::string filename;
|
||||
filename = std::string(*Nan::Utf8String(fileName->ToString()));
|
||||
filename = std::string(*NanAsciiString(fileName->ToString()));
|
||||
|
||||
if (!cc.load(filename.c_str())) {
|
||||
Nan::ThrowTypeError("Error loading file");
|
||||
NanThrowTypeError("Error loading file");
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncDetectMultiScale: public Nan::AsyncWorker {
|
||||
class AsyncDetectMultiScale: public NanAsyncWorker {
|
||||
public:
|
||||
AsyncDetectMultiScale(Nan::Callback *callback, CascadeClassifierWrap *cc,
|
||||
AsyncDetectMultiScale(NanCallback *callback, CascadeClassifierWrap *cc,
|
||||
Matrix* im, double scale, int neighbors, int minw, int minh) :
|
||||
Nan::AsyncWorker(callback),
|
||||
NanAsyncWorker(callback),
|
||||
cc(cc),
|
||||
im(im),
|
||||
scale(scale),
|
||||
@ -79,22 +79,22 @@ public:
|
||||
}
|
||||
|
||||
void HandleOKCallback() {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
// this->matrix->Unref();
|
||||
|
||||
Handle < Value > argv[2];
|
||||
v8::Local < v8::Array > arr = Nan::New < v8::Array > (this->res.size());
|
||||
v8::Local < v8::Array > arr = NanNew < v8::Array > (this->res.size());
|
||||
|
||||
for (unsigned int i = 0; i < this->res.size(); i++) {
|
||||
v8::Local < v8::Object > x = Nan::New<v8::Object>();
|
||||
x->Set(Nan::New("x").ToLocalChecked(), Nan::New < Number > (this->res[i].x));
|
||||
x->Set(Nan::New("y").ToLocalChecked(), Nan::New < Number > (this->res[i].y));
|
||||
x->Set(Nan::New("width").ToLocalChecked(), Nan::New < Number > (this->res[i].width));
|
||||
x->Set(Nan::New("height").ToLocalChecked(), Nan::New < Number > (this->res[i].height));
|
||||
v8::Local < v8::Object > x = NanNew<v8::Object>();
|
||||
x->Set(NanNew("x"), NanNew < Number > (this->res[i].x));
|
||||
x->Set(NanNew("y"), NanNew < Number > (this->res[i].y));
|
||||
x->Set(NanNew("width"), NanNew < Number > (this->res[i].width));
|
||||
x->Set(NanNew("height"), NanNew < Number > (this->res[i].height));
|
||||
arr->Set(i, x);
|
||||
}
|
||||
|
||||
argv[0] = Nan::Null();
|
||||
argv[0] = NanNull();
|
||||
argv[1] = arr;
|
||||
|
||||
TryCatch try_catch;
|
||||
@ -115,37 +115,37 @@ private:
|
||||
};
|
||||
|
||||
NAN_METHOD(CascadeClassifierWrap::DetectMultiScale) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
CascadeClassifierWrap *self = Nan::ObjectWrap::Unwrap<CascadeClassifierWrap> (info.This());
|
||||
CascadeClassifierWrap *self = ObjectWrap::Unwrap<CascadeClassifierWrap> (args.This());
|
||||
|
||||
if (info.Length() < 2) {
|
||||
Nan::ThrowTypeError("detectMultiScale takes at least 2 info");
|
||||
if (args.Length() < 2) {
|
||||
NanThrowTypeError("detectMultiScale takes at least 2 args");
|
||||
}
|
||||
|
||||
Matrix *im = Nan::ObjectWrap::Unwrap < Matrix > (info[0]->ToObject());
|
||||
Matrix *im = ObjectWrap::Unwrap < Matrix > (args[0]->ToObject());
|
||||
REQ_FUN_ARG(1, cb);
|
||||
|
||||
double scale = 1.1;
|
||||
if (info.Length() > 2 && info[2]->IsNumber()) {
|
||||
scale = info[2]->NumberValue();
|
||||
if (args.Length() > 2 && args[2]->IsNumber()) {
|
||||
scale = args[2]->NumberValue();
|
||||
}
|
||||
|
||||
int neighbors = 2;
|
||||
if (info.Length() > 3 && info[3]->IsInt32()) {
|
||||
neighbors = info[3]->IntegerValue();
|
||||
if (args.Length() > 3 && args[3]->IsInt32()) {
|
||||
neighbors = args[3]->IntegerValue();
|
||||
}
|
||||
|
||||
int minw = 30;
|
||||
int minh = 30;
|
||||
if (info.Length() > 5 && info[4]->IsInt32() && info[5]->IsInt32()) {
|
||||
minw = info[4]->IntegerValue();
|
||||
minh = info[5]->IntegerValue();
|
||||
if (args.Length() > 5 && args[4]->IsInt32() && args[5]->IsInt32()) {
|
||||
minw = args[4]->IntegerValue();
|
||||
minh = args[5]->IntegerValue();
|
||||
}
|
||||
|
||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||
|
||||
Nan::AsyncQueueWorker( new AsyncDetectMultiScale(callback, self, im, scale,
|
||||
NanAsyncQueueWorker( new AsyncDetectMultiScale(callback, self, im, scale,
|
||||
neighbors, minw, minh));
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
4
src/CascadeClassifierWrap.h
Normal file → Executable file
4
src/CascadeClassifierWrap.h
Normal file → Executable file
@ -1,10 +1,10 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class CascadeClassifierWrap: public Nan::ObjectWrap {
|
||||
class CascadeClassifierWrap: public node::ObjectWrap {
|
||||
public:
|
||||
cv::CascadeClassifier cc;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
|
||||
@ -2,15 +2,15 @@
|
||||
#include "Constants.h"
|
||||
|
||||
#define CONST(C) \
|
||||
obj->Set(Nan::New<String>(#C).ToLocalChecked(), Nan::New<Integer>(C));
|
||||
obj->Set(NanNew<String>(#C), NanNew<Integer>(C));
|
||||
|
||||
#define CONST_ENUM(C) \
|
||||
obj->Set(Nan::New<String>(#C).ToLocalChecked(), Nan::New<Integer>((int)(cv::C)));
|
||||
obj->Set(NanNew<String>(#C), NanNew<Integer>((int)(cv::C)));
|
||||
|
||||
void Constants::Init(Handle<Object> target) {
|
||||
Nan::Persistent<Object> inner;
|
||||
Local<Object> obj = Nan::New<Object>();
|
||||
inner.Reset(obj);
|
||||
Persistent<Object> inner;
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
NanAssignPersistent(inner, obj);
|
||||
|
||||
CONST(CV_8U);
|
||||
CONST(CV_8S);
|
||||
@ -72,7 +72,7 @@ void Constants::Init(Handle<Object> target) {
|
||||
CONST_ENUM(NORM_RELATIVE);
|
||||
CONST_ENUM(NORM_TYPE_MASK);
|
||||
|
||||
target->Set(Nan::New("Constants").ToLocalChecked(), obj);
|
||||
target->Set(NanNew("Constants"), obj);
|
||||
}
|
||||
|
||||
#undef CONST
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class Constants: public Nan::ObjectWrap {
|
||||
class Constants: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
};
|
||||
|
||||
316
src/Contours.cc
Normal file → Executable file
316
src/Contours.cc
Normal file → Executable file
@ -4,337 +4,337 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Nan::Persistent<FunctionTemplate> Contour::constructor;
|
||||
v8::Persistent<FunctionTemplate> Contour::constructor;
|
||||
|
||||
void Contour::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
// Class/contructor
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(Contour::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Contour::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("Contours").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("Contours"));
|
||||
|
||||
// Prototype
|
||||
// Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
Nan::SetPrototypeMethod(ctor, "point", Point);
|
||||
Nan::SetPrototypeMethod(ctor, "size", Size);
|
||||
Nan::SetPrototypeMethod(ctor, "cornerCount", CornerCount);
|
||||
Nan::SetPrototypeMethod(ctor, "area", Area);
|
||||
Nan::SetPrototypeMethod(ctor, "arcLength", ArcLength);
|
||||
Nan::SetPrototypeMethod(ctor, "approxPolyDP", ApproxPolyDP);
|
||||
Nan::SetPrototypeMethod(ctor, "convexHull", ConvexHull);
|
||||
Nan::SetPrototypeMethod(ctor, "boundingRect", BoundingRect);
|
||||
Nan::SetPrototypeMethod(ctor, "minAreaRect", MinAreaRect);
|
||||
Nan::SetPrototypeMethod(ctor, "fitEllipse", FitEllipse);
|
||||
Nan::SetPrototypeMethod(ctor, "isConvex", IsConvex);
|
||||
Nan::SetPrototypeMethod(ctor, "moments", Moments);
|
||||
Nan::SetPrototypeMethod(ctor, "hierarchy", Hierarchy);
|
||||
Nan::SetPrototypeMethod(ctor, "serialize", Serialize);
|
||||
Nan::SetPrototypeMethod(ctor, "deserialize", Deserialize);
|
||||
target->Set(Nan::New("Contours").ToLocalChecked(), ctor->GetFunction());
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "point", Point);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "size", Size);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "cornerCount", CornerCount);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "area", Area);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "arcLength", ArcLength);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "approxPolyDP", ApproxPolyDP);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "convexHull", ConvexHull);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "boundingRect", BoundingRect);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "minAreaRect", MinAreaRect);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "fitEllipse", FitEllipse);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "isConvex", IsConvex);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "moments", Moments);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "hierarchy", Hierarchy);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "serialize", Serialize);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "deserialize", Deserialize);
|
||||
target->Set(NanNew("Contours"), ctor->GetFunction());
|
||||
};
|
||||
|
||||
NAN_METHOD(Contour::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
Nan::ThrowTypeError("Cannot instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
}
|
||||
|
||||
Contour *contours;
|
||||
contours = new Contour;
|
||||
|
||||
contours->Wrap(info.Holder());
|
||||
info.GetReturnValue().Set(info.Holder());
|
||||
contours->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
Contour::Contour() :
|
||||
Nan::ObjectWrap() {
|
||||
ObjectWrap() {
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Point) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
int index = info[1]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
int index = args[1]->NumberValue();
|
||||
|
||||
cv::Point point = self->contours[pos][index];
|
||||
|
||||
Local<Object> data = Nan::New<Object>();
|
||||
data->Set(Nan::New("x").ToLocalChecked(), Nan::New<Number>(point.x));
|
||||
data->Set(Nan::New("y").ToLocalChecked(), Nan::New<Number>(point.y));
|
||||
Local<Object> data = NanNew<Object>();
|
||||
data->Set(NanNew("x"), NanNew<Number>(point.x));
|
||||
data->Set(NanNew("y"), NanNew<Number>(point.y));
|
||||
|
||||
info.GetReturnValue().Set(data);
|
||||
NanReturnValue(data);
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Points) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
vector<cv::Point> points = self->contours[pos];
|
||||
Local<Array> data = Nan::New<Array>(points.size());
|
||||
Local<Array> data = NanNew<Array>(points.size());
|
||||
|
||||
for (std::vector<int>::size_type i = 0; i != points.size(); i++) {
|
||||
Local<Object> point_data = Nan::New<Object>();
|
||||
point_data->Set(Nan::New<String>("x").ToLocalChecked(), Nan::New<Number>(points[i].x));
|
||||
point_data->Set(Nan::New<String>("y").ToLocalChecked(), Nan::New<Number>(points[i].y));
|
||||
Local<Object> point_data = NanNew<Object>();
|
||||
point_data->Set(NanNew<String>("x"), NanNew<Number>(points[i].x));
|
||||
point_data->Set(NanNew<String>("y"), NanNew<Number>(points[i].y));
|
||||
|
||||
data->Set(i, point_data);
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(data);
|
||||
NanReturnValue(data);
|
||||
}
|
||||
|
||||
// FIXME: this should 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.
|
||||
NAN_METHOD(Contour::Size) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
|
||||
info.GetReturnValue().Set(Nan::New<Number>(self->contours.size()));
|
||||
NanReturnValue(NanNew<Number>(self->contours.size()));
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::CornerCount) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
info.GetReturnValue().Set(Nan::New<Number>(self->contours[pos].size()));
|
||||
NanReturnValue(NanNew<Number>(self->contours[pos].size()));
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Area) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
// info.GetReturnValue().Set(Nan::New<Number>(contourArea(self->contours)));
|
||||
info.GetReturnValue().Set(Nan::New<Number>(contourArea(cv::Mat(self->contours[pos]))));
|
||||
// NanReturnValue(NanNew<Number>(contourArea(self->contours)));
|
||||
NanReturnValue(NanNew<Number>(contourArea(cv::Mat(self->contours[pos]))));
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::ArcLength) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
bool isClosed = info[1]->BooleanValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
bool isClosed = args[1]->BooleanValue();
|
||||
|
||||
info.GetReturnValue().Set(Nan::New<Number>(arcLength(cv::Mat(self->contours[pos]), isClosed)));
|
||||
NanReturnValue(NanNew<Number>(arcLength(cv::Mat(self->contours[pos]), isClosed)));
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::ApproxPolyDP) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
double epsilon = info[1]->NumberValue();
|
||||
bool isClosed = info[2]->BooleanValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
double epsilon = args[1]->NumberValue();
|
||||
bool isClosed = args[2]->BooleanValue();
|
||||
|
||||
cv::Mat approxed;
|
||||
approxPolyDP(cv::Mat(self->contours[pos]), approxed, epsilon, isClosed);
|
||||
approxed.copyTo(self->contours[pos]);
|
||||
|
||||
info.GetReturnValue().Set(Nan::Null());
|
||||
NanReturnNull();
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::ConvexHull) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
|
||||
int pos = info[0]->NumberValue();
|
||||
bool clockwise = info[1]->BooleanValue();
|
||||
int pos = args[0]->NumberValue();
|
||||
bool clockwise = args[1]->BooleanValue();
|
||||
|
||||
cv::Mat hull;
|
||||
cv::convexHull(cv::Mat(self->contours[pos]), hull, clockwise);
|
||||
hull.copyTo(self->contours[pos]);
|
||||
|
||||
info.GetReturnValue().Set(Nan::Null());
|
||||
NanReturnNull();
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::BoundingRect) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
cv::Rect bounding = cv::boundingRect(cv::Mat(self->contours[pos]));
|
||||
Local<Object> rect = Nan::New<Object>();
|
||||
Local<Object> rect = NanNew<Object>();
|
||||
|
||||
rect->Set(Nan::New("x").ToLocalChecked(), Nan::New<Number>(bounding.x));
|
||||
rect->Set(Nan::New("y").ToLocalChecked(), Nan::New<Number>(bounding.y));
|
||||
rect->Set(Nan::New("width").ToLocalChecked(), Nan::New<Number>(bounding.width));
|
||||
rect->Set(Nan::New("height").ToLocalChecked(), Nan::New<Number>(bounding.height));
|
||||
rect->Set(NanNew("x"), NanNew<Number>(bounding.x));
|
||||
rect->Set(NanNew("y"), NanNew<Number>(bounding.y));
|
||||
rect->Set(NanNew("width"), NanNew<Number>(bounding.width));
|
||||
rect->Set(NanNew("height"), NanNew<Number>(bounding.height));
|
||||
|
||||
info.GetReturnValue().Set(rect);
|
||||
NanReturnValue(rect);
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::MinAreaRect) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
cv::RotatedRect minimum = cv::minAreaRect(cv::Mat(self->contours[pos]));
|
||||
|
||||
Local<Object> rect = Nan::New<Object>();
|
||||
rect->Set(Nan::New("angle").ToLocalChecked(), Nan::New<Number>(minimum.angle));
|
||||
Local<Object> rect = NanNew<Object>();
|
||||
rect->Set(NanNew("angle"), NanNew<Number>(minimum.angle));
|
||||
|
||||
Local<Object> size = Nan::New<Object>();
|
||||
size->Set(Nan::New("height").ToLocalChecked(), Nan::New<Number>(minimum.size.height));
|
||||
size->Set(Nan::New("width").ToLocalChecked(), Nan::New<Number>(minimum.size.width));
|
||||
rect->Set(Nan::New("size").ToLocalChecked(), size);
|
||||
Local<Object> size = NanNew<Object>();
|
||||
size->Set(NanNew("height"), NanNew<Number>(minimum.size.height));
|
||||
size->Set(NanNew("width"), NanNew<Number>(minimum.size.width));
|
||||
rect->Set(NanNew("size"), size);
|
||||
|
||||
Local<Object> center = Nan::New<Object>();
|
||||
center->Set(Nan::New("x").ToLocalChecked(), Nan::New<Number>(minimum.center.x));
|
||||
center->Set(Nan::New("y").ToLocalChecked(), Nan::New<Number>(minimum.center.y));
|
||||
Local<Object> center = NanNew<Object>();
|
||||
center->Set(NanNew("x"), NanNew<Number>(minimum.center.x));
|
||||
center->Set(NanNew("y"), NanNew<Number>(minimum.center.y));
|
||||
|
||||
v8::Local<v8::Array> points = Nan::New<Array>(4);
|
||||
v8::Local<v8::Array> points = NanNew<Array>(4);
|
||||
|
||||
cv::Point2f rect_points[4];
|
||||
minimum.points(rect_points);
|
||||
|
||||
for (unsigned int i=0; i<4; i++) {
|
||||
Local<Object> point = Nan::New<Object>();
|
||||
point->Set(Nan::New("x").ToLocalChecked(), Nan::New<Number>(rect_points[i].x));
|
||||
point->Set(Nan::New("y").ToLocalChecked(), Nan::New<Number>(rect_points[i].y));
|
||||
Local<Object> point = NanNew<Object>();
|
||||
point->Set(NanNew("x"), NanNew<Number>(rect_points[i].x));
|
||||
point->Set(NanNew("y"), NanNew<Number>(rect_points[i].y));
|
||||
points->Set(i, point);
|
||||
}
|
||||
|
||||
rect->Set(Nan::New("points").ToLocalChecked(), points);
|
||||
rect->Set(NanNew("points"), points);
|
||||
|
||||
info.GetReturnValue().Set(rect);
|
||||
NanReturnValue(rect);
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::FitEllipse) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
if (self->contours[pos].size() >= 5) { // Minimum number for an ellipse
|
||||
cv::RotatedRect ellipse = cv::fitEllipse(cv::Mat(self->contours[pos]));
|
||||
|
||||
Local<Object> jsEllipse = Nan::New<Object>();
|
||||
jsEllipse->Set(Nan::New("angle").ToLocalChecked(), Nan::New<Number>(ellipse.angle));
|
||||
Local<Object> jsEllipse = NanNew<Object>();
|
||||
jsEllipse->Set(NanNew("angle"), NanNew<Number>(ellipse.angle));
|
||||
|
||||
Local<Object> size = Nan::New<Object>();
|
||||
size->Set(Nan::New("height").ToLocalChecked(), Nan::New<Number>(ellipse.size.height));
|
||||
size->Set(Nan::New("width").ToLocalChecked(), Nan::New<Number>(ellipse.size.width));
|
||||
jsEllipse->Set(Nan::New("size").ToLocalChecked(), size);
|
||||
Local<Object> size = NanNew<Object>();
|
||||
size->Set(NanNew("height"), NanNew<Number>(ellipse.size.height));
|
||||
size->Set(NanNew("width"), NanNew<Number>(ellipse.size.width));
|
||||
jsEllipse->Set(NanNew("size"), size);
|
||||
|
||||
Local<Object> center = Nan::New<Object>();
|
||||
center->Set(Nan::New("x").ToLocalChecked(), Nan::New<Number>(ellipse.center.x));
|
||||
center->Set(Nan::New("y").ToLocalChecked(), Nan::New<Number>(ellipse.center.y));
|
||||
jsEllipse->Set(Nan::New("center").ToLocalChecked(), center);
|
||||
Local<Object> center = NanNew<Object>();
|
||||
center->Set(NanNew("x"), NanNew<Number>(ellipse.center.x));
|
||||
center->Set(NanNew("y"), NanNew<Number>(ellipse.center.y));
|
||||
jsEllipse->Set(NanNew("center"), center);
|
||||
|
||||
info.GetReturnValue().Set(jsEllipse);
|
||||
NanReturnValue(jsEllipse);
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(Nan::Null());
|
||||
NanReturnNull();
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::IsConvex) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
info.GetReturnValue().Set(Nan::New<Boolean>(isContourConvex(cv::Mat(self->contours[pos]))));
|
||||
NanReturnValue(NanNew<Boolean>(isContourConvex(cv::Mat(self->contours[pos]))));
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Moments) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
// Get the moments
|
||||
cv::Moments mu = moments( self->contours[pos], false );
|
||||
|
||||
Local<Object> res = Nan::New<Object>();
|
||||
Local<Object> res = NanNew<Object>();
|
||||
|
||||
res->Set(Nan::New("m00").ToLocalChecked(), Nan::New<Number>(mu.m00));
|
||||
res->Set(Nan::New("m10").ToLocalChecked(), Nan::New<Number>(mu.m10));
|
||||
res->Set(Nan::New("m01").ToLocalChecked(), Nan::New<Number>(mu.m01));
|
||||
res->Set(Nan::New("m11").ToLocalChecked(), Nan::New<Number>(mu.m11));
|
||||
res->Set(NanNew("m00"), NanNew<Number>(mu.m00));
|
||||
res->Set(NanNew("m10"), NanNew<Number>(mu.m10));
|
||||
res->Set(NanNew("m01"), NanNew<Number>(mu.m01));
|
||||
res->Set(NanNew("m11"), NanNew<Number>(mu.m11));
|
||||
|
||||
info.GetReturnValue().Set(res);
|
||||
NanReturnValue(res);
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Hierarchy) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
int pos = info[0]->IntegerValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->IntegerValue();
|
||||
|
||||
cv::Vec4i hierarchy = self->hierarchy[pos];
|
||||
|
||||
Local<Array> res = Nan::New<Array>(4);
|
||||
Local<Array> res = NanNew<Array>(4);
|
||||
|
||||
res->Set(0, Nan::New<Number>(hierarchy[0]));
|
||||
res->Set(1, Nan::New<Number>(hierarchy[1]));
|
||||
res->Set(2, Nan::New<Number>(hierarchy[2]));
|
||||
res->Set(3, Nan::New<Number>(hierarchy[3]));
|
||||
res->Set(0, NanNew<Number>(hierarchy[0]));
|
||||
res->Set(1, NanNew<Number>(hierarchy[1]));
|
||||
res->Set(2, NanNew<Number>(hierarchy[2]));
|
||||
res->Set(3, NanNew<Number>(hierarchy[3]));
|
||||
|
||||
info.GetReturnValue().Set(res);
|
||||
NanReturnValue(res);
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Serialize) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
|
||||
Local<Array> contours_data = Nan::New<Array>(self->contours.size());
|
||||
Local<Array> contours_data = NanNew<Array>(self->contours.size());
|
||||
|
||||
for (std::vector<int>::size_type i = 0; i != self->contours.size(); i++) {
|
||||
vector<cv::Point> points = self->contours[i];
|
||||
Local<Array> contour_data = Nan::New<Array>(points.size());
|
||||
Local<Array> contour_data = NanNew<Array>(points.size());
|
||||
|
||||
for (std::vector<int>::size_type j = 0; j != points.size(); j++) {
|
||||
Local<Array> point_data = Nan::New<Array>(2);
|
||||
point_data->Set(0, Nan::New<Number>(points[j].x));
|
||||
point_data->Set(1, Nan::New<Number>(points[j].y));
|
||||
Local<Array> point_data = NanNew<Array>(2);
|
||||
point_data->Set(0, NanNew<Number>(points[j].x));
|
||||
point_data->Set(1, NanNew<Number>(points[j].y));
|
||||
|
||||
contour_data->Set(j, point_data);
|
||||
}
|
||||
contours_data->Set(i, contour_data);
|
||||
}
|
||||
|
||||
Local<Array> hierarchy_data = Nan::New<Array>(self->hierarchy.size());
|
||||
Local<Array> hierarchy_data = NanNew<Array>(self->hierarchy.size());
|
||||
for (std::vector<int>::size_type i = 0; i != self->hierarchy.size(); i++) {
|
||||
Local<Array> contour_data = Nan::New<Array>(4);
|
||||
contour_data->Set(0, Nan::New<Number>(self->hierarchy[i][0]));
|
||||
contour_data->Set(1, Nan::New<Number>(self->hierarchy[i][1]));
|
||||
contour_data->Set(2, Nan::New<Number>(self->hierarchy[i][2]));
|
||||
contour_data->Set(3, Nan::New<Number>(self->hierarchy[i][3]));
|
||||
Local<Array> contour_data = NanNew<Array>(4);
|
||||
contour_data->Set(0, NanNew<Number>(self->hierarchy[i][0]));
|
||||
contour_data->Set(1, NanNew<Number>(self->hierarchy[i][1]));
|
||||
contour_data->Set(2, NanNew<Number>(self->hierarchy[i][2]));
|
||||
contour_data->Set(3, NanNew<Number>(self->hierarchy[i][3]));
|
||||
|
||||
hierarchy_data->Set(i, contour_data);
|
||||
}
|
||||
|
||||
Local<Object> data = Nan::New<Object>();
|
||||
data->Set(Nan::New<String>("contours").ToLocalChecked(), contours_data);
|
||||
data->Set(Nan::New<String>("hierarchy").ToLocalChecked(), hierarchy_data);
|
||||
Local<Object> data = NanNew<Object>();
|
||||
data->Set(NanNew<String>("contours"), contours_data);
|
||||
data->Set(NanNew<String>("hierarchy"), hierarchy_data);
|
||||
|
||||
info.GetReturnValue().Set(data);
|
||||
NanReturnValue(data);
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Deserialize) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Contour *self = Nan::ObjectWrap::Unwrap<Contour>(info.This());
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
|
||||
Handle<Object> data = Handle<Object>::Cast(info[0]);
|
||||
Handle<Object> data = Handle<Object>::Cast(args[0]);
|
||||
|
||||
Handle<Array> contours_data = Handle<Array>::Cast(data->Get(Nan::New<String>("contours").ToLocalChecked()));
|
||||
Handle<Array> hierarchy_data = Handle<Array>::Cast(data->Get(Nan::New<String>("hierarchy").ToLocalChecked()));
|
||||
Handle<Array> contours_data = Handle<Array>::Cast(data->Get(NanNew<String>("contours")));
|
||||
Handle<Array> hierarchy_data = Handle<Array>::Cast(data->Get(NanNew<String>("hierarchy")));
|
||||
|
||||
vector<vector<cv::Point> > contours_res;
|
||||
int contours_length = contours_data->Length();
|
||||
@ -369,5 +369,5 @@ NAN_METHOD(Contour::Deserialize) {
|
||||
self->contours = contours_res;
|
||||
self->hierarchy = hierarchy_res;
|
||||
|
||||
info.GetReturnValue().Set(Nan::Null());
|
||||
NanReturnNull();
|
||||
}
|
||||
|
||||
4
src/Contours.h
Normal file → Executable file
4
src/Contours.h
Normal file → Executable file
@ -2,13 +2,13 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Contour: public Nan::ObjectWrap {
|
||||
class Contour: public node::ObjectWrap {
|
||||
public:
|
||||
cv::Mat mat;
|
||||
vector<vector<cv::Point> > contours;
|
||||
vector<cv::Vec4i> hierarchy;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
|
||||
@ -14,11 +14,11 @@
|
||||
cv::Mat fromMatrixOrFilename(Local<Value> v) {
|
||||
cv::Mat im;
|
||||
if (v->IsString()) {
|
||||
std::string filename = std::string(*Nan::Utf8String(v->ToString()));
|
||||
std::string filename = std::string(*NanAsciiString(v->ToString()));
|
||||
im = cv::imread(filename);
|
||||
// std::cout<< im.size();
|
||||
} else {
|
||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(v->ToObject());
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(v->ToObject());
|
||||
im = img->mat;
|
||||
}
|
||||
return im;
|
||||
@ -27,36 +27,36 @@ cv::Mat fromMatrixOrFilename(Local<Value> v) {
|
||||
void AsyncPredict(uv_work_t *req);
|
||||
void AfterAsyncPredict(uv_work_t *req);
|
||||
|
||||
Nan::Persistent<FunctionTemplate> FaceRecognizerWrap::constructor;
|
||||
Persistent<FunctionTemplate> FaceRecognizerWrap::constructor;
|
||||
|
||||
void FaceRecognizerWrap::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(FaceRecognizerWrap::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(FaceRecognizerWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("FaceRecognizer").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("FaceRecognizer"));
|
||||
|
||||
Nan::SetMethod(ctor, "createLBPHFaceRecognizer", CreateLBPH);
|
||||
Nan::SetMethod(ctor, "createEigenFaceRecognizer", CreateEigen);
|
||||
Nan::SetMethod(ctor, "createFisherFaceRecognizer", CreateFisher);
|
||||
NODE_SET_METHOD(ctor, "createLBPHFaceRecognizer", CreateLBPH);
|
||||
NODE_SET_METHOD(ctor, "createEigenFaceRecognizer", CreateEigen);
|
||||
NODE_SET_METHOD(ctor, "createFisherFaceRecognizer", CreateFisher);
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "trainSync", TrainSync);
|
||||
Nan::SetPrototypeMethod(ctor, "updateSync", UpdateSync);
|
||||
Nan::SetPrototypeMethod(ctor, "predictSync", PredictSync);
|
||||
Nan::SetPrototypeMethod(ctor, "saveSync", SaveSync);
|
||||
Nan::SetPrototypeMethod(ctor, "loadSync", LoadSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "trainSync", TrainSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "updateSync", UpdateSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "predictSync", PredictSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "saveSync", SaveSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "loadSync", LoadSync);
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "getMat", GetMat);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "getMat", GetMat);
|
||||
|
||||
target->Set(Nan::New("FaceRecognizer").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("FaceRecognizer"), ctor->GetFunction());
|
||||
};
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||
}
|
||||
|
||||
@ -64,12 +64,12 @@ NAN_METHOD(FaceRecognizerWrap::New) {
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createLBPHFaceRecognizer(1, 8, 8, 8, 80.0);
|
||||
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH);
|
||||
|
||||
pt->Wrap(info.This());
|
||||
info.GetReturnValue().Set(info.This());
|
||||
pt->Wrap(args.This());
|
||||
NanReturnValue(args.This());
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::CreateLBPH) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
int radius = 1;
|
||||
int neighbors = 8;
|
||||
@ -83,17 +83,17 @@ NAN_METHOD(FaceRecognizerWrap::CreateLBPH) {
|
||||
INT_FROM_ARGS(grid_y, 3)
|
||||
DOUBLE_FROM_ARGS(threshold, 4)
|
||||
|
||||
Local<Object> n = Nan::New(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
Local<Object> n = NanNew(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createLBPHFaceRecognizer(radius,
|
||||
neighbors, grid_x, grid_y, threshold);
|
||||
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH);
|
||||
pt->Wrap(n);
|
||||
|
||||
info.GetReturnValue().Set( n );
|
||||
NanReturnValue( n );
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::CreateEigen) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
int components = 0;
|
||||
double threshold = DBL_MAX;
|
||||
@ -101,17 +101,17 @@ NAN_METHOD(FaceRecognizerWrap::CreateEigen) {
|
||||
INT_FROM_ARGS(components, 0)
|
||||
DOUBLE_FROM_ARGS(threshold, 1)
|
||||
|
||||
Local<Object> n = Nan::New(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
Local<Object> n = NanNew(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createEigenFaceRecognizer(components,
|
||||
threshold);
|
||||
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, EIGEN);
|
||||
pt->Wrap(n);
|
||||
|
||||
info.GetReturnValue().Set( n );
|
||||
NanReturnValue( n );
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::CreateFisher) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
int components = 0;
|
||||
double threshold = DBL_MAX;
|
||||
@ -119,14 +119,14 @@ NAN_METHOD(FaceRecognizerWrap::CreateFisher) {
|
||||
INT_FROM_ARGS(components, 0)
|
||||
DOUBLE_FROM_ARGS(threshold, 1)
|
||||
|
||||
Local<Object> n = Nan::New(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
Local<Object> n = NanNew(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createFisherFaceRecognizer(components,
|
||||
threshold);
|
||||
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, FISHER);
|
||||
pt->Wrap(n);
|
||||
|
||||
info.GetReturnValue().Set( n );
|
||||
NanReturnValue( n );
|
||||
}
|
||||
|
||||
FaceRecognizerWrap::FaceRecognizerWrap(cv::Ptr<cv::FaceRecognizer> f,
|
||||
@ -135,16 +135,16 @@ FaceRecognizerWrap::FaceRecognizerWrap(cv::Ptr<cv::FaceRecognizer> f,
|
||||
typ = type;
|
||||
}
|
||||
|
||||
Handle<Value> UnwrapTrainingData(Nan::NAN_METHOD_ARGS_TYPE info,
|
||||
Handle<Value> UnwrapTrainingData(_NAN_METHOD_ARGS_TYPE args,
|
||||
cv::vector<cv::Mat>* images, cv::vector<int>* labels) {
|
||||
|
||||
if (info.Length() < 1 || !info[0]->IsArray()) {
|
||||
if (args.Length() < 1 || !args[0]->IsArray()) {
|
||||
JSTHROW("FaceRecognizer.train takes a list of [<int> label, image] tuples")
|
||||
}
|
||||
|
||||
// Iterate through [[label, image], ...] etc, and add matrix / label to vectors
|
||||
// const Local<Array> tuples = v8::Array::Cast(*info[0]);
|
||||
const Local<Array> tuples = Local<Array>::Cast(info[0]);
|
||||
// const Local<Array> tuples = v8::Array::Cast(*args[0]);
|
||||
const Local<Array> tuples = Local<Array>::Cast(args[0]);
|
||||
|
||||
const uint32_t length = tuples->Length();
|
||||
for (uint32_t i=0; i<length; ++i) {
|
||||
@ -167,7 +167,7 @@ Handle<Value> UnwrapTrainingData(Nan::NAN_METHOD_ARGS_TYPE info,
|
||||
labels->push_back(label);
|
||||
images->push_back(im);
|
||||
}
|
||||
return Nan::Undefined();
|
||||
return NanUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::TrainSync) {
|
||||
@ -176,14 +176,14 @@ NAN_METHOD(FaceRecognizerWrap::TrainSync) {
|
||||
cv::vector<cv::Mat> images;
|
||||
cv::vector<int> labels;
|
||||
|
||||
Handle<Value> exception = UnwrapTrainingData(info, &images, &labels);
|
||||
Handle<Value> exception = UnwrapTrainingData(args, &images, &labels);
|
||||
if (!exception->IsUndefined()) {
|
||||
info.GetReturnValue().Set(exception); // FIXME: not too sure about returning exceptions like this
|
||||
NanReturnValue(exception); // FIXME: not too sure about returning exceptions like this
|
||||
}
|
||||
|
||||
self->rec->train(images, labels);
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::UpdateSync) {
|
||||
@ -199,20 +199,20 @@ NAN_METHOD(FaceRecognizerWrap::UpdateSync) {
|
||||
cv::vector<cv::Mat> images;
|
||||
cv::vector<int> labels;
|
||||
|
||||
Handle<Value> exception = UnwrapTrainingData(info, &images, &labels);
|
||||
Handle<Value> exception = UnwrapTrainingData(args, &images, &labels);
|
||||
if (!exception->IsUndefined()) {
|
||||
JSTHROW(exception);
|
||||
}
|
||||
|
||||
self->rec->update(images, labels);
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::PredictSync) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
|
||||
cv::Mat im = fromMatrixOrFilename(info[0]); // TODO CHECK!
|
||||
cv::Mat im = fromMatrixOrFilename(args[0]); // TODO CHECK!
|
||||
cv::cvtColor(im, im, CV_RGB2GRAY);
|
||||
// int predictedLabel = self->rec->predict(im);
|
||||
|
||||
@ -220,46 +220,46 @@ NAN_METHOD(FaceRecognizerWrap::PredictSync) {
|
||||
double confidence = 0.0;
|
||||
self->rec->predict(im, predictedLabel, confidence);
|
||||
|
||||
v8::Local<v8::Object> res = Nan::New<Object>();
|
||||
res->Set(Nan::New("id").ToLocalChecked(), Nan::New<Number>(predictedLabel));
|
||||
res->Set(Nan::New("confidence").ToLocalChecked(), Nan::New<Number>(confidence));
|
||||
v8::Local<v8::Object> res = NanNew<Object>();
|
||||
res->Set(NanNew("id"), NanNew<Number>(predictedLabel));
|
||||
res->Set(NanNew("confidence"), NanNew<Number>(confidence));
|
||||
|
||||
info.GetReturnValue().Set(res);
|
||||
NanReturnValue(res);
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::SaveSync) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!info[0]->IsString()) {
|
||||
if (!args[0]->IsString()) {
|
||||
JSTHROW("Save takes a filename")
|
||||
}
|
||||
std::string filename = std::string(*Nan::Utf8String(info[0]->ToString()));
|
||||
std::string filename = std::string(*NanAsciiString(args[0]->ToString()));
|
||||
self->rec->save(filename);
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::LoadSync) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!info[0]->IsString()) {
|
||||
if (!args[0]->IsString()) {
|
||||
JSTHROW("Load takes a filename")
|
||||
}
|
||||
std::string filename = std::string(*Nan::Utf8String(info[0]->ToString()));
|
||||
std::string filename = std::string(*NanAsciiString(args[0]->ToString()));
|
||||
self->rec->load(filename);
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::GetMat) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!info[0]->IsString()) {
|
||||
if (!args[0]->IsString()) {
|
||||
JSTHROW("getMat takes a key")
|
||||
}
|
||||
std::string key = std::string(*Nan::Utf8String(info[0]->ToString()));
|
||||
std::string key = std::string(*NanAsciiString(args[0]->ToString()));
|
||||
cv::Mat m = self->rec->getMat(key);
|
||||
|
||||
Local<Object> im = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(im);
|
||||
Local<Object> im = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im);
|
||||
img->mat = m;
|
||||
|
||||
info.GetReturnValue().Set(im);
|
||||
NanReturnValue(im);
|
||||
}
|
||||
|
||||
#endif // End version > 2.4
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
#include "opencv2/contrib/contrib.hpp"
|
||||
|
||||
class FaceRecognizerWrap: public Nan::ObjectWrap {
|
||||
class FaceRecognizerWrap: public node::ObjectWrap {
|
||||
public:
|
||||
cv::Ptr<cv::FaceRecognizer> rec;
|
||||
int typ;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
|
||||
@ -6,15 +6,15 @@
|
||||
#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
void Features::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Nan::SetMethod(target, "ImageSimilarity", Similarity);
|
||||
NODE_SET_METHOD(target, "ImageSimilarity", Similarity);
|
||||
}
|
||||
|
||||
class AsyncDetectSimilarity: public Nan::AsyncWorker {
|
||||
class AsyncDetectSimilarity: public NanAsyncWorker {
|
||||
public:
|
||||
AsyncDetectSimilarity(Nan::Callback *callback, cv::Mat image1, cv::Mat image2) :
|
||||
Nan::AsyncWorker(callback),
|
||||
AsyncDetectSimilarity(NanCallback *callback, cv::Mat image1, cv::Mat image2) :
|
||||
NanAsyncWorker(callback),
|
||||
image1(image1),
|
||||
image2(image2),
|
||||
dissimilarity(0) {
|
||||
@ -80,12 +80,12 @@ public:
|
||||
}
|
||||
|
||||
void HandleOKCallback() {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Handle<Value> argv[2];
|
||||
|
||||
argv[0] = Nan::Null();
|
||||
argv[1] = Nan::New<Number>(dissimilarity);
|
||||
argv[0] = NanNull();
|
||||
argv[1] = NanNew<Number>(dissimilarity);
|
||||
|
||||
callback->Call(2, argv);
|
||||
}
|
||||
@ -97,17 +97,17 @@ private:
|
||||
};
|
||||
|
||||
NAN_METHOD(Features::Similarity) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
REQ_FUN_ARG(2, cb);
|
||||
|
||||
cv::Mat image1 = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject())->mat;
|
||||
cv::Mat image2 = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject())->mat;
|
||||
cv::Mat image1 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject())->mat;
|
||||
cv::Mat image2 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject())->mat;
|
||||
|
||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||
|
||||
Nan::AsyncQueueWorker( new AsyncDetectSimilarity(callback, image1, image2) );
|
||||
return;
|
||||
NanAsyncQueueWorker( new AsyncDetectSimilarity(callback, image1, image2) );
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
|
||||
class Features: public Nan::ObjectWrap {
|
||||
class Features: public node::ObjectWrap {
|
||||
public:
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
static NAN_METHOD(Similarity);
|
||||
|
||||
@ -2,41 +2,41 @@
|
||||
#include "OpenCV.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
Nan::Persistent<FunctionTemplate> NamedWindow::constructor;
|
||||
Persistent<FunctionTemplate> NamedWindow::constructor;
|
||||
|
||||
void NamedWindow::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(NamedWindow::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(NamedWindow::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("NamedWindow").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("NamedWindow"));
|
||||
|
||||
// Prototype
|
||||
Nan::SetPrototypeMethod(ctor, "show", Show);
|
||||
Nan::SetPrototypeMethod(ctor, "destroy", Destroy);
|
||||
Nan::SetPrototypeMethod(ctor, "blockingWaitKey", BlockingWaitKey);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "show", Show);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "destroy", Destroy);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "blockingWaitKey", BlockingWaitKey);
|
||||
|
||||
target->Set(Nan::New("NamedWindow").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("NamedWindow"), ctor->GetFunction());
|
||||
};
|
||||
|
||||
NAN_METHOD(NamedWindow::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||
}
|
||||
|
||||
NamedWindow* win;
|
||||
if (info.Length() == 1) {
|
||||
win = new NamedWindow(std::string(*Nan::Utf8String(info[0]->ToString())), 0);
|
||||
} else { //if (info.Length() == 2){
|
||||
win = new NamedWindow(std::string(*Nan::Utf8String(info[0]->ToString())), 0);
|
||||
if (args.Length() == 1) {
|
||||
win = new NamedWindow(std::string(*NanAsciiString(args[0]->ToString())), 0);
|
||||
} else { //if (args.Length() == 2){
|
||||
win = new NamedWindow(std::string(*NanAsciiString(args[0]->ToString())), 0);
|
||||
}
|
||||
|
||||
win->Wrap(info.Holder());
|
||||
info.GetReturnValue().Set(info.Holder());
|
||||
win->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
NamedWindow::NamedWindow(const std::string& name, int f) {
|
||||
@ -47,38 +47,38 @@ NamedWindow::NamedWindow(const std::string& name, int f) {
|
||||
|
||||
NAN_METHOD(NamedWindow::Show) {
|
||||
SETUP_FUNCTION(NamedWindow)
|
||||
Matrix *im = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
|
||||
try {
|
||||
cv::imshow(self->winname, im->mat);
|
||||
} catch (cv::Exception& e) {
|
||||
const char* err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
NanThrowError(err_msg);
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(info.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
NAN_METHOD(NamedWindow::Destroy) {
|
||||
SETUP_FUNCTION(NamedWindow)
|
||||
cv::destroyWindow(self->winname);
|
||||
info.GetReturnValue().Set(info.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
NAN_METHOD(NamedWindow::BlockingWaitKey) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
//SETUP_FUNCTION(NamedWindow)
|
||||
int time = 0;
|
||||
|
||||
if (info.Length() > 1) {
|
||||
time = info[1]->IntegerValue();
|
||||
if (args.Length() > 1) {
|
||||
time = args[1]->IntegerValue();
|
||||
} else {
|
||||
if (info.Length() > 0) {
|
||||
time = info[0]->IntegerValue();
|
||||
if (args.Length() > 0) {
|
||||
time = args[0]->IntegerValue();
|
||||
}
|
||||
}
|
||||
|
||||
int res = cv::waitKey(time);
|
||||
|
||||
info.GetReturnValue().Set(Nan::New<Number>(res));
|
||||
NanReturnValue(NanNew<Number>(res));
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class NamedWindow: public Nan::ObjectWrap {
|
||||
class NamedWindow: public node::ObjectWrap {
|
||||
public:
|
||||
std::string winname;
|
||||
int flags;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
|
||||
@ -2,34 +2,34 @@
|
||||
#include "Matrix.h"
|
||||
|
||||
void ImgProc::Init(Handle<Object> target) {
|
||||
Nan::Persistent<Object> inner;
|
||||
Local<Object> obj = Nan::New<Object>();
|
||||
inner.Reset(obj);
|
||||
Persistent<Object> inner;
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
NanAssignPersistent(inner, obj);
|
||||
|
||||
Nan::SetMethod(obj, "undistort", Undistort);
|
||||
Nan::SetMethod(obj, "initUndistortRectifyMap", InitUndistortRectifyMap);
|
||||
Nan::SetMethod(obj, "remap", Remap);
|
||||
NODE_SET_METHOD(obj, "undistort", Undistort);
|
||||
NODE_SET_METHOD(obj, "initUndistortRectifyMap", InitUndistortRectifyMap);
|
||||
NODE_SET_METHOD(obj, "remap", Remap);
|
||||
|
||||
target->Set(Nan::New("imgproc").ToLocalChecked(), obj);
|
||||
target->Set(NanNew("imgproc"), obj);
|
||||
}
|
||||
|
||||
// cv::undistort
|
||||
NAN_METHOD(ImgProc::Undistort) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the image
|
||||
Matrix* m0 = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat inputImage = m0->mat;
|
||||
|
||||
// Arg 1 is the camera matrix
|
||||
Matrix* m1 = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject());
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat K = m1->mat;
|
||||
|
||||
// Arg 2 is the distortion coefficents
|
||||
Matrix* m2 = Nan::ObjectWrap::Unwrap<Matrix>(info[2]->ToObject());
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat dist = m2->mat;
|
||||
|
||||
// Make an mat to hold the result image
|
||||
@ -39,51 +39,51 @@ NAN_METHOD(ImgProc::Undistort) {
|
||||
cv::undistort(inputImage, outputImage, K, dist);
|
||||
|
||||
// Wrap the output image
|
||||
Local<Object> outMatrixWrap = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *outMatrix = Nan::ObjectWrap::Unwrap<Matrix>(outMatrixWrap);
|
||||
Local<Object> outMatrixWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *outMatrix = ObjectWrap::Unwrap<Matrix>(outMatrixWrap);
|
||||
outMatrix->mat = outputImage;
|
||||
|
||||
// Return the output image
|
||||
info.GetReturnValue().Set(outMatrixWrap);
|
||||
NanReturnValue(outMatrixWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::initUndistortRectifyMap
|
||||
NAN_METHOD(ImgProc::InitUndistortRectifyMap) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Arg 0 is the camera matrix
|
||||
Matrix* m0 = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat K = m0->mat;
|
||||
|
||||
// Arg 1 is the distortion coefficents
|
||||
Matrix* m1 = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject());
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat dist = m1->mat;
|
||||
|
||||
// Arg 2 is the recification transformation
|
||||
Matrix* m2 = Nan::ObjectWrap::Unwrap<Matrix>(info[2]->ToObject());
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat R = m2->mat;
|
||||
|
||||
// Arg 3 is the new camera matrix
|
||||
Matrix* m3 = Nan::ObjectWrap::Unwrap<Matrix>(info[3]->ToObject());
|
||||
Matrix* m3 = ObjectWrap::Unwrap<Matrix>(args[3]->ToObject());
|
||||
cv::Mat newK = m3->mat;
|
||||
|
||||
// Arg 4 is the image size
|
||||
cv::Size imageSize;
|
||||
if (info[4]->IsArray()) {
|
||||
Local<Object> v8sz = info[4]->ToObject();
|
||||
if (args[4]->IsArray()) {
|
||||
Local<Object> v8sz = args[4]->ToObject();
|
||||
imageSize = cv::Size(v8sz->Get(1)->IntegerValue(), v8sz->Get(0)->IntegerValue());
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass image size");
|
||||
}
|
||||
|
||||
// Arg 5 is the first map type, skip for now
|
||||
int m1type = info[5]->IntegerValue();
|
||||
int m1type = args[5]->IntegerValue();
|
||||
|
||||
// Make matrices to hold the output maps
|
||||
cv::Mat map1, map2;
|
||||
@ -92,49 +92,49 @@ NAN_METHOD(ImgProc::InitUndistortRectifyMap) {
|
||||
cv::initUndistortRectifyMap(K, dist, R, newK, imageSize, m1type, map1, map2);
|
||||
|
||||
// Wrap the output maps
|
||||
Local<Object> map1Wrap = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *map1Matrix = Nan::ObjectWrap::Unwrap<Matrix>(map1Wrap);
|
||||
Local<Object> map1Wrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *map1Matrix = ObjectWrap::Unwrap<Matrix>(map1Wrap);
|
||||
map1Matrix->mat = map1;
|
||||
|
||||
Local<Object> map2Wrap = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *map2Matrix = Nan::ObjectWrap::Unwrap<Matrix>(map2Wrap);
|
||||
Local<Object> map2Wrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *map2Matrix = ObjectWrap::Unwrap<Matrix>(map2Wrap);
|
||||
map2Matrix->mat = map2;
|
||||
|
||||
// Make a return object with the two maps
|
||||
Local<Object> ret = Nan::New<Object>();
|
||||
ret->Set(Nan::New<String>("map1").ToLocalChecked(), map1Wrap);
|
||||
ret->Set(Nan::New<String>("map2").ToLocalChecked(), map2Wrap);
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
ret->Set(NanNew<String>("map1"), map1Wrap);
|
||||
ret->Set(NanNew<String>("map2"), map2Wrap);
|
||||
|
||||
// Return the maps
|
||||
info.GetReturnValue().Set(ret);
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::remap
|
||||
NAN_METHOD(ImgProc::Remap) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the image
|
||||
Matrix* m0 = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat inputImage = m0->mat;
|
||||
|
||||
// Arg 1 is the first map
|
||||
Matrix* m1 = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject());
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat map1 = m1->mat;
|
||||
|
||||
// Arg 2 is the second map
|
||||
Matrix* m2 = Nan::ObjectWrap::Unwrap<Matrix>(info[2]->ToObject());
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat map2 = m2->mat;
|
||||
|
||||
// Arg 3 is the interpolation mode
|
||||
int interpolation = info[3]->IntegerValue();
|
||||
int interpolation = args[3]->IntegerValue();
|
||||
|
||||
// Args 4, 5 border settings, skipping for now
|
||||
|
||||
@ -145,15 +145,15 @@ NAN_METHOD(ImgProc::Remap) {
|
||||
cv::remap(inputImage, outputImage, map1, map2, interpolation);
|
||||
|
||||
// Wrap the output image
|
||||
Local<Object> outMatrixWrap = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *outMatrix = Nan::ObjectWrap::Unwrap<Matrix>(outMatrixWrap);
|
||||
Local<Object> outMatrixWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *outMatrix = ObjectWrap::Unwrap<Matrix>(outMatrixWrap);
|
||||
outMatrix->mat = outputImage;
|
||||
|
||||
// Return the image
|
||||
info.GetReturnValue().Set(outMatrixWrap);
|
||||
NanReturnValue(outMatrixWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/**
|
||||
* Implementation of imgproc.hpp functions
|
||||
*/
|
||||
class ImgProc: public Nan::ObjectWrap {
|
||||
class ImgProc: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(Undistort);
|
||||
|
||||
1414
src/Matrix.cc
Normal file → Executable file
1414
src/Matrix.cc
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
58
src/Matrix.h
Normal file → Executable file
58
src/Matrix.h
Normal file → Executable file
@ -1,10 +1,10 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class Matrix: public Nan::ObjectWrap {
|
||||
class Matrix: public node::ObjectWrap {
|
||||
public:
|
||||
|
||||
cv::Mat mat;
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
Matrix();
|
||||
@ -119,34 +119,34 @@ public:
|
||||
|
||||
JSFUNC(Release)
|
||||
/*
|
||||
static Handle<Value> Val(const Arguments& info);
|
||||
static Handle<Value> RowRange(const Arguments& info);
|
||||
static Handle<Value> ColRange(const Arguments& info);
|
||||
static Handle<Value> Diag(const Arguments& info);
|
||||
static Handle<Value> Clone(const Arguments& info);
|
||||
static Handle<Value> CopyTo(const Arguments& info);
|
||||
static Handle<Value> ConvertTo(const Arguments& info);
|
||||
static Handle<Value> AssignTo(const Arguments& info);
|
||||
static Handle<Value> SetTo(const Arguments& info);
|
||||
static Handle<Value> Reshape(const Arguments& info);
|
||||
static Handle<Value> Transpose(const Arguments& info);
|
||||
static Handle<Value> Invert(const Arguments& info);
|
||||
static Handle<Value> Multiply(const Arguments& info);
|
||||
static Handle<Value> Cross(const Arguments& info);
|
||||
static Handle<Value> Dot(const Arguments& info);
|
||||
static Handle<Value> Zeroes(const Arguments& info);
|
||||
static Handle<Value> Ones(const Arguments& info);
|
||||
static Handle<Value> Val(const Arguments& args);
|
||||
static Handle<Value> RowRange(const Arguments& args);
|
||||
static Handle<Value> ColRange(const Arguments& args);
|
||||
static Handle<Value> Diag(const Arguments& args);
|
||||
static Handle<Value> Clone(const Arguments& args);
|
||||
static Handle<Value> CopyTo(const Arguments& args);
|
||||
static Handle<Value> ConvertTo(const Arguments& args);
|
||||
static Handle<Value> AssignTo(const Arguments& args);
|
||||
static Handle<Value> SetTo(const Arguments& args);
|
||||
static Handle<Value> Reshape(const Arguments& args);
|
||||
static Handle<Value> Transpose(const Arguments& args);
|
||||
static Handle<Value> Invert(const Arguments& args);
|
||||
static Handle<Value> Multiply(const Arguments& args);
|
||||
static Handle<Value> Cross(const Arguments& args);
|
||||
static Handle<Value> Dot(const Arguments& args);
|
||||
static Handle<Value> Zeroes(const Arguments& args);
|
||||
static Handle<Value> Ones(const Arguments& args);
|
||||
// create, increment, release
|
||||
static Handle<Value> PushBack(const Arguments& info);
|
||||
static Handle<Value> PopBack(const Arguments& info);
|
||||
static Handle<Value> Total(const Arguments& info);
|
||||
static Handle<Value> IsContinous(const Arguments& info);
|
||||
static Handle<Value> Type(const Arguments& info);
|
||||
static Handle<Value> Depth(const Arguments& info);
|
||||
static Handle<Value> Channels(const Arguments& info);
|
||||
static Handle<Value> StepOne(const Arguments& info);
|
||||
static Handle<Value> GetPerspectiveTransform(const Arguments& info);
|
||||
static Handle<Value> WarpPerspective(const Arguments& info);
|
||||
static Handle<Value> PushBack(const Arguments& args);
|
||||
static Handle<Value> PopBack(const Arguments& args);
|
||||
static Handle<Value> Total(const Arguments& args);
|
||||
static Handle<Value> IsContinous(const Arguments& args);
|
||||
static Handle<Value> Type(const Arguments& args);
|
||||
static Handle<Value> Depth(const Arguments& args);
|
||||
static Handle<Value> Channels(const Arguments& args);
|
||||
static Handle<Value> StepOne(const Arguments& args);
|
||||
static Handle<Value> GetPerspectiveTransform(const Arguments& args);
|
||||
static Handle<Value> WarpPerspective(const Arguments& args);
|
||||
|
||||
*/
|
||||
};
|
||||
|
||||
40
src/OpenCV.cc
Normal file → Executable file
40
src/OpenCV.cc
Normal file → Executable file
@ -3,66 +3,66 @@
|
||||
#include <nan.h>
|
||||
|
||||
void OpenCV::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
// Version string.
|
||||
char out [21];
|
||||
int n = sprintf(out, "%i.%i", CV_MAJOR_VERSION, CV_MINOR_VERSION);
|
||||
target->Set(Nan::New<String>("version").ToLocalChecked(), Nan::New<String>(out, n).ToLocalChecked());
|
||||
target->Set(NanNew<String>("version"), NanNew<String>(out, n));
|
||||
|
||||
Nan::SetMethod(target, "readImage", ReadImage);
|
||||
NODE_SET_METHOD(target, "readImage", ReadImage);
|
||||
}
|
||||
|
||||
NAN_METHOD(OpenCV::ReadImage) {
|
||||
Nan::EscapableHandleScope scope;
|
||||
NanEscapableScope();
|
||||
|
||||
REQ_FUN_ARG(1, cb);
|
||||
|
||||
Local<Value> argv[2];
|
||||
argv[0] = Nan::Null();
|
||||
argv[0] = NanNull();
|
||||
|
||||
Local<Object> im_h = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(im_h);
|
||||
Local<Object> im_h = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
|
||||
argv[1] = im_h;
|
||||
|
||||
try {
|
||||
cv::Mat mat;
|
||||
|
||||
if (info[0]->IsNumber() && info[1]->IsNumber()) {
|
||||
if (args[0]->IsNumber() && args[1]->IsNumber()) {
|
||||
int width, height;
|
||||
|
||||
width = info[0]->Uint32Value();
|
||||
height = info[1]->Uint32Value();
|
||||
width = args[0]->Uint32Value();
|
||||
height = args[1]->Uint32Value();
|
||||
mat = *(new cv::Mat(width, height, CV_64FC1));
|
||||
|
||||
} else if (info[0]->IsString()) {
|
||||
std::string filename = std::string(*Nan::Utf8String(info[0]->ToString()));
|
||||
} else if (args[0]->IsString()) {
|
||||
std::string filename = std::string(*NanUtf8String(args[0]->ToString()));
|
||||
mat = cv::imread(filename);
|
||||
|
||||
} else if (Buffer::HasInstance(info[0])) {
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(info[0]->ToObject());
|
||||
unsigned len = Buffer::Length(info[0]->ToObject());
|
||||
} else if (Buffer::HasInstance(args[0])) {
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
|
||||
unsigned len = Buffer::Length(args[0]->ToObject());
|
||||
|
||||
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
|
||||
mat = cv::imdecode(*mbuf, -1);
|
||||
|
||||
if (mat.empty()) {
|
||||
argv[0] = Nan::Error("Error loading file");
|
||||
argv[0] = NanError("Error loading file");
|
||||
}
|
||||
}
|
||||
|
||||
img->mat = mat;
|
||||
} catch (cv::Exception& e) {
|
||||
argv[0] = Nan::Error(e.what());
|
||||
argv[1] = Nan::Null();
|
||||
argv[0] = NanError(e.what());
|
||||
argv[1] = NanNull();
|
||||
}
|
||||
|
||||
TryCatch try_catch;
|
||||
cb->Call(Nan::GetCurrentContext()->Global(), 2, argv);
|
||||
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
FatalException(try_catch);
|
||||
}
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
24
src/OpenCV.h
Normal file → Executable file
24
src/OpenCV.h
Normal file → Executable file
@ -15,34 +15,34 @@ using namespace v8;
|
||||
using namespace node;
|
||||
|
||||
#define REQ_FUN_ARG(I, VAR) \
|
||||
if (info.Length() <= (I) || !info[I]->IsFunction()) \
|
||||
return Nan::ThrowTypeError("Argument " #I " must be a function"); \
|
||||
Local<Function> VAR = Local<Function>::Cast(info[I]);
|
||||
if (args.Length() <= (I) || !args[I]->IsFunction()) \
|
||||
return NanThrowTypeError("Argument " #I " must be a function"); \
|
||||
Local<Function> VAR = Local<Function>::Cast(args[I]);
|
||||
|
||||
#define SETUP_FUNCTION(TYP) \
|
||||
Nan::HandleScope scope; \
|
||||
TYP *self = Nan::ObjectWrap::Unwrap<TYP>(info.This());
|
||||
NanScope(); \
|
||||
TYP *self = ObjectWrap::Unwrap<TYP>(args.This());
|
||||
|
||||
#define JSFUNC(NAME) \
|
||||
static NAN_METHOD(NAME);
|
||||
|
||||
#define JSTHROW_TYPE(ERR) \
|
||||
Nan::ThrowTypeError( ERR );
|
||||
NanThrowTypeError( ERR );
|
||||
|
||||
#define JSTHROW(ERR) \
|
||||
Nan::ThrowError( ERR );
|
||||
NanThrowError( ERR );
|
||||
|
||||
#define INT_FROM_ARGS(NAME, IND) \
|
||||
if (info[IND]->IsInt32()){ \
|
||||
NAME = info[IND]->Uint32Value(); \
|
||||
if (args[IND]->IsInt32()){ \
|
||||
NAME = args[IND]->Uint32Value(); \
|
||||
}
|
||||
|
||||
#define DOUBLE_FROM_ARGS(NAME, IND) \
|
||||
if (info[IND]->IsInt32()){ \
|
||||
NAME = info[IND]->NumberValue(); \
|
||||
if (args[IND]->IsInt32()){ \
|
||||
NAME = args[IND]->NumberValue(); \
|
||||
}
|
||||
|
||||
class OpenCV: public Nan::ObjectWrap {
|
||||
class OpenCV: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
|
||||
60
src/Point.cc
Normal file → Executable file
60
src/Point.cc
Normal file → Executable file
@ -1,72 +1,72 @@
|
||||
#include "Point.h"
|
||||
#include "OpenCV.h"
|
||||
|
||||
Nan::Persistent<FunctionTemplate> Point::constructor;
|
||||
v8::Persistent<FunctionTemplate> Point::constructor;
|
||||
|
||||
void Point::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(Point::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Point::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("Point").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("Point"));
|
||||
|
||||
// Prototype
|
||||
Local<ObjectTemplate> proto = ctor->PrototypeTemplate();
|
||||
Nan::SetAccessor(proto, Nan::New("x").ToLocalChecked(), GetX, RaiseImmutable);
|
||||
Nan::SetAccessor(proto, Nan::New("y").ToLocalChecked(), GetY, RaiseImmutable);
|
||||
proto->SetAccessor(NanNew("x"), GetX, RaiseImmutable);
|
||||
proto->SetAccessor(NanNew("y"), GetY, RaiseImmutable);
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "dot", Dot);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "dot", Dot);
|
||||
|
||||
target->Set(Nan::New("Point").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("Point"), ctor->GetFunction());
|
||||
};
|
||||
|
||||
NAN_METHOD(Point::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
return Nan::ThrowTypeError("Cannot Instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
return NanThrowTypeError("Cannot Instantiate without new");
|
||||
}
|
||||
|
||||
double x = 0, y = 0;
|
||||
if (info[0]->IsNumber()) {
|
||||
x = info[0]->NumberValue();
|
||||
if (args[0]->IsNumber()) {
|
||||
x = args[0]->NumberValue();
|
||||
}
|
||||
if (info[1]->IsNumber()) {
|
||||
y = info[1]->NumberValue();
|
||||
if (args[1]->IsNumber()) {
|
||||
y = args[1]->NumberValue();
|
||||
}
|
||||
Point *pt = new Point(x, y);
|
||||
pt->Wrap(info.This());
|
||||
info.GetReturnValue().Set(info.This());
|
||||
pt->Wrap(args.This());
|
||||
NanReturnValue(args.This());
|
||||
}
|
||||
|
||||
NAN_GETTER(Point::GetX) {
|
||||
Nan::HandleScope scope;
|
||||
Point *pt = Nan::ObjectWrap::Unwrap<Point>(info.This());
|
||||
info.GetReturnValue().Set(Nan::New<Number>(pt->point.x));
|
||||
NanScope();
|
||||
Point *pt = ObjectWrap::Unwrap<Point>(args.This());
|
||||
NanReturnValue(NanNew<Number>(pt->point.x));
|
||||
}
|
||||
|
||||
NAN_GETTER(Point::GetY) {
|
||||
Nan::HandleScope scope;
|
||||
Point *pt = Nan::ObjectWrap::Unwrap<Point>(info.This());
|
||||
info.GetReturnValue().Set(Nan::New<Number>(pt->point.y));
|
||||
NanScope();
|
||||
Point *pt = ObjectWrap::Unwrap<Point>(args.This());
|
||||
NanReturnValue(NanNew<Number>(pt->point.y));
|
||||
}
|
||||
|
||||
NAN_SETTER(Point::RaiseImmutable) {
|
||||
Nan::ThrowTypeError("Point is immutable");
|
||||
NanThrowTypeError("Point is immutable");
|
||||
}
|
||||
|
||||
NAN_METHOD(Point::Dot) {
|
||||
Nan::HandleScope scope;
|
||||
Point *p1 = Nan::ObjectWrap::Unwrap<Point>(info.This());
|
||||
Point *p2 = Nan::ObjectWrap::Unwrap<Point>(info[0]->ToObject());
|
||||
NanScope();
|
||||
Point *p1 = ObjectWrap::Unwrap<Point>(args.This());
|
||||
Point *p2 = ObjectWrap::Unwrap<Point>(args[0]->ToObject());
|
||||
|
||||
// Since V 2.3 Native Dot no longer supported
|
||||
info.GetReturnValue().Set(Nan::New<Number>(p1->point.x * p2->point.x + p1->point.y * p2->point.y));
|
||||
NanReturnValue(NanNew<Number>(p1->point.x * p2->point.x + p1->point.y * p2->point.y));
|
||||
}
|
||||
|
||||
Point::Point(double x, double y) :
|
||||
Nan::ObjectWrap() {
|
||||
ObjectWrap() {
|
||||
point = cvPoint2D32f(x, y);
|
||||
}
|
||||
|
||||
4
src/Point.h
Normal file → Executable file
4
src/Point.h
Normal file → Executable file
@ -2,10 +2,10 @@
|
||||
|
||||
#include "OpenCV.h"
|
||||
|
||||
class Point: public Nan::ObjectWrap {
|
||||
class Point: public node::ObjectWrap {
|
||||
public:
|
||||
CvPoint2D32f point;
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
Point(double x, double y);
|
||||
|
||||
218
src/Stereo.cc
218
src/Stereo.cc
@ -4,54 +4,54 @@
|
||||
|
||||
// Block matching
|
||||
|
||||
Nan::Persistent<FunctionTemplate> StereoBM::constructor;
|
||||
v8::Persistent<FunctionTemplate> StereoBM::constructor;
|
||||
|
||||
void StereoBM::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(StereoBM::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoBM::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("StereoBM").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("StereoBM"));
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "compute", Compute);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
|
||||
ctor->Set(Nan::New<String>("BASIC_PRESET").ToLocalChecked(), Nan::New<Integer>((int)cv::StereoBM::BASIC_PRESET));
|
||||
ctor->Set(Nan::New<String>("FISH_EYE_PRESET").ToLocalChecked(), Nan::New<Integer>((int)cv::StereoBM::FISH_EYE_PRESET));
|
||||
ctor->Set(Nan::New<String>("NARROW_PRESET").ToLocalChecked(), Nan::New<Integer>((int)cv::StereoBM::NARROW_PRESET));
|
||||
ctor->Set(NanNew<String>("BASIC_PRESET"), NanNew<Integer>((int)cv::StereoBM::BASIC_PRESET));
|
||||
ctor->Set(NanNew<String>("FISH_EYE_PRESET"), NanNew<Integer>((int)cv::StereoBM::FISH_EYE_PRESET));
|
||||
ctor->Set(NanNew<String>("NARROW_PRESET"), NanNew<Integer>((int)cv::StereoBM::NARROW_PRESET));
|
||||
|
||||
target->Set(Nan::New("StereoBM").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("StereoBM"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(StereoBM::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
Nan::ThrowTypeError("Cannot instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
}
|
||||
|
||||
StereoBM *stereo;
|
||||
|
||||
if (info.Length() == 0) {
|
||||
if (args.Length() == 0) {
|
||||
stereo = new StereoBM();
|
||||
} else if (info.Length() == 1) {
|
||||
} else if (args.Length() == 1) {
|
||||
// preset
|
||||
stereo = new StereoBM(info[0]->IntegerValue());
|
||||
} else if (info.Length() == 2) {
|
||||
stereo = new StereoBM(args[0]->IntegerValue());
|
||||
} else if (args.Length() == 2) {
|
||||
// preset, disparity search range
|
||||
stereo = new StereoBM(info[0]->IntegerValue(), info[1]->IntegerValue());
|
||||
stereo = new StereoBM(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||
} else {
|
||||
stereo = new StereoBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
stereo = new StereoBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
// preset, disparity search range, sum of absolute differences window size
|
||||
info[2]->IntegerValue());
|
||||
args[2]->IntegerValue());
|
||||
}
|
||||
|
||||
stereo->Wrap(info.Holder());
|
||||
info.GetReturnValue().Set(info.Holder());
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
StereoBM::StereoBM(int preset, int ndisparities, int SADWindowSize) :
|
||||
Nan::ObjectWrap(),
|
||||
ObjectWrap(),
|
||||
stereo(preset, ndisparities, SADWindowSize) {
|
||||
}
|
||||
|
||||
@ -63,17 +63,17 @@ NAN_METHOD(StereoBM::Compute) {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject());
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
|
||||
// Optional 3rd arg, the disparty depth
|
||||
int type = CV_16S;
|
||||
if (info.Length() > 2) {
|
||||
type = info[2]->IntegerValue();
|
||||
if (args.Length() > 2) {
|
||||
type = args[2]->IntegerValue();
|
||||
}
|
||||
|
||||
// Compute stereo using the block matching algorithm
|
||||
@ -82,108 +82,108 @@ NAN_METHOD(StereoBM::Compute) {
|
||||
|
||||
// Wrap the returned disparity map
|
||||
Local < Object > disparityWrap =
|
||||
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = Nan::ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
|
||||
info.GetReturnValue().Set(disparityWrap);
|
||||
NanReturnValue(disparityWrap);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// Semi-Global Block matching
|
||||
Nan::Persistent<FunctionTemplate> StereoSGBM::constructor;
|
||||
v8::Persistent<FunctionTemplate> StereoSGBM::constructor;
|
||||
|
||||
void StereoSGBM::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(StereoSGBM::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoSGBM::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("StereoSGBM").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("StereoSGBM"));
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "compute", Compute);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
|
||||
target->Set(Nan::New("StereoSGBM").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("StereoSGBM"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(StereoSGBM::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0) {
|
||||
Nan::ThrowTypeError("Cannot instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
}
|
||||
|
||||
StereoSGBM *stereo;
|
||||
|
||||
if (info.Length() == 0) {
|
||||
if (args.Length() == 0) {
|
||||
stereo = new StereoSGBM();
|
||||
} else {
|
||||
// If passing arguments, must pass the first 3 at least
|
||||
if (info.Length() >= 3) {
|
||||
switch (info.Length()) {
|
||||
if (args.Length() >= 3) {
|
||||
switch (args.Length()) {
|
||||
case 3:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue());
|
||||
break;
|
||||
case 4:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue(), info[3]->IntegerValue());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue());
|
||||
break;
|
||||
case 5:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue(), info[3]->IntegerValue(), info[4]->IntegerValue());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue());
|
||||
break;
|
||||
case 6:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue(), info[3]->IntegerValue(), info[4]->IntegerValue(),
|
||||
info[5]->IntegerValue());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue());
|
||||
break;
|
||||
case 7:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue(), info[3]->IntegerValue(), info[4]->IntegerValue(),
|
||||
info[5]->IntegerValue(), info[6]->IntegerValue());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue());
|
||||
break;
|
||||
case 8:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue(), info[3]->IntegerValue(), info[4]->IntegerValue(),
|
||||
info[5]->IntegerValue(), info[6]->IntegerValue(), info[7]->IntegerValue());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue());
|
||||
break;
|
||||
case 9:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue(), info[3]->IntegerValue(), info[4]->IntegerValue(),
|
||||
info[5]->IntegerValue(), info[6]->IntegerValue(), info[7]->IntegerValue(),
|
||||
info[8]->IntegerValue());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(),
|
||||
args[8]->IntegerValue());
|
||||
break;
|
||||
case 10:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue(), info[3]->IntegerValue(), info[4]->IntegerValue(),
|
||||
info[5]->IntegerValue(), info[6]->IntegerValue(), info[7]->IntegerValue(),
|
||||
info[8]->IntegerValue(), info[9]->IntegerValue());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(),
|
||||
args[8]->IntegerValue(), args[9]->IntegerValue());
|
||||
break;
|
||||
default:
|
||||
stereo = new StereoSGBM(info[0]->IntegerValue(), info[1]->IntegerValue(),
|
||||
info[2]->IntegerValue(), info[3]->IntegerValue(), info[4]->IntegerValue(),
|
||||
info[5]->IntegerValue(), info[6]->IntegerValue(), info[7]->IntegerValue(),
|
||||
info[8]->IntegerValue(), info[9]->IntegerValue(), info[10]->ToBoolean()->Value());
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(),
|
||||
args[8]->IntegerValue(), args[9]->IntegerValue(), args[10]->ToBoolean()->Value());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Nan::ThrowError("If overriding default settings, must pass minDisparity, numDisparities, and SADWindowSize");
|
||||
return;
|
||||
NanThrowError("If overriding default settings, must pass minDisparity, numDisparities, and SADWindowSize");
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
stereo->Wrap(info.Holder());
|
||||
info.GetReturnValue().Set(info.Holder());
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
StereoSGBM::StereoSGBM() :
|
||||
Nan::ObjectWrap(),
|
||||
ObjectWrap(),
|
||||
stereo() {
|
||||
|
||||
}
|
||||
@ -191,7 +191,7 @@ StereoSGBM::StereoSGBM() :
|
||||
StereoSGBM::StereoSGBM(int minDisparity, int ndisparities, int SADWindowSize,
|
||||
int p1, int p2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio,
|
||||
int speckleWindowSize, int speckleRange, bool fullDP) :
|
||||
Nan::ObjectWrap(),
|
||||
ObjectWrap(),
|
||||
stereo(minDisparity, ndisparities, SADWindowSize, p1, p2, disp12MaxDiff,
|
||||
preFilterCap, uniquenessRatio, speckleWindowSize, speckleRange, fullDP) {
|
||||
}
|
||||
@ -204,11 +204,11 @@ NAN_METHOD(StereoSGBM::Compute) {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject());
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
|
||||
// Compute stereo using the block matching algorithm
|
||||
@ -217,59 +217,59 @@ NAN_METHOD(StereoSGBM::Compute) {
|
||||
|
||||
// Wrap the returned disparity map
|
||||
Local < Object > disparityWrap =
|
||||
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = Nan::ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
|
||||
info.GetReturnValue().Set(disparityWrap);
|
||||
NanReturnValue(disparityWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// Graph cut
|
||||
|
||||
Nan::Persistent<FunctionTemplate> StereoGC::constructor;
|
||||
v8::Persistent<FunctionTemplate> StereoGC::constructor;
|
||||
|
||||
void StereoGC::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(StereoGC::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoGC::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("StereoGC").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("StereoGC"));
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "compute", Compute);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
|
||||
target->Set(Nan::New("StereoGC").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("StereoGC"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(StereoGC::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0)
|
||||
Nan::ThrowTypeError("Cannot instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
|
||||
StereoGC *stereo;
|
||||
|
||||
if (info.Length() == 0) {
|
||||
if (args.Length() == 0) {
|
||||
stereo = new StereoGC();
|
||||
} else if (info.Length() == 1) {
|
||||
} else if (args.Length() == 1) {
|
||||
// numberOfDisparities
|
||||
stereo = new StereoGC(info[0]->IntegerValue());
|
||||
stereo = new StereoGC(args[0]->IntegerValue());
|
||||
} else {
|
||||
// max iterations
|
||||
stereo = new StereoGC(info[0]->IntegerValue(), info[1]->IntegerValue());
|
||||
stereo = new StereoGC(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||
}
|
||||
|
||||
stereo->Wrap(info.Holder());
|
||||
info.GetReturnValue().Set(info.Holder());
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
StereoGC::StereoGC(int numberOfDisparities, int maxIters) :
|
||||
Nan::ObjectWrap() {
|
||||
ObjectWrap() {
|
||||
stereo = cvCreateStereoGCState(numberOfDisparities, maxIters);
|
||||
}
|
||||
|
||||
@ -281,11 +281,11 @@ NAN_METHOD(StereoGC::Compute) {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject());
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
|
||||
// Compute stereo using the block matching algorithm
|
||||
@ -301,14 +301,14 @@ NAN_METHOD(StereoGC::Compute) {
|
||||
|
||||
// Wrap the returned disparity map
|
||||
Local < Object > disparityWrap =
|
||||
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = Nan::ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
|
||||
info.GetReturnValue().Set(disparityWrap);
|
||||
NanReturnValue(disparityWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
Nan::ThrowError(err_msg);
|
||||
return;
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
12
src/Stereo.h
12
src/Stereo.h
@ -3,11 +3,11 @@
|
||||
|
||||
#include "OpenCV.h"
|
||||
|
||||
class StereoBM: public Nan::ObjectWrap {
|
||||
class StereoBM: public node::ObjectWrap {
|
||||
public:
|
||||
cv::StereoBM stereo;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
@ -18,11 +18,11 @@ public:
|
||||
;
|
||||
};
|
||||
|
||||
class StereoSGBM: public Nan::ObjectWrap {
|
||||
class StereoSGBM: public node::ObjectWrap {
|
||||
public:
|
||||
cv::StereoSGBM stereo;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
@ -37,11 +37,11 @@ public:
|
||||
|
||||
struct CvStereoGCState;
|
||||
|
||||
class StereoGC: public Nan::ObjectWrap {
|
||||
class StereoGC: public node::ObjectWrap {
|
||||
public:
|
||||
CvStereoGCState *stereo;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
|
||||
156
src/VideoCaptureWrap.cc
Normal file → Executable file
156
src/VideoCaptureWrap.cc
Normal file → Executable file
@ -5,11 +5,11 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
Nan::Persistent<FunctionTemplate> VideoCaptureWrap::constructor;
|
||||
v8::Persistent<FunctionTemplate> VideoCaptureWrap::constructor;
|
||||
|
||||
struct videocapture_baton {
|
||||
|
||||
Nan::Persistent<Function> cb;
|
||||
Persistent<Function> cb;
|
||||
VideoCaptureWrap *vc;
|
||||
Matrix *im;
|
||||
|
||||
@ -17,124 +17,124 @@ struct videocapture_baton {
|
||||
};
|
||||
|
||||
void VideoCaptureWrap::Init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
//Class
|
||||
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(VideoCaptureWrap::New);
|
||||
constructor.Reset(ctor);
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(VideoCaptureWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(Nan::New("VideoCapture").ToLocalChecked());
|
||||
ctor->SetClassName(NanNew("VideoCapture"));
|
||||
|
||||
// Prototype
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
Nan::SetPrototypeMethod(ctor, "read", Read);
|
||||
Nan::SetPrototypeMethod(ctor, "setWidth", SetWidth);
|
||||
Nan::SetPrototypeMethod(ctor, "setHeight", SetHeight);
|
||||
Nan::SetPrototypeMethod(ctor, "setPosition", SetPosition);
|
||||
Nan::SetPrototypeMethod(ctor, "close", Close);
|
||||
Nan::SetPrototypeMethod(ctor, "ReadSync", ReadSync);
|
||||
Nan::SetPrototypeMethod(ctor, "grab", Grab);
|
||||
Nan::SetPrototypeMethod(ctor, "retrieve", Retrieve);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "read", Read);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setWidth", SetWidth);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setHeight", SetHeight);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setPosition", SetPosition);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "close", Close);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "ReadSync", ReadSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "grab", Grab);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "retrieve", Retrieve);
|
||||
|
||||
target->Set(Nan::New("VideoCapture").ToLocalChecked(), ctor->GetFunction());
|
||||
target->Set(NanNew("VideoCapture"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::New) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
if (info.This()->InternalFieldCount() == 0)
|
||||
return Nan::ThrowTypeError("Cannot Instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
return NanThrowTypeError("Cannot Instantiate without new");
|
||||
|
||||
VideoCaptureWrap *v;
|
||||
|
||||
if (info[0]->IsNumber()) {
|
||||
v = new VideoCaptureWrap(info[0]->NumberValue());
|
||||
if (args[0]->IsNumber()) {
|
||||
v = new VideoCaptureWrap(args[0]->NumberValue());
|
||||
} else {
|
||||
//TODO - assumes that we have string, verify
|
||||
v = new VideoCaptureWrap(std::string(*Nan::Utf8String(info[0]->ToString())));
|
||||
v = new VideoCaptureWrap(std::string(*NanAsciiString(args[0]->ToString())));
|
||||
}
|
||||
|
||||
v->Wrap(info.This());
|
||||
v->Wrap(args.This());
|
||||
|
||||
info.GetReturnValue().Set(info.This());
|
||||
NanReturnValue(args.This());
|
||||
}
|
||||
|
||||
VideoCaptureWrap::VideoCaptureWrap(int device) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
cap.open(device);
|
||||
|
||||
if(!cap.isOpened()) {
|
||||
Nan::ThrowError("Camera could not be opened");
|
||||
NanThrowError("Camera could not be opened");
|
||||
}
|
||||
}
|
||||
|
||||
VideoCaptureWrap::VideoCaptureWrap(const std::string& filename) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
cap.open(filename);
|
||||
// TODO! At the moment this only takes a full path - do relative too.
|
||||
if(!cap.isOpened()) {
|
||||
Nan::ThrowError("Video file could not be opened (opencv reqs. non relative paths)");
|
||||
NanThrowError("Video file could not be opened (opencv reqs. non relative paths)");
|
||||
}
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::SetWidth) {
|
||||
Nan::HandleScope scope;
|
||||
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
if(info.Length() != 1)
|
||||
return;
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
int w = info[0]->IntegerValue();
|
||||
int w = args[0]->IntegerValue();
|
||||
|
||||
if(v->cap.isOpened())
|
||||
v->cap.set(CV_CAP_PROP_FRAME_WIDTH, w);
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::SetHeight) {
|
||||
Nan::HandleScope scope;
|
||||
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
if(info.Length() != 1)
|
||||
return;
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
int h = info[0]->IntegerValue();
|
||||
int h = args[0]->IntegerValue();
|
||||
|
||||
v->cap.set(CV_CAP_PROP_FRAME_HEIGHT, h);
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::SetPosition) {
|
||||
Nan::HandleScope scope;
|
||||
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
if(info.Length() != 1)
|
||||
return;
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
int pos = info[0]->IntegerValue();
|
||||
int pos = args[0]->IntegerValue();
|
||||
|
||||
v->cap.set(CV_CAP_PROP_POS_FRAMES, pos);
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::Close) {
|
||||
Nan::HandleScope scope;
|
||||
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
v->cap.release();
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
class AsyncVCWorker: public Nan::AsyncWorker {
|
||||
class AsyncVCWorker: public NanAsyncWorker {
|
||||
public:
|
||||
AsyncVCWorker(Nan::Callback *callback, VideoCaptureWrap* vc,
|
||||
AsyncVCWorker(NanCallback *callback, VideoCaptureWrap* vc,
|
||||
bool retrieve = false, int channel = 0) :
|
||||
Nan::AsyncWorker(callback),
|
||||
NanAsyncWorker(callback),
|
||||
vc(vc),
|
||||
retrieve(retrieve),
|
||||
channel(channel) {
|
||||
@ -161,14 +161,14 @@ public:
|
||||
// this function will be run inside the main event loop
|
||||
// so it is safe to use V8 again
|
||||
void HandleOKCallback() {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
|
||||
Local<Object> im_to_return= Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(im_to_return);
|
||||
Local<Object> im_to_return= NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_to_return);
|
||||
img->mat = mat;
|
||||
|
||||
Local<Value> argv[] = {
|
||||
Nan::Null()
|
||||
NanNull()
|
||||
, im_to_return
|
||||
};
|
||||
|
||||
@ -187,33 +187,33 @@ private:
|
||||
};
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::Read) {
|
||||
Nan::HandleScope scope;
|
||||
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
REQ_FUN_ARG(0, cb);
|
||||
|
||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||
Nan::AsyncQueueWorker(new AsyncVCWorker(callback, v));
|
||||
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||
NanAsyncQueueWorker(new AsyncVCWorker(callback, v));
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::ReadSync) {
|
||||
Nan::HandleScope scope;
|
||||
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
Local<Object> im_to_return= Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(im_to_return);
|
||||
Local<Object> im_to_return= NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_to_return);
|
||||
|
||||
v->cap.read(img->mat);
|
||||
|
||||
info.GetReturnValue().Set(im_to_return);
|
||||
NanReturnValue(im_to_return);
|
||||
}
|
||||
|
||||
class AsyncGrabWorker: public Nan::AsyncWorker {
|
||||
class AsyncGrabWorker: public NanAsyncWorker {
|
||||
public:
|
||||
AsyncGrabWorker(Nan::Callback *callback, VideoCaptureWrap* vc) :
|
||||
Nan::AsyncWorker(callback),
|
||||
AsyncGrabWorker(NanCallback *callback, VideoCaptureWrap* vc) :
|
||||
NanAsyncWorker(callback),
|
||||
vc(vc) {
|
||||
}
|
||||
|
||||
@ -231,27 +231,27 @@ private:
|
||||
};
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::Grab) {
|
||||
Nan::HandleScope scope;
|
||||
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
REQ_FUN_ARG(0, cb);
|
||||
|
||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||
Nan::AsyncQueueWorker(new AsyncGrabWorker(callback, v));
|
||||
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||
NanAsyncQueueWorker(new AsyncGrabWorker(callback, v));
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::Retrieve) {
|
||||
Nan::HandleScope scope;
|
||||
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
int channel = 0;
|
||||
REQ_FUN_ARG(0, cb);
|
||||
INT_FROM_ARGS(channel, 1);
|
||||
|
||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||
Nan::AsyncQueueWorker(new AsyncVCWorker(callback, v, true, channel));
|
||||
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||
NanAsyncQueueWorker(new AsyncVCWorker(callback, v, true, channel));
|
||||
|
||||
return;
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
4
src/VideoCaptureWrap.h
Normal file → Executable file
4
src/VideoCaptureWrap.h
Normal file → Executable file
@ -1,10 +1,10 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class VideoCaptureWrap: public Nan::ObjectWrap {
|
||||
class VideoCaptureWrap: public node::ObjectWrap {
|
||||
public:
|
||||
cv::VideoCapture cap;
|
||||
|
||||
static Nan::Persistent<FunctionTemplate> constructor;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
|
||||
2
src/init.cc
Normal file → Executable file
2
src/init.cc
Normal file → Executable file
@ -16,7 +16,7 @@
|
||||
#include "BackgroundSubtractor.h"
|
||||
|
||||
extern "C" void init(Handle<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
NanScope();
|
||||
OpenCV::Init(target);
|
||||
|
||||
Point::Init(target);
|
||||
|
||||
@ -24,5 +24,3 @@ apt-get -y install libgtk2.0-dev
|
||||
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
|
||||
make install
|
||||
cd /home/vagrant/$REPO_FOLDER/
|
||||
|
||||
npm install node-gyp -g
|
||||
Loading…
x
Reference in New Issue
Block a user