{"id":16758139,"url":"https://github.com/foo123/haarphp","last_synced_at":"2025-04-10T17:11:44.465Z","repository":{"id":2591672,"uuid":"3573522","full_name":"foo123/HAARPHP","owner":"foo123","description":"Feature Detection based on Haar Cascades in PHP (Viola-Jones-Lienhart et al Algorithm)","archived":false,"fork":false,"pushed_at":"2023-08-24T07:26:46.000Z","size":1202,"stargazers_count":15,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-24T14:51:22.951Z","etag":null,"topics":["computer-vision","object-detection","viola-jones"],"latest_commit_sha":null,"homepage":"https://foo123.github.io/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foo123.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-02-28T17:30:17.000Z","updated_at":"2024-02-14T00:21:29.000Z","dependencies_parsed_at":"2025-02-17T16:46:36.972Z","dependency_job_id":null,"html_url":"https://github.com/foo123/HAARPHP","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FHAARPHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FHAARPHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FHAARPHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FHAARPHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foo123","download_url":"https://codeload.github.com/foo123/HAARPHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248261713,"owners_count":21074223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","object-detection","viola-jones"],"created_at":"2024-10-13T04:04:16.691Z","updated_at":"2025-04-10T17:11:44.434Z","avatar_url":"https://github.com/foo123.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HAARPHP \n\n\n__Feature Detection Library for PHP__\n\nBased on [Viola-Jones Feature Detection Algorithm using Haar Cascades](http://www.cs.cmu.edu/~efros/courses/LBMV07/Papers/viola-cvpr-01.pdf)\nand improvement [Viola-Jones-Lienhart et al Feature Detection Algorithm](http://www.multimedia-computing.de/mediawiki//images/5/52/MRL-TR-May02-revised-Dec02.pdf)\n\nThis is a port of [OpenCV C++ Haar Detection](https://github.com/opencv/opencv) and of [JViolaJones Java](http://code.google.com/p/jviolajones/)) to PHP.\n\n\n**there is also a [`javascript` version: HAAR.js](https://github.com/foo123/HAAR.js)**\n\n\n![screenshot](/example-screenshot.png)\n\n### Contents\n\n* [How to Use](#how-to-use)\n* [Detector Methods](#detector-methods)\n* [Haar Cascades](#where-to-find-haar-cascades-xml-files-to-use-for-feature-detection)\n* [Todo](#todo)\n* [Changelog](#changelog)\n\n\n### How to Use\nYou can use the __existing openCV cascades__  to build your detectors.\n\nTo do this just transform the __opencv xml file__ to *PHP* format\nusing the __haartophp__ (php) tool (in cascades folder)\n\n__examples:__\n\nto use opencv's *haarcascades_frontalface_alt.xml*  in *php* do:\n\n```bash\nhaartophp haarcascades_frontalface_alt.xml \u003e haarcascades_frontalface_alt.php\n```\n\nthis creates a `php` file: `haarcascades_frontalface_alt.php`\nwhich you can include in your `php` application (see examples)\n\nthe variable to use in php is similarly: `$haarcascades_frontalface_alt`\n\n\n#### Detector Methods\n\n__constructor()__\n```php\nnew HaarDetector($haardata);\n```\n\n__Explanation of parameters__\n\n* `$haardata` : The actual haardata (as generated by `haartophp` tool), this is specific per feature, openCV haar data can be used.\n\n\n\n__clearCache()__\n```php\n$detector-\u003eclearCache();\n```\n\nClear 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\n\n\n\n__cascade()__\n```php\n$detector-\u003ecascade($haardata);\n```\n\nAllow 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\n\n__Explanation of parameters__\n\n* `$haardata` : The actual haardata (as generated by `haartophp` tool), this is specific per feature, openCV haar data can be used.\n\n\n\n__image()__\n```php\n$detector-\u003eimage($GDImage, $scale = 1.0);\n```\n\n__Explanation of parameters__\n\n* `$GDImage` : an actual `GD` Image object.\n* `$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)\n\n\n\n__selection()__\n```php\n$detector-\u003eselection('auto'|array|feature|$x [,$y, $width, $height]);\n```\n\nGet/Set a custom region in the image to confine the detection process only in that region (eg detect nose while face already detected)\n\n__Explanation of parameters__\n\n* `1st parameter` : This can be the string `'auto'` which sets the whole image as the selection, or an array ie: `array('x'=\u003e10, 'y'=\u003e'auto', 'width'=\u003e100, 'height'=\u003e'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).\n* `$y` : (Optional) the selection start y coordinate, can be an actual value or `'auto'` (`$y=0`)\n* `$width` : (Optional) the selection width, can be an actual value or `'auto'` (`$width=image.width`)\n* `$height` : (Optional) the selection height, can be an actual value or `'auto'` (`$height=image.height`)\n\nThe actual selection rectangle/feature is available as `$this-\u003eselection()` or `$detector-\u003eselection()` with no parameters\n\n\n\n__cannyThreshold()__\n```php\n$detector-\u003ecannyThreshold(array('low'=\u003e lowThreshold, 'high'=\u003e highThreshold));\n```\n\nSet the thresholds when Canny Pruning is used, for extra fine-tuning. \nCanny 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. \nDefault values work fine in most cases, however depending on image size and the specific feature, some fine tuning could be needed\n\n__Explanation of parameters__\n\n* `low` : (Optional) The low threshold (default __20__ ).\n* `high` : (Optional) The high threshold (default __100__ ).\n\n\n\n\n__detect()__\n```php\n$detector-\u003edetect($baseScale = 1, $scale_inc = 1.25, $increment = 0.1, $min_neighbors = 1 , $epsilon = 0.2, $doCannyPruning = false);\n```\n\n__Explanation of parameters__ ([JViolaJones Parameters](http://code.google.com/p/jviolajones/wiki/Parameters))\n\n* `$baseScale` : The initial ratio between the window size and the Haar classifier size (default __1__ ).\n* `$scale_inc` : The scale increment of the window size, at each step (default __1.25__ ).\n* `$increment` : The shift of the window at each sub-step, in terms of percentage of the window size (default __0.1__ ).\n* `$min_neighbors` : The minimum numbers of similar rectangles needed for the region to be considered as a feature (avoid noise) (default __1__ )\n* `$epsilon` : Epsilon value that determines similarity between detected rectangles. `0` means identical (default __0.2__ )\n* `$doCannyPruning` : enable Canny Pruning to pre-detect regions unlikely to contain features, in order to speed up the execution (optional default __false__ ). \n\n\n__Examples included with face detection__\n\n\n\n### Where to find Haar Cascades XML files to use for feature detection\n\n* [OpenCV](http://opencv.org/)\n* [This resource](http://alereimondo.no-ip.org/OpenCV/34)\n* search the web :)\n* [Train your own](http://docs.opencv.org/doc/user_guide/ug_traincascade.html) with a little extra help [here](http://note.sonots.com/SciSoftware/haartraining.html) and [here](http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html)\n\n\n#### TODO\n\n- [ ] keep up with the changes in openCV cascades xml format (will try)\n\n\n#### ChangeLog\n\n__1.0.6__\n* correction when selection is used again (revert to previous code)\n\n__1.0.5__\n* correction when selection is used, use same version as HAAR.js\n* implicit type casting warnings in php 8 handled\n\n__1.0.2__\n* port code from latest version of opencv\n\n__1.0.1__\n* inline detection routine for further speed\n* update test examples with many faces detection\n\n__1.0.0__\n* correct detection on custom selection\n* refactor code\n\n__0.4__\n* refactor code (make smaller)\n* add clearCache method, to delete any stored/cached image data in the detector (in case space is an issue)\n* add the tilted feature (Lienhart et al, extension)\n* make new `haartophp` tool, output format changed, __make sure to re-convert your `.php` haar cascades!!__\n* tidy up the repo\n* fix some typos, edits\n\n\n__0.3__\n* add new methods (_selection_ , _cascade_ , _cannyThreshold_ )\n* use fixed-point arithmetic if possible (eg gray-scale, canny computation)\n* optimize array indexing, remove unnecessary multiplications\n* reduce unnecessary loops, inline code instead of method calling for speed\n* rewrite _merge_ method (features might be slightly different now)\n* features are now generic classes not arrays\n* code refactor/fixes\n* update readme, add method documentation\n\n\n__0.2__\n* add haartophp tool in php (all-php solution)\n* optimize array operations, refactor, etc..\n\n\n__0.1__\n* initial release\n\n**see also:**\n\n* [Abacus](https://github.com/foo123/Abacus) advanced Combinatorics and Algebraic Number Theory Symbolic Computation library for JavaScript, Python\n* [MOD3](https://github.com/foo123/MOD3) 3D Modifier Library in JavaScript\n* [Geometrize](https://github.com/foo123/Geometrize) Computational Geometry and Rendering Library for JavaScript\n* [Plot.js](https://github.com/foo123/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\n* [HAAR.js](https://github.com/foo123/HAAR.js) image feature detection based on Haar Cascades in JavaScript (Viola-Jones-Lienhart et al Algorithm)\n* [HAARPHP](https://github.com/foo123/HAARPHP) image feature detection based on Haar Cascades in PHP (Viola-Jones-Lienhart et al Algorithm)\n* [FILTER.js](https://github.com/foo123/FILTER.js) video and image processing and computer vision Library in pure JavaScript (browser and node)\n* [Xpresion](https://github.com/foo123/Xpresion) a simple and flexible eXpression parser engine (with custom functions and variables support), based on [GrammarTemplate](https://github.com/foo123/GrammarTemplate), for PHP, JavaScript, Python\n* [Regex Analyzer/Composer](https://github.com/foo123/RegexAnalyzer) Regular Expression Analyzer and Composer for PHP, JavaScript, Python\n* [GrammarTemplate](https://github.com/foo123/GrammarTemplate) grammar-based templating for PHP, JavaScript, Python\n* [codemirror-grammar](https://github.com/foo123/codemirror-grammar) transform a formal grammar in JSON format into a syntax-highlight parser for CodeMirror editor\n* [ace-grammar](https://github.com/foo123/ace-grammar) transform a formal grammar in JSON format into a syntax-highlight parser for ACE editor\n* [prism-grammar](https://github.com/foo123/prism-grammar) transform a formal grammar in JSON format into a syntax-highlighter for Prism code highlighter\n* [highlightjs-grammar](https://github.com/foo123/highlightjs-grammar) transform a formal grammar in JSON format into a syntax-highlight mode for Highlight.js code highlighter\n* [syntaxhighlighter-grammar](https://github.com/foo123/syntaxhighlighter-grammar) transform a formal grammar in JSON format to a highlight brush for SyntaxHighlighter code highlighter\n* [SortingAlgorithms](https://github.com/foo123/SortingAlgorithms) implementations of Sorting Algorithms in JavaScript\n* [PatternMatchingAlgorithms](https://github.com/foo123/PatternMatchingAlgorithms) implementations of Pattern Matching Algorithms in JavaScript\n* [CanvasLite](https://github.com/foo123/CanvasLite) an html canvas implementation in pure JavaScript\n* [Rasterizer](https://github.com/foo123/Rasterizer) stroke and fill lines, rectangles, curves and paths, without canvaσ\n* [Gradient](https://github.com/foo123/Gradient) create linear, radial, conic and elliptic gradients and image patterns without canvas\n* [css-color](https://github.com/foo123/css-color) simple class to parse and manipulate colors in various formats\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoo123%2Fhaarphp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoo123%2Fhaarphp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoo123%2Fhaarphp/lists"}