File: LDAWrap.cc

package info (click to toggle)
node-opencv 6.0.0+git20180416.cfc96ba0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 24,632 kB
  • sloc: xml: 476,707; cpp: 5,950; makefile: 114; sh: 59; ansic: 20
file content (98 lines) | stat: -rw-r--r-- 2,561 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "OpenCV.h"

#if CV_MAJOR_VERSION >= 3
#ifdef __GNUC__
#warning TODO: port me to OpenCV 3
#else
// vs style message pragma
#pragma message ( "TODO: port me to OpenCV 3" )
#endif
#endif

#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))
#include "LDAWrap.h"
#include "Matrix.h"
#include <nan.h>

Nan::Persistent<FunctionTemplate> LDAWrap::constructor;

void LDAWrap::Init(Local<Object> target) {
  Nan::HandleScope scope;

  // Constructor
  Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(LDAWrap::New);
  constructor.Reset(ctor);
  ctor->InstanceTemplate()->SetInternalFieldCount(1);
  ctor->SetClassName(Nan::New("LDA").ToLocalChecked());

  Nan::SetMethod(ctor, "subspaceProject", SubspaceProject);
  Nan::SetMethod(ctor, "subspaceReconstruct", SubspaceReconstruct);

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

NAN_METHOD(LDAWrap::New) {
  Nan::HandleScope scope;

  if (info.This()->InternalFieldCount() == 0) {
    JSTHROW_TYPE("Cannot Instantiate without new")
  }

  LDAWrap *pt = new LDAWrap();

  pt->Wrap(info.This());
  info.GetReturnValue().Set(info.This());
}

LDAWrap::LDAWrap() {
}

/**
 * http://docs.opencv.org/master/db/d59/classcv_1_1LDA.html#a69c7019a344edc5c55799c16a9fc9ada
 */
NAN_METHOD(LDAWrap::SubspaceProject) {
  if (info.Length() != 3) {
    JSTHROW("SubspaceProject function requires 3 arguments")
  }

  // param 0 - eigenvectors
  Matrix *w = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());

  // param 1 - mean
  Matrix *mean = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject());

  // param 2 - src
  Matrix *src = Nan::ObjectWrap::Unwrap<Matrix>(info[2]->ToObject());

  cv::Mat m = cv::subspaceProject(w->mat, mean->mat, src->mat);

  Local<Object> im = Matrix::CreateWrappedFromMat(m);

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

/**
 * http://docs.opencv.org/master/db/d59/classcv_1_1LDA.html#acbf9949e7567e23af5f71c29fcef76d4
 */
NAN_METHOD(LDAWrap::SubspaceReconstruct) {
  if (info.Length() != 3) {
    JSTHROW("SubspaceReconstruct function requires 3 arguments")
  }

  // param 0 - eigenvectors
  Matrix *w = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());

  // param 1 - mean
  Matrix *mean = Nan::ObjectWrap::Unwrap<Matrix>(info[1]->ToObject());

  // param 2 - src
  Matrix *src = Nan::ObjectWrap::Unwrap<Matrix>(info[2]->ToObject());

  cv::Mat m = cv::subspaceReconstruct(w->mat, mean->mat, src->mat);

  Local<Object> im = Matrix::CreateWrappedFromMat(m);

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

#endif // End version > 2.4