jjil.algorithm
Class DetectHaarMultiScale

java.lang.Object
  extended by jjil.core.PipelineStage
      extended by jjil.algorithm.DetectHaarMultiScale

public class DetectHaarMultiScale
extends PipelineStage

DetectHaar applies a Haar cascade at multiple locations and multiple scales to an input Gray8Image. The result is a mask with the masked (non-Byte.MIN_VALUE) locations indicating the areas where the feature was detected.
The Haar cascade is applied at multiple scales, starting with the coarsest scale, and working down to the finest scale. At each scale, the cascade is applied to subimages spread across the image. If the cascade detects a feature, the area of the mask corresponding to that subimage is set to Byte.MAX_VALUE. When a subimage is to be tested, the mask is first examined to see if the central pixel in the mask area corresponding to that subimage is masked. If it is, the subimage is skipped. When transitioning to a finer scale, the mask is stretched to the new size. This results in areas where features have been detected at a coarser scale not being re-searched at a finer scale.
DetectHaarMultiScale is structured as a pipeline stage so push'ing an image results in a new mask being available on getFront. The mask can be further processed by doing connected component detection to determine the feature characteristics, or the mask can be displayed in an overlay on the original image to show the feature areas.

Author:
webb

Constructor Summary
DetectHaarMultiScale(java.io.InputStream is, int nMinScale, int nMaxScale)
          Creates a new instance of DetectHaarMultiScale.
 
Method Summary
 void push(Image image)
          Apply multi-scale Haar cascade and prepare a mask image showing where features were detected.
 void setScale(int nMinScale, int nMaxScale)
          Set minimum and maximum scale.
 
Methods inherited from class jjil.core.PipelineStage
getFront, isEmpty
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DetectHaarMultiScale

public DetectHaarMultiScale(java.io.InputStream is,
                            int nMinScale,
                            int nMaxScale)
                     throws Error,
                            java.io.IOException
Creates a new instance of DetectHaarMultiScale. The scale parameters correspond to the size of a square area in the original input image that are averaged to create a single pixel in the image used for detection. A scale factor of 1 would do detection at full image resolution.

Parameters:
is - Input stream containing the Haar cascade. This input stream is created by the Haar2J2me program (run on a PC) from a Haar cascade that has been trained using the OpenCV. See {http://sourceforge.net/projects/opencv} for more information about the OpenCV. The Haar2J2me program should be available wherever you got this code from.
nMinScale - Minimum (finest) scale at which features will be detected.
nMaxScale - Maximum (coarsest) scale at which features will be detected.
Throws:
Error - if there is an error in the input file.
java.io.IOException - if there is an I/O error reading the input file.
Method Detail

push

public void push(Image image)
          throws Error
Apply multi-scale Haar cascade and prepare a mask image showing where features were detected.

Specified by:
push in class PipelineStage
Parameters:
image - Input Gray8Image.
Throws:
Error - if the input is not a Gray8Image or is too small.

setScale

public void setScale(int nMinScale,
                     int nMaxScale)
Set minimum and maximum scale.

Parameters:
nMinScale - The finest scale -- a scale factor of 1 corresponds to the full image resolution.
nMaxScale - The coarsest scale. A scale factor equal to the image width (for a square image) would mean the entire image is reduced to a single pixel.
Note. The maximum scale actually used is the maximum of this number and the scale which would reduce the image size to the smallest size that the image used in the Haar cascade would fit inside.