opencv4nodejs
Advanced tools
Comparing version 2.9.0 to 2.10.0
const path = require('path'); | ||
let binding; | ||
let cv; | ||
if (process.env.BINDINGS_DEBUG) { | ||
binding = require('../build/Debug/opencv4nodejs'); | ||
cv = require('../build/Debug/opencv4nodejs'); | ||
} else { | ||
binding = require('../build/Release/opencv4nodejs'); | ||
cv = require('../build/Release/opencv4nodejs'); | ||
} | ||
const { resolvePath } = require('./utils'); | ||
const promisify = require('./promisify'); | ||
// resolve haarcascade files | ||
const { haarCascades } = binding; | ||
const { haarCascades } = cv; | ||
Object.keys(haarCascades).forEach( | ||
key => binding[key] = resolvePath(path.join(__dirname, './haarcascades'), haarCascades[key])); | ||
key => cv[key] = resolvePath(path.join(__dirname, './haarcascades'), haarCascades[key])); | ||
module.exports = binding; | ||
// promisify async methods | ||
cv = promisify(cv); | ||
module.exports = cv; |
{ | ||
"name": "opencv4nodejs", | ||
"version": "2.9.0", | ||
"version": "2.10.0", | ||
"description": "Asynchronous OpenCV 3.x API for node.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,3 +8,3 @@ opencv4nodejs | ||
**By it's nature, JavaScript lacks the performance to implement Computer Vision tasks efficiently. Therefore this package brings the performance of the native OpenCV C++ library to your Node.js application. Bindings to OpenCV 3 are available as an asynchronous (currently under construction) and synchronous API.** | ||
**By it's nature, JavaScript lacks the performance to implement Computer Vision tasks efficiently. Therefore this package brings the performance of the native OpenCV C++ library to your Node.js application. Bindings to OpenCV 3 are available as an asynchronous (callbacked and promisified, currently under construction) and synchronous API.** | ||
@@ -17,2 +17,3 @@ * **[Examples](#examples)** | ||
* **[Quick Start](#quick-start)** | ||
* **[Async API](#async-api)** | ||
* **[Available Modules](#available-modules)** | ||
@@ -325,2 +326,43 @@ * **[Request new Features](#request-features)** | ||
<a name="async-api"></a> | ||
## Async API | ||
The async API can be consumed by passing a callback as the last argument of the function call. By default, if an async method is called without passing a callback, the function call will yield a Promise. | ||
### Async Face Detection | ||
``` javascript | ||
const classifier = new cv.CascadeClassifier(cv.HAAR_FRONTALFACE_ALT2); | ||
// by nesting callbacks | ||
cv.imreadAsync('./faceimg.jpg', (err, img) => { | ||
if (err) { return console.error(err); } | ||
const grayImg = img.bgrToGray(); | ||
classifier.detectMultiScaleAsync(grayImg, (err, res) => { | ||
if (err) { return console.error(err); } | ||
const { objects, numDetections } = res; | ||
... | ||
}); | ||
}); | ||
// via Promise | ||
cv.imreadAsync('./faceimg.jpg') | ||
.then(img => classifier.detectMultiScaleAsync(img.bgrToGray()).then(res => ({ res, img }))) | ||
.then(({ res, img }) => { | ||
const { objects, numDetections } = res; | ||
... | ||
}) | ||
.catch(err => console.error(err)); | ||
// using async await | ||
const img = await cv.imreadAsync('./faceimg.jpg'); | ||
const grayImg = img.bgrToGray(); | ||
const { objects, numDetections } = await classifier.detectMultiScaleAsync(grayImg); | ||
... | ||
``` | ||
<a name="available-modules"></a> | ||
@@ -327,0 +369,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10094085
165
177
390