ImageEn, unit ievision

TIEVisionCascadeClassifier


Declaration

TIEVisionCascadeClassifier = interface(TIEVisionBase)


Description

An interface to handle a cascade classifier to locate faces and other objects within an image or video frame.
Classifiers are supplied to TIEVisionObjectsFinder.
You can use the built-in classifiers or load from file (e.g. that you created using TIEVisionCascadeClassifierTrainer).




Demos

Demo  Demos\IEVision\FaceDetection_LowLevel\FaceDetection_LowLevel.dpr
Demo  Demos\IEVision\TrackObjects_LowLevel\TrackObjects_LowLevel.dpr


Examples

// Load two face detectors
objectsFinder := IEVisionLib.createObjectsFinder();
objectsFinder.addClassifier('face detector 1', IEVisionLib.createCascadeClassifier(IEVC_FRONTAL_FACE_ALT_TREE);
objectsFinder.addClassifier('face detector 2', IEVisionLib.createCascadeClassifier(IEVC_FRONTAL_FACE_DEFAULT));


// Automatically detect a face in the current image
const
  divisor = 3;
var
  m_classifier: TIEVisionCascadeClassifier;
  origImage, workImage:TIEVisionImage;
  objects:TIEVisionVectorRect;
begin
  m_classifier := IEVisionLib.createCascadeClassifier( IEVC_FRONTAL_FACE_DEFAULT );

  // copy current sample to ImageEnView bitmap
  ImageEnView1.IO.DShowParams.GetSample(ImageEnView1.IEBitmap);

  // create scaled gray scale image
  origImage := ImageEnView1.IEBitmap.GetIEVisionImage();
  origImage.flip(ievY_AXIS);  // show image correctly
  workImage := IEVisionLib.createImage(origImage.getWidth(), origImage.getHeight(), ievUINT8, 1);
  origImage.convertColor(workImage, ievBGR2GRAY);
  workImage.resize(workImage.getWidth() div divisor, workImage.getHeight() div divisor);
  workImage.equalizeHistogram();

  // detect face
  objects := m_classifier.detectObjects(workImage, 1.1, 3, ievDO_CANNY_PRUNING, IEVisionSize(0,0), IEVisionSize(0,0));

  // face found?
  if objects.size() > 0 then
  begin
    // at least one face detected
    // setup window
    with ImageEnView1, objects.getRect(0) do
      m_lastWindow := IEVisionRect(x*divisor, y*divisor, width*divisor, height*divisor);
    // reset histogram and HUE ranges
    m_histogram := nil;
    m_minHSV := IEVisionScalar(  0,   0,   0);
    m_maxHSV := IEVisionScalar(180, 256, 256);
    // disable face detection
    AutoDetectFace.Down := false;
  end;

  // refresh ImageEnView1
  ImageEnView1.Update;
  m_classifier := nil;
end;


Methods and Properties

Public Method  detectObjects
Public Method  empty
Public Method  load


See Also

createCascadeClassifier
addClassifier
IEVision Embedded Classifiers
DrawRects