####Detector Methods
constructor(haardata, Parallel)
new detector(haardata, Parallel);
Explanation of parameters
- haardata : The actual haardata (as generated by haartojs tool), this is specific per feature, openCV haar data can be used.
- Parallel : Optional, this is the Parallel object, as returned by the parallel.js script (included). It enables HAAR.js to run parallel computations both in browser and node (can be much faster)
dispose()
detector.dispose();
Disposes the detector and clears space of data cached
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(haardata)
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 haartojs tool), this is specific per feature, openCV haar data can be used.
parallel(Parallel)
detector.paralell(Parallel | false);
Enable/disable parallel processing (passing the Parallel Object or null/false)
Explanation of parameters
- Parallel : The actual Parallel object used in parallel.js (included)
image(ImageOrVideoOrCanvas, scale, CanvasClass)
detector.image(ImageOrVideoOrCanvas, scale, CanvasClass);
Explanation of parameters
- ImageOrVideoOrCanvas : an actual Image or Video element or Canvas Object (in this case they are equivalent).
- scale : The percent of scaling from the original image, so detection proceeds faster on a smaller image (default 0.5 ). NOTE scaling might alter the detection results sometimes, if having problems opt towards 1 (slower)
- CanvasClass : This is optional and used only when running in node (passing the node-canvas object).
interval(detectionInterval)
detector.interval(detectionInterval);
Explanation of parameters
- detectionInterval : interval to run the detection asynchronously (if not parallel) in microseconds (default 30).
cannyThreshold({low: lowThreshold, high: highThreshold})
detector.cannyThreshold({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 ).
select|selection('auto'|object|feature|x [,y, width, height])
detector.selection('auto'|object|feature|x [,y, width, height]);
Allow to 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 object ie: {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
complete(callback)
detector.complete(callback);
Set the callback handler when detection completes (for parallel and asynchronous detection)
Explanation of parameters
- callback : The user-defined callback function (will be called within the detectors scope, the value of 'this' will be the detector instance).
detect(baseScale, scale_inc, increment, min_neighbors, doCannyPruning)
detector.detect(baseScale, scale_inc, increment, min_neighbors, doCannyPruning);
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.5 ).
- min_neighbors : The minimum numbers of similar rectangles needed for the region to be considered as a feature (avoid noise) (default 1 )
- doCannyPruning : enable Canny Pruning to pre-detect regions unlikely to contain features, in order to speed up the execution (optional default true ).