Git Product home page Git Product logo

haarphp's Introduction

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

see also:

  • Abacus advanced Combinatorics and Algebraic Number Theory Symbolic Computation library for JavaScript, Python
  • MOD3 3D Modifier Library in JavaScript
  • Geometrize Computational Geometry and Rendering Library for JavaScript
  • Plot.js simple and small library which can plot graphs of functions and various simple charts and can render to Canvas, SVG and plain HTML
  • HAAR.js image feature detection based on Haar Cascades in JavaScript (Viola-Jones-Lienhart et al Algorithm)
  • HAARPHP image feature detection based on Haar Cascades in PHP (Viola-Jones-Lienhart et al Algorithm)
  • FILTER.js video and image processing and computer vision Library in pure JavaScript (browser and node)
  • Xpresion a simple and flexible eXpression parser engine (with custom functions and variables support), based on GrammarTemplate, for PHP, JavaScript, Python
  • Regex Analyzer/Composer Regular Expression Analyzer and Composer for PHP, JavaScript, Python
  • GrammarTemplate grammar-based templating for PHP, JavaScript, Python
  • codemirror-grammar transform a formal grammar in JSON format into a syntax-highlight parser for CodeMirror editor
  • ace-grammar transform a formal grammar in JSON format into a syntax-highlight parser for ACE editor
  • prism-grammar transform a formal grammar in JSON format into a syntax-highlighter for Prism code highlighter
  • highlightjs-grammar transform a formal grammar in JSON format into a syntax-highlight mode for Highlight.js code highlighter
  • syntaxhighlighter-grammar transform a formal grammar in JSON format to a highlight brush for SyntaxHighlighter code highlighter
  • SortingAlgorithms implementations of Sorting Algorithms in JavaScript
  • PatternMatchingAlgorithms implementations of Pattern Matching Algorithms in JavaScript

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

  • $haardata : The actual haardata (as generated by haartophp tool), this is specific per feature, openCV haar data can be used.

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

  • $haardata : The actual haardata (as generated by haartophp tool), this is specific per feature, openCV haar data can be used.

image()

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

Explanation of parameters

  • $GDImage : an actual GD Image object.
  • $scale : The percent of scaling from the original image, so detection proceeds faster on a smaller image (default 1.0 ). NOTE scaling might alter the detection results sometimes, if having problems opt towards 1 (slower)

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

  • 1st parameter : This can be the string 'auto' which sets the whole image as the selection, or an array ie: array('x'=>10, 'y'=>'auto', 'width'=>100, 'height'=>'auto') (every param set as 'auto' will take the default image value) or a detection rectangle/feature, or a x coordinate (along with rest coordinates).
  • $y : (Optional) the selection start y coordinate, can be an actual value or 'auto' ($y=0)
  • $width : (Optional) the selection width, can be an actual value or 'auto' ($width=image.width)
  • $height : (Optional) the selection height, can be an actual value or 'auto' ($height=image.height)

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

  • low : (Optional) The low threshold (default 20 ).
  • high : (Optional) The high threshold (default 100 ).

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)

  • $baseScale : The initial ratio between the window size and the Haar classifier size (default 1 ).
  • $scale_inc : The scale increment of the window size, at each step (default 1.25 ).
  • $increment : The shift of the window at each sub-step, in terms of percentage of the window size (default 0.1 ).
  • $min_neighbors : The minimum numbers of similar rectangles needed for the region to be considered as a feature (avoid noise) (default 1 )
  • $epsilon : Epsilon value that determines similarity between detected rectangles. 0 means identical (default 0.2 )
  • $doCannyPruning : enable Canny Pruning to pre-detect regions unlikely to contain features, in order to speed up the execution (optional default false ).

Examples included with face detection

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

TODO

  • keep up with the changes in openCV cascades xml format (will try)

ChangeLog

1.0.2

  • port code from latest version of opencv

1.0.1

  • inline detection routine for further speed
  • update test examples with many faces detection

1.0.0

  • correct detection on custom selection
  • refactor code

0.4

  • refactor code (make smaller)
  • add clearCache method, to delete any stored/cached image data in the detector (in case space is an issue)
  • add the tilted feature (Lienhart et al, extension)
  • make new haartophp tool, output format changed, make sure to re-convert your .php haar cascades!!
  • tidy up the repo
  • fix some typos, edits

0.3

  • add new methods (selection , cascade , cannyThreshold )
  • use fixed-point arithmetic if possible (eg gray-scale, canny computation)
  • optimize array indexing, remove unnecessary multiplications
  • reduce unnecessary loops, inline code instead of method calling for speed
  • rewrite merge method (features might be slightly different now)
  • features are now generic classes not arrays
  • code refactor/fixes
  • update readme, add method documentation

0.2

  • add haartophp tool in php (all-php solution)
  • optimize array operations, refactor, etc..

0.1

  • initial release

haarphp's People

Contributors

foo123 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.