lib
Class Gray8DetectHaarMultiScale

java.lang.Object
  extended by jjil.core.PipelineStage
      extended by lib.Gray8DetectHaarMultiScale

public class Gray8DetectHaarMultiScale
extends jjil.core.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.
Gray8DetectHaarMultiScale 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

Field Summary
 
Fields inherited from class jjil.core.PipelineStage
fReady, imageOutput
 
Constructor Summary
Gray8DetectHaarMultiScale(java.io.InputStream is, int nMinScale, int nMaxScale)
          Creates a new instance of Gray8DetectHaarMultiScale.
 
Method Summary
 void push(jjil.core.Image image)
          Apply multi-scale Haar cascade and prepare a mask image showing where features were detected.
 java.util.List<jjil.core.Rect> pushAndReturn(jjil.core.Image image)
           
 void setScale(int nMinScale, int nMaxScale)
          Set minimum and maximum scale.
 
Methods inherited from class jjil.core.PipelineStage
getFront, isEmpty, setOutput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Gray8DetectHaarMultiScale

public Gray8DetectHaarMultiScale(java.io.InputStream is,
                                 int nMinScale,
                                 int nMaxScale)
                          throws jjil.core.Error,
                                 java.io.IOException
Creates a new instance of Gray8DetectHaarMultiScale. 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:
jjil.core.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(jjil.core.Image image)
          throws jjil.core.Error
Apply multi-scale Haar cascade and prepare a mask image showing where features were detected.

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

pushAndReturn

public java.util.List<jjil.core.Rect> pushAndReturn(jjil.core.Image image)
                                             throws jjil.core.Error
Throws:
jjil.core.Error

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.