Reputation: 133
I recently installed OpenCV through npm using the following guide: https://www.npmjs.com/package/opencv
My question is pretty simple. How do I actually use the OpenCV library in my project?
On that site, there is a face detection example that looks like this:
cv.readImage("./examples/files/mona.png", function(err, im){
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
for (var i=0;i<faces.length; i++){
var x = faces[i]
im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);
}
im.save('./out.jpg');
});
})
The cv.
variable is where I'm stuck at. Typically whenever I install a new package using npm, I would add it to my app.js
file like so:
angular
.module('App', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'ui.sortable',
'firebase',
'angular-toArrayFilter'
])
Similarly in any of my controllers, I would add the name of the module as a parameter to the controller:
angular.module('App')
.controller('LoginCtrl', function ($scope, UserAuth, $window, $firebaseArray, fireBaseRef)
I can't seem to find the dependency name for OpenCV to even allow me to use it in the first place. None of the guides that I've looked at to date ever mention how to include it into your project.
Thanks for your time!
Upvotes: 2
Views: 4620
Reputation: 11
Follow the installation instructions for whatever your operating system is (i.e. Mac OSX, Windows, Linux/Debian). Instructions for the most popular systems can be found here: https://www.npmjs.com/package/opencv.
Then, before using the 'cv' variable you must require the 'opencv' module.
var cv = require('opencv');
If you receive an error, it will usually be a dependency issue. Verify that you have correctly installed all the dependencies for node-opencv. On my first install I needed
npm install buffers
and
npm install node-pre-gyp
Depending on where you installed your opencv bundle, you may need to explicitly include the file path to the opencv.js file like so
var cv = require('/path_to_node-opencv-master/lib/opencv');
I recommend reading the intro to OpenCV articles and the documentation on the OpenCV website at http://opencv.org/ to learn more.
Upvotes: 0
Reputation: 21
You can't use OpenCV in browser-side javascript projects. OpenCV is a native library and node-opencv
allows you to use it on the server, but you cannot use it directly in the browser.
From the installation instructions for node-opencv
:
You'll need OpenCV 2.3.1 or newer installed before installing node-opencv. Note that OpenCV 3.x is not yet fully supported.
Upvotes: 1