Home

Awesome

HAAR.js

Note: FILTER.js project, for Image Processing and Computer Vision, includes a HaarDetector plugin which can be seen as the continuation of this project.

Feature Detection Library for JavaScript (uses HTML5 canvas on browser and canvas alternative on Node)

Based on Viola-Jones Feature Detection Algorithm using Haar Cascades and improvement Viola-Jones-Lienhart et al Feature Detection Algorithm

This is a port of OpenCV C++ Haar Detection and of JViolaJones Java) to JavaScript.

there is also a php version: HAARPHP

Light-weight (~11kB minified, ~5kB gzipped).

Haar.js Face Detection Haar.js Many Faces Detection Haar.js Mouth Detection Haar.js Eyes Detection

Contents

Live Examples

How To use

You can use the existing openCV cascades to build your detectors.

To do this just transform the opencv xml file to javascript or json format using the haartojs (php) tool (in cascades folder)

examples:

to use opencv's haarcascades_frontalface_alt.xml in javascript do:

haartojs haarcascades_frontalface_alt.xml > haarcascades_frontalface_alt.js

this creates a javascript file: haarcascades_frontalface_alt.js which you can include in your html file or node file

the variable to use in javascript is similarly haarcascades_frontalface_alt (both in browser and node)

to transform a cascade xml file to json format do:

haartojson haarcascades_frontalface_alt.xml > haarcascades_frontalface_alt.json

The structure of the .js and .json formats is exactly the same, so you can interchange between the two freely

HAAR.js works both in the browser and in Node.js (supporting parallel computations with Parallel.js)

NOTE HAAR.js (0.4.4+) (and the generated cascades) support umd-style generic loading capability for: commonjs / node , amd , browsers script tags

Runing inside the browser

Loading with script tags.

You can run the example face.html or mouth.html inside your browser.

Running inside node

For running in nodejs, the package has a dependency on canvas.

Canvas alternatives for nodejs:

  1. CanvasLite
  2. node-canvas

To work properly node-canvas needs some system dependencies. You can find instruction on https://github.com/Automattic/node-canvas/wiki

You can find an example inside examples/nodes.js for both alternatives.

Example Output

node examples/node.js
processing the picture
[{"x":84,"y":90,"width":202,"height":202,"area":40804}]

Loading with requirejs

As a third option, you can load the library with requireJS, both in the browser in node. There is an example of loading with RequireJS inside node in examples/require.js. The configuration would be the same inside a browser

Supporting parallel computation

The parallel.js library is included in this repository, see the face.html example for how to use. In most cases using parallel computation (if supported) can be much faster (eg eye.html example)

Where to find Haar Cascades xml files to use for feature detection

Usage Ideas

TODO

see also: