Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 4920f5c

Browse files
committed
Merge branch 'master' into facemark
2 parents bed0691 + 5ab4fcb commit 4920f5c

File tree

5 files changed

+121
-39
lines changed

5 files changed

+121
-39
lines changed

README.md

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ opencv4nodejs
1111
[![node version](https://img.shields.io/badge/node.js-%3E=_6-green.svg?style=flat)](http://nodejs.org/download/)
1212
[![Slack](https://slack.bri.im/badge.svg)](https://slack.bri.im/)
1313

14-
**By its nature, JavaScript lacks the performance to implement Computer Vision tasks efficiently. Therefore this package brings the performance of the native OpenCV library to your Node.js application. Supports all OpenCV 3 versions. The bindings are available as an asynchronous (via promises or callbacks) and synchronous API.**
14+
**By its nature, JavaScript lacks the performance to implement Computer Vision tasks efficiently. Therefore this package brings the performance of the native OpenCV library to your Node.js application. This project targets OpenCV 3 and provides an asynchronous as well as an synchronous API.**
1515

16-
**The ultimate goal of this project is to provide a collection of Node.js bindings, which supports the entire OpenCV and OpenCV-contrib API. An overview of available bindings can be found in the [API Documentation](https://opencv4nodejs.herokuapp.com/docs). The implementation of missing bindings can be specifically prioritized by [requesting new features](#request-features). Furthermore, contribution is highly appreciated. If you want to get involved you can have a look at the <a href="https://github.com/justadudewhohacks/opencv4nodejs/tree/master/CONTRIBUTING.md"><b>contribution guide</b>.**
16+
**The ultimate goal of this project is to provide a comprehensive collection of Node.js bindings to the API of OpenCV and the OpenCV-contrib modules. An overview of available bindings can be found in the [API Documentation](https://justadudewhohacks.github.io/opencv4nodejs). Furthermore, contribution is highly appreciated. If you want to get involved you can have a look at the <a href="https://github.com/justadudewhohacks/opencv4nodejs/tree/master/CONTRIBUTING.md"><b>contribution guide</b>.**
1717

1818
* **[Examples](#examples)**
1919
* **[How to install](#how-to-install)**
@@ -25,7 +25,6 @@ opencv4nodejs
2525
* **[With TypeScript](#with-typescript)**
2626
* **[External Memory Tracking (v4.0.0)](#external-mem-tracking)**
2727
* **[Available Modules](#available-modules)**
28-
* **[Request new Features](#request-features)**
2928

3029
<a name="examples"></a>
3130

@@ -204,7 +203,7 @@ const matFromArray = new cv.Mat(matData, cv.CV_8UC3);
204203

205204
// from node buffer
206205
const charData = [255, 0, ...];
207-
const matFromArray = new cv.Mat(new Buffer.from(charData), rows, cols, cv.CV_8UC3);
206+
const matFromArray = new cv.Mat(Buffer.from(charData), rows, cols, cv.CV_8UC3);
208207

209208
// Point
210209
const pt2 = new cv.Point(100, 100);
@@ -451,6 +450,7 @@ try {
451450
```
452451

453452
<a name="with-typescript"></a>
453+
454454
# With TypeScript
455455

456456
``` javascript
@@ -463,9 +463,9 @@ Check out the TypeScript [examples](https://github.com/justadudewhohacks/opencv4
463463

464464
# External Memory Tracking (v4.0.0)
465465

466-
Since version 4.0.0 external memory tracking will be enabled by default. Simply put, the memory allocated for Matrices (cv.Mat) will be manually reported to the node process. This solves the issue of inconsistent Garbage Collection, which could have resulted in spiking memory usage of the node process eventually leading to overflowing the RAM of your system, prior to version 4.0.0.
466+
Since version 4.0.0 was released, external memory tracking has been enabled by default. Simply put, the memory allocated for Matrices (cv.Mat) will be manually reported to the node process. This solves the issue of inconsistent Garbage Collection, which could have resulted in spiking memory usage of the node process eventually leading to overflowing the RAM of your system, prior to version 4.0.0.
467467

468-
Note, that in doubt this feature can be **disabled** by setting and environment variable `OPENCV4NODEJS_DISABLE_EXTERNAL_MEM_TRACKING` before requiring the module:
468+
Note, that in doubt this feature can be **disabled** by setting an environment variable `OPENCV4NODEJS_DISABLE_EXTERNAL_MEM_TRACKING` before requiring the module:
469469

470470
``` bash
471471
export OPENCV4NODEJS_DISABLE_EXTERNAL_MEM_TRACKING=1 // linux
@@ -482,28 +482,20 @@ const cv = require('opencv4nodejs')
482482

483483
# Available Modules
484484

485-
### <a href="https://opencv4nodejs.herokuapp.com/docs"><b>API doc overview</b></a>
486-
487-
* <a href="https://opencv4nodejs.herokuapp.com/docs/core"><b>core</b></a>
488-
* <a href="https://opencv4nodejs.herokuapp.com/docs/io"><b>io</b></a>
489-
* <a href="https://opencv4nodejs.herokuapp.com/docs/imgproc"><b>imgproc</b></a>
490-
* <a href="https://opencv4nodejs.herokuapp.com/docs/ximgproc"><b>ximgproc</b></a>
491-
* <a href="https://opencv4nodejs.herokuapp.com/docs/objdetect"><b>objdetect</b></a>
492-
* <a href="https://opencv4nodejs.herokuapp.com/docs/machinelearning"><b>machinelearning</b></a>
493-
* <a href="https://opencv4nodejs.herokuapp.com/docs/dnn"><b>deepneuralnetworks</b></a>
494-
* <a href="https://opencv4nodejs.herokuapp.com/docs/video"><b>video</b></a>
495-
* <a href="https://opencv4nodejs.herokuapp.com/docs/calib3d"><b>calib3d</b></a>
496-
* <a href="https://opencv4nodejs.herokuapp.com/docs/photo"><b>photo</b></a>
497-
* <a href="https://opencv4nodejs.herokuapp.com/docs/features2d"><b>features2d</b></a>
498-
* <a href="https://opencv4nodejs.herokuapp.com/docs/xfeatures2d"><b>xfeatures2d</b></a>
499-
* <a href="https://opencv4nodejs.herokuapp.com/docs/tracking"><b>tracking</b></a>
500-
* <a href="https://opencv4nodejs.herokuapp.com/docs/text"><b>text</b></a>
501-
* <a href="https://opencv4nodejs.herokuapp.com/docs/face"><b>face</b></a>
502-
503-
<a name="request-features"></a>
504-
505-
## Request new Features
506-
507-
Are you missing some functions from OpenCV (<a href="https://opencv4nodejs.herokuapp.com/docs"><b>overview</b></a> of available bindings) or have an idea for utility in regards to the OpenCV API, which you would like to be added to this package? No problem! Open a new <a href="https://github.com/justadudewhohacks/opencv4nodejs/issues"><b>issue</b></a> with a listing of the desired function bindings or features and you will find them in this package soon.
508-
509-
485+
### <a href="https://justadudewhohacks.github.io/opencv4nodejs"><b>API doc overview</b></a>
486+
487+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/Mat#Mat"><b>core</b></a>
488+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/VideoCapture#VideoCapture"><b>io</b></a>
489+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/Contour#Contour"><b>imgproc</b></a>
490+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/SuperpixelLSC#SuperpixelLSC"><b>ximgproc</b></a>
491+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/CascadeClassifier#CascadeClassifier"><b>objdetect</b></a>
492+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/SVM#SVM"><b>machinelearning</b></a>
493+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/Net#Net"><b>deepneuralnetworks</b></a>
494+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/BackgroundSubtractorKNN#BackgroundSubtractorKNN"><b>video</b></a>
495+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/cv#calibrateCamera"><b>calib3d</b></a>
496+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/cv#fastNlMeansDenoisingColored"><b>photo</b></a>
497+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/AGASTDetector#AGASTDetector"><b>features2d</b></a>
498+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/SIFTDetector#SIFTDetector"><b>xfeatures2d</b></a>
499+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/MultiTracker#MultiTracker"><b>tracking</b></a>
500+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/OCRHMMClassifier#OCRHMMClassifier"><b>text</b></a>
501+
* <a href="https://justadudewhohacks.github.io/opencv4nodejs/docs/EigenFaceRecognizer#EigenFaceRecognizer"><b>face</b></a>

cc/core/Mat.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,12 @@ NAN_METHOD(Mat::Set) {
291291

292292
NAN_METHOD(Mat::GetDataAsArray) {
293293
cv::Mat mat = FF_UNWRAP_MAT_AND_GET(info.This());
294-
FF_ARR rowArray = FF_NEW_ARRAY(mat.rows);
295-
FF_MAT_APPLY_TYPED_OPERATOR(mat, rowArray, mat.type(), FF_JS_ARRAY_FROM_MAT, FF::matGet);
294+
FF_ARR rowArray = FF_NEW_ARRAY(mat.size[0]);
295+
if (mat.dims > 2) { // 3D
296+
FF_MAT_APPLY_TYPED_OPERATOR(mat, rowArray, mat.type(), FF_JS_ARRAY_FROM_MAT_3D, FF::matGet);
297+
} else { // 2D
298+
FF_MAT_APPLY_TYPED_OPERATOR(mat, rowArray, mat.type(), FF_JS_ARRAY_FROM_MAT, FF::matGet);
299+
}
296300
FF_RETURN(rowArray);
297301
}
298302

cc/core/matUtils.h

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
#ifndef __FF_MATUTILS_H__
55
#define __FF_MATUTILS_H__
66

7-
#define FF_MAT_AT(mat, val, get) \
8-
val = get(mat, info[0]->Int32Value(), info[1]->Int32Value());
7+
#define FF_MAT_AT(mat, val, get) \
8+
if (mat.dims > 2) \
9+
val = get(mat, info[0]->Int32Value(), info[1]->Int32Value(), info[2]->Int32Value()); \
10+
else \
11+
val = get(mat, info[0]->Int32Value(), info[1]->Int32Value());
912

10-
#define FF_MAT_SET(mat, val, put) \
11-
put(mat, val, info[0]->Int32Value(), info[1]->Int32Value());
13+
#define FF_MAT_SET(mat, val, put) \
14+
if (mat.dims > 2) \
15+
put(mat, val, info[0]->Int32Value(), info[1]->Int32Value(), info[2]->Int32Value()); \
16+
else \
17+
put(mat, val, info[0]->Int32Value(), info[1]->Int32Value());
1218

1319
#define FF_MAT_FILL(mat, vec, put) \
1420
for (int r = 0; r < mat.rows; r++) { \
@@ -34,6 +40,19 @@
3440
rowArray->Set(r, colArray); \
3541
}
3642

43+
#define FF_JS_ARRAY_FROM_MAT_3D(mat, rowArray, get) \
44+
for (int r = 0; r < mat.size[0]; r++) { \
45+
v8::Local<v8::Array> colArray = Nan::New<v8::Array>(mat.size[1]); \
46+
for (int c = 0; c < mat.size[1]; c++) { \
47+
v8::Local<v8::Array> depthArray = Nan::New<v8::Array>(mat.size[2]); \
48+
for (int z = 0; z < mat.size[2]; z++) { \
49+
depthArray->Set(z, get(mat, r, c, z)); \
50+
} \
51+
colArray->Set(c, depthArray); \
52+
} \
53+
rowArray->Set(r, colArray); \
54+
}
55+
3756
#define FF_MAT_APPLY_TYPED_OPERATOR(mat, arg, type, ITERATOR, OPERATOR) { \
3857
switch (type) { \
3958
case CV_8UC1: \
@@ -138,6 +157,11 @@ namespace FF {
138157
mat.at<type>(r, c) = (type)value->NumberValue();
139158
}
140159

160+
template<typename type>
161+
static inline void matPutVal(cv::Mat mat, v8::Local<v8::Value> value, int r, int c, int z) {
162+
mat.at<type>(r, c, z) = (type)value->NumberValue();
163+
}
164+
141165
template<typename type>
142166
static inline void matPutVec2(cv::Mat mat, v8::Local<v8::Value> vector, int r, int c) {
143167
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(vector);
@@ -147,6 +171,15 @@ namespace FF {
147171
);
148172
}
149173

174+
template<typename type>
175+
static inline void matPutVec2(cv::Mat mat, v8::Local<v8::Value> vector, int r, int c, int z) {
176+
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(vector);
177+
mat.at< cv::Vec<type, 2> >(r, c, z) = cv::Vec<type, 2>(
178+
(type)vec->Get(0)->NumberValue(),
179+
(type)vec->Get(1)->NumberValue()
180+
);
181+
}
182+
150183
template<typename type>
151184
static inline void matPutVec3(cv::Mat mat, v8::Local<v8::Value> vector, int r, int c) {
152185
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(vector);
@@ -157,6 +190,16 @@ namespace FF {
157190
);
158191
}
159192

193+
template<typename type>
194+
static inline void matPutVec3(cv::Mat mat, v8::Local<v8::Value> vector, int r, int c, int z) {
195+
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(vector);
196+
mat.at< cv::Vec<type, 3> >(r, c, z) = cv::Vec<type, 3>(
197+
(type)vec->Get(0)->NumberValue(),
198+
(type)vec->Get(1)->NumberValue(),
199+
(type)vec->Get(2)->NumberValue()
200+
);
201+
}
202+
160203
template<typename type>
161204
static inline void matPutVec4(cv::Mat mat, v8::Local<v8::Value> vector, int r, int c) {
162205
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(vector);
@@ -168,11 +211,27 @@ namespace FF {
168211
);
169212
}
170213

214+
template<typename type>
215+
static inline void matPutVec4(cv::Mat mat, v8::Local<v8::Value> vector, int r, int c, int z) {
216+
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(vector);
217+
mat.at< cv::Vec<type, 4> >(r, c, z) = cv::Vec<type, 4>(
218+
(type)vec->Get(0)->NumberValue(),
219+
(type)vec->Get(1)->NumberValue(),
220+
(type)vec->Get(2)->NumberValue(),
221+
(type)vec->Get(3)->NumberValue()
222+
);
223+
}
224+
171225
template<typename type>
172226
static inline v8::Local<v8::Value> matGetVal(cv::Mat mat, int r, int c) {
173227
return Nan::New(mat.at<type>(r, c));
174228
}
175229

230+
template<typename type>
231+
static inline v8::Local<v8::Value> matGetVal(cv::Mat mat, int r, int c, int z) {
232+
return Nan::New(mat.at<type>(r, c, z));
233+
}
234+
176235
template<typename type>
177236
static inline v8::Local<v8::Value> matGetVec2(cv::Mat mat, int r, int c) {
178237
v8::Local<v8::Array> vec = Nan::New<v8::Array>(2);
@@ -181,6 +240,14 @@ namespace FF {
181240
return vec;
182241
}
183242

243+
template<typename type>
244+
static inline v8::Local<v8::Value> matGetVec2(cv::Mat mat, int r, int c, int z) {
245+
v8::Local<v8::Array> vec = Nan::New<v8::Array>(2);
246+
vec->Set(0, Nan::New(mat.at< cv::Vec<type, 2> >(r, c, z)[0]));
247+
vec->Set(1, Nan::New(mat.at< cv::Vec<type, 2> >(r, c, z)[1]));
248+
return vec;
249+
}
250+
184251
template<typename type>
185252
static inline v8::Local<v8::Value> matGetVec3(cv::Mat mat, int r, int c) {
186253
v8::Local<v8::Array> vec = Nan::New<v8::Array>(3);
@@ -190,6 +257,15 @@ namespace FF {
190257
return vec;
191258
}
192259

260+
template<typename type>
261+
static inline v8::Local<v8::Value> matGetVec3(cv::Mat mat, int r, int c, int z) {
262+
v8::Local<v8::Array> vec = Nan::New<v8::Array>(3);
263+
vec->Set(0, Nan::New(mat.at< cv::Vec<type, 3> >(r, c, z)[0]));
264+
vec->Set(1, Nan::New(mat.at< cv::Vec<type, 3> >(r, c, z)[1]));
265+
vec->Set(2, Nan::New(mat.at< cv::Vec<type, 3> >(r, c, z)[2]));
266+
return vec;
267+
}
268+
193269
template<typename type>
194270
static inline v8::Local<v8::Value> matGetVec4(cv::Mat mat, int r, int c) {
195271
v8::Local<v8::Array> vec = Nan::New<v8::Array>(4);
@@ -199,6 +275,16 @@ namespace FF {
199275
vec->Set(3, Nan::New(mat.at< cv::Vec<type, 4> >(r, c)[3]));
200276
return vec;
201277
}
278+
279+
template<typename type>
280+
static inline v8::Local<v8::Value> matGetVec4(cv::Mat mat, int r, int c, int z) {
281+
v8::Local<v8::Array> vec = Nan::New<v8::Array>(4);
282+
vec->Set(0, Nan::New(mat.at< cv::Vec<type, 4> >(r, c, z)[0]));
283+
vec->Set(1, Nan::New(mat.at< cv::Vec<type, 4> >(r, c, z)[1]));
284+
vec->Set(2, Nan::New(mat.at< cv::Vec<type, 4> >(r, c, z)[2]));
285+
vec->Set(3, Nan::New(mat.at< cv::Vec<type, 4> >(r, c, z)[3]));
286+
return vec;
287+
}
202288
}
203289

204290
#endif

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencv4nodejs",
3-
"version": "4.2.1",
3+
"version": "4.3.0",
44
"description": "Asynchronous OpenCV 3.x nodejs bindings with JavaScript and TypeScript API.",
55
"keywords": [
66
"opencv",

0 commit comments

Comments
 (0)