Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
justadudewhohacks committed Jul 25, 2017
0 parents commit 180657e
Show file tree
Hide file tree
Showing 34 changed files with 5,531 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vs
.vs
.vscode
build
node_modules
94 changes: 94 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"targets": [
{
"target_name": "opencv4nodejs",
"include_dirs" : [
"$(OPENCV_DIR)/include",
"$(EIGEN_DIR)",
"C:/Users/user/Documents/dev/cpp/installs/TheiaSfM-0.7/include",
"C:/Users/user/Documents/dev/cpp/installs/TheiaSfM-0.7/src",
"C:/Users/user/Documents/dev/cpp/installs/sfm/glog-0.3.5/build/include",
"C:/Users/user/Documents/dev/cpp/installs/TheiaSfM-0.7/libraries/cereal/include",
"C:/Users/user/Documents/dev/cpp/installs/sfm/ceres-solver-1.13.0rc1/include",
"C:/Users/user/Documents/dev/cpp/installs/GL/freeglut-3.0.0/include",
"C:/Users/user/Documents/dev/cpp/installs/GL/glew-1.13.0/include",
"<!(node -e \"require('nan')\")"
],
"libraries": [
"$(OPENCV_LIB_DIR)/opencv_core320.lib",
"$(OPENCV_LIB_DIR)/opencv_highgui320.lib",
"$(OPENCV_LIB_DIR)/opencv_imgcodecs320.lib",
"$(OPENCV_LIB_DIR)/opencv_imgproc320.lib",
"$(OPENCV_LIB_DIR)/opencv_features2d320.lib",
"$(OPENCV_LIB_DIR)/opencv_xfeatures2d320.lib",
"$(OPENCV_LIB_DIR)/opencv_photo320.lib",
"$(OPENCV_LIB_DIR)/opencv_videostab320.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/glog-0.3.5/build/Release/glog.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/gflags-2.2.1/build-x64/lib/Release/gflags_static.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/ceres-solver-1.13.0rc1/build/lib/Release/ceres.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/build/lib/Release/libspqr.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/build/lib/Release/libcholmod.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/build/lib/Release/libccolamd.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/build/lib/Release/libcamd.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/build/lib/Release/libcolamd.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/build/lib/Release/libamd.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/lapack_windows/x64/liblapack.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/lapack_windows/x64/libblas.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/build/lib/Release/suitesparseconfig.lib",
"C:/Users/user/Documents/dev/cpp/installs/sfm/suitesparse-win/build/lib/Release/metis.lib",
"$(THEIA_LIB_DIR)/akaze.lib",
"$(THEIA_LIB_DIR)/build_reconstruction.lib",
"$(THEIA_LIB_DIR)/build_1dsfm_reconstruction.lib",
"$(THEIA_LIB_DIR)/compute_two_view_geometry.lib",
"$(THEIA_LIB_DIR)/flann_cpp.lib",
"$(THEIA_LIB_DIR)/flann_cpp_s.lib",
"$(THEIA_LIB_DIR)/statx.lib",
"$(THEIA_LIB_DIR)/stlplus3.lib",
"$(THEIA_LIB_DIR)/visual_sfm.lib",
"$(THEIA_LIB_DIR)/vlfeat.lib",
"$(THEIA_LIB_DIR)/theia.lib",
"C:/Users/user/Documents/dev/cpp/installs/GL/freeglut-3.0.0/lib/x64/freeglut.lib",
"C:/Users/user/Documents/dev/cpp/installs/GL/glew-1.13.0/lib/Release/x64/glew32.lib"
],
"sources": [
"cc/index.cc",
"cc/core/Mat.cc",
"cc/KeyPoint.cc",
"cc/KeyPointMatch.cc",
"cc/modules/io.cc",
"cc/modules/features2d.cc",
"cc/modules/photo.cc",
"cc/modules/sfm/sfm.cc",
"cc/modules/sfm/RelativePose.cc",
"cc/modules/sfm/Camera.cc",
"cc/modules/sfm/WorldPoint.cc"
],

"cflags!" : [ "-fno-exceptions"],
"cflags_cc!": [ "-fno-rtti", "-fno-exceptions"],

"conditions": [
[ "OS==\"win\"", {
"cflags": [
"-Wall"
],
"defines": [
"WIN",
"_HAS_EXCEPTIONS=1"
],
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": "2",
"RuntimeLibrary": "2",
'AdditionalOptions': [
'/GR',
'/MD',
'/EHsc'
]
},
}
}]
]
}
]
}
83 changes: 83 additions & 0 deletions cc/KeyPoint.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "KeyPoint.h"
#include "macros.h"

Nan::Persistent<v8::FunctionTemplate> KeyPoint::constructor;

NAN_MODULE_INIT(KeyPoint::Init) {
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(KeyPoint::New);
constructor.Reset(ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(Nan::New("KeyPoint").ToLocalChecked());

Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("localId").ToLocalChecked(), GetLocalId);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("x").ToLocalChecked(), GetX);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("y").ToLocalChecked(), GetY);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("angle").ToLocalChecked(), GetAngle);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("classId").ToLocalChecked(), GetClassId);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("response").ToLocalChecked(), GetResponse);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("size").ToLocalChecked(), GetSize);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("octave").ToLocalChecked(), GetOctave);

target->Set(Nan::New("KeyPoint").ToLocalChecked(), ctor->GetFunction());
};

NAN_METHOD(KeyPoint::New) {
if (info.Length() > 0) {
// TODO check args
KeyPoint *keyPoint = new KeyPoint();
v8::Local<v8::Object> jsKp = info[0]->ToObject();
keyPoint->setNativeProps(
(uint)Nan::Get(jsKp, Nan::New("localId").ToLocalChecked()).ToLocalChecked()->NumberValue(),
cv::KeyPoint(
FF_GET_JS_PROP_FLOAT(jsKp, x),
FF_GET_JS_PROP_FLOAT(jsKp, y),
FF_GET_JS_PROP_FLOAT(jsKp, size),
FF_GET_JS_PROP_FLOAT(jsKp, angle),
FF_GET_JS_PROP_FLOAT(jsKp, response),
FF_GET_JS_PROP_INT(jsKp, octave),
FF_GET_JS_PROP_INT(jsKp, classId)
)
);
keyPoint->Wrap(info.Holder());
} else {
(new KeyPoint())->Wrap(info.Holder());
}
info.GetReturnValue().Set(info.Holder());
}

NAN_GETTER(KeyPoint::GetLocalId) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPoint>(info.This())->localId);
}

NAN_GETTER(KeyPoint::GetX) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPoint>(info.This())->keyPoint.pt.x);
}

NAN_GETTER(KeyPoint::GetY) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPoint>(info.This())->keyPoint.pt.y);
}

NAN_GETTER(KeyPoint::GetAngle) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPoint>(info.This())->keyPoint.angle);
}

NAN_GETTER(KeyPoint::GetClassId) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPoint>(info.This())->keyPoint.class_id);
}

NAN_GETTER(KeyPoint::GetResponse) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPoint>(info.This())->keyPoint.response);
}

NAN_GETTER(KeyPoint::GetSize) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPoint>(info.This())->keyPoint.size);
}

NAN_GETTER(KeyPoint::GetOctave) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPoint>(info.This())->keyPoint.octave);
}

void KeyPoint::setNativeProps(uint localId, cv::KeyPoint keyPoint) {
this->localId = localId;
this->keyPoint = keyPoint;
};
33 changes: 33 additions & 0 deletions cc/KeyPoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <nan.h>
#include <opencv2/imgproc.hpp>
#include <opencv2/features2d.hpp>

class KeyPoint : public Nan::ObjectWrap {
public:
uint localId;
cv::KeyPoint keyPoint;

static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);
static NAN_GETTER(GetLocalId);
static NAN_GETTER(GetX);
static NAN_GETTER(GetY);
static NAN_GETTER(GetAngle);
static NAN_GETTER(GetClassId);
static NAN_GETTER(GetResponse);
static NAN_GETTER(GetSize);
static NAN_GETTER(GetOctave);

static Nan::Persistent<v8::FunctionTemplate> constructor;

static std::vector<cv::KeyPoint> unwrapJSKps(v8::Local<v8::Array> jsKps) {
std::vector<cv::KeyPoint> kps;
for (uint i = 0; i < jsKps->Length(); i++) {
KeyPoint* kp = Nan::ObjectWrap::Unwrap<KeyPoint>(Nan::To<v8::Object>(jsKps->Get(i)).ToLocalChecked());
kps.push_back(kp->keyPoint);
}
return kps;
};

void setNativeProps(uint localId, cv::KeyPoint);
};
51 changes: 51 additions & 0 deletions cc/KeypointMatch.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "KeyPointMatch.h"

Nan::Persistent<v8::FunctionTemplate> KeyPointMatch::constructor;

NAN_MODULE_INIT(KeyPointMatch::Init) {
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(KeyPointMatch::New);
constructor.Reset(ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(Nan::New("KeyPointMatch").ToLocalChecked());

Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("kpFrom").ToLocalChecked(), GetKpFrom);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("kpTo").ToLocalChecked(), GetKpTo);
Nan::SetAccessor(ctor->InstanceTemplate(), Nan::New("distance").ToLocalChecked(), GetDistance);

target->Set(Nan::New("KeyPointMatch").ToLocalChecked(), ctor->GetFunction());
};

NAN_METHOD(KeyPointMatch::New) {
if (info.Length() > 0) {
// TODO check args
KeyPointMatch *keyPointMatch = new KeyPointMatch();
keyPointMatch->setNativeProps(
Nan::ObjectWrap::Unwrap<KeyPoint>(info[0]->ToObject()),
Nan::ObjectWrap::Unwrap<KeyPoint>(info[1]->ToObject()),
(float)info[2]->NumberValue()
);
keyPointMatch->Wrap(info.Holder());
} else {
(new KeyPointMatch())->Wrap(info.Holder());
}

info.GetReturnValue().Set(info.Holder());
}

NAN_GETTER(KeyPointMatch::GetKpFrom) {
info.GetReturnValue().Set(Nan::New(Nan::ObjectWrap::Unwrap<KeyPointMatch>(info.This())->kpFrom));
}

NAN_GETTER(KeyPointMatch::GetKpTo) {
info.GetReturnValue().Set(Nan::New(Nan::ObjectWrap::Unwrap<KeyPointMatch>(info.This())->kpTo));
}

NAN_GETTER(KeyPointMatch::GetDistance) {
info.GetReturnValue().Set(Nan::ObjectWrap::Unwrap<KeyPointMatch>(info.This())->distance);
}

void KeyPointMatch::setNativeProps(KeyPoint* kpFrom, KeyPoint* kpTo, float distance) {
this->kpFrom.Reset(kpFrom->persistent());
this->kpTo.Reset(kpTo->persistent());
this->distance = distance;
}
28 changes: 28 additions & 0 deletions cc/KeypointMatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <nan.h>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include "KeyPoint.h"

class KeyPointMatch : public Nan::ObjectWrap {
public:
Nan::Persistent<v8::Object> kpFrom;
Nan::Persistent<v8::Object> kpTo;
float distance;

static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);
static NAN_GETTER(GetKpFrom);
static NAN_GETTER(GetKpTo);
static NAN_GETTER(GetDistance);

static Nan::Persistent<v8::FunctionTemplate> constructor;

void setNativeProps(KeyPoint* kpFrom, KeyPoint* kpTo, float distance);
KeyPoint* getKpFrom() {
return Nan::ObjectWrap::Unwrap<KeyPoint>(Nan::New(this->kpFrom));
}

KeyPoint* getKpTo() {
return Nan::ObjectWrap::Unwrap<KeyPoint>(Nan::New(this->kpTo));
}
};
Loading

0 comments on commit 180657e

Please sign in to comment.