foo123/HAAR.js
Feature Detection based on Haar Cascades in JavaScript (Viola-Jones-Lienhart et al Algorithm)
What it solves
HAAR.js brings classic image feature detection—like finding faces, eyes, or mouths in a picture—to JavaScript. It lets web and Node.js developers detect objects in images without needing a heavy computer-vision library or a server, using the well-known Viola-Jones Haar cascade algorithm.
How it works
The library scans an image (drawn on an HTML5 canvas in the browser, or a canvas alternative in Node) using a trained "Haar cascade"—a set of simple pattern tests that together decide whether a region contains the target feature. You supply the cascade as a file. HAAR.js includes tools to convert standard OpenCV cascade XML files into JavaScript or JSON format, so you can reuse existing trained models. It also supports parallel computation via Parallel.js to speed up detection on capable browsers.
Who it’s for
Developers building browser-based or Node.js applications that need real-time or offline object/feature detection (for example, face detection in a webcam feed or photo upload). It’s also useful for anyone who wants a lightweight, self-contained alternative to OpenCV in JavaScript, and who is comfortable converting OpenCV cascade files.
Highlights
- Lightweight: about 11 kB minified, ~5 kB gzipped
- Works in both browser and Node.js (with a canvas alternative)
- Can reuse existing OpenCV Haar cascade XML files by converting them to JS or JSON
- Supports parallel computation with Parallel.js for faster detection
- Includes live interactive examples for face, many-faces, and mouth detection
- Also has a PHP version (HAARPHP) for server-side use
Related
- Project
- Project
- Project
- Project