Home

Awesome

HAARPHP

Feature Detection Library for PHP

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 PHP.

there is also a javascript version: HAAR.js

screenshot

Contents

How to Use

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

To do this just transform the opencv xml file to PHP format using the haartophp (php) tool (in cascades folder)

examples:

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

haartophp haarcascades_frontalface_alt.xml > haarcascades_frontalface_alt.php

this creates a php file: haarcascades_frontalface_alt.php which you can include in your php application (see examples)

the variable to use in php is similarly: $haarcascades_frontalface_alt

Detector Methods

constructor()

new HaarDetector($haardata);

Explanation of parameters

clearCache()

$detector->clearCache();

Clear any cached image data and haardata in case space is an issue. Use image method and cascade method (see below) to re-set image and haar data

cascade()

$detector->cascade($haardata);

Allow to use same detector (with its cached image data), to detect different feature on same image, by using another cascade. This way any image pre-processing is done only once

Explanation of parameters

image()

$detector->image($GDImage, $scale = 1.0);

Explanation of parameters

selection()

$detector->selection('auto'|array|feature|$x [,$y, $width, $height]);

Get/Set a custom region in the image to confine the detection process only in that region (eg detect nose while face already detected)

Explanation of parameters

The actual selection rectangle/feature is available as $this->selection() or $detector->selection() with no parameters

cannyThreshold()

$detector->cannyThreshold(array('low'=> lowThreshold, 'high'=> highThreshold));

Set the thresholds when Canny Pruning is used, for extra fine-tuning. Canny Pruning detects the number/density of edges in a given region. A region with too few or too many edges is unlikely to be a feature. Default values work fine in most cases, however depending on image size and the specific feature, some fine tuning could be needed

Explanation of parameters

detect()

$detector->detect($baseScale = 1, $scale_inc = 1.25, $increment = 0.1, $min_neighbors = 1 , $epsilon = 0.2, $doCannyPruning = false);

Explanation of parameters (JViolaJones Parameters)

Examples included with face detection

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

TODO

ChangeLog

1.0.6

1.0.5

1.0.2

1.0.1

1.0.0

0.4

0.3

0.2

0.1

see also: