ImageEn, unit ievision

TIEVisionLibrary.createBlobDetector

TIEVisionLibrary.createBlobDetector


Declaration

function createBlobDetector(): TIEVisionBlobDetector; safecall;


Description

Create a TIEVisionBlobDetector object.



Note: A shortcut method for this is available: DetectBlobs


Demos

Demo  Demos\IEVision\BlobDetection\BlobDetection.dpr
Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr


Example

var
  detector: TIEVisionBlobDetector;
  keyPoints: TIEVisionVectorKeyPoint;
  kp: TIEVisionKeyPoint;
  i: integer;
  x1, y1, x2, y2: double;
begin
  detector := IEVisionLib().createBlobDetector();

  // Setup parameters
  detector.setThreshold( StrToFlt( EditThresholdMin.Text, 50), StrToFlt( EditThresholdMax.Text, 220), StrToFlt( EditThresholdStep.Text, 10 ));
  detector.setMinDistBetweenBlobs( StrToFlt( EditMinBlobDistance.Text, 10 ));
  detector.setFilterByGrayLevel( CheckBoxGrayLevelFilter.Checked, ComboBoxColorFilter.ItemIndex * 255 );
  detector.setFilterByArea( CheckBoxAreaFilter.Checked, StrToFlt( EditMinArea.Text, 25 ), StrToFlt( EditMaxArea.Text, 5000 ));
  detector.setFilterByCircularity( CheckBoxCircularityFilter.Checked, StrToFlt( EditMinCircularity.Text, 0.8 ), StrToFlt(EditMaxCircularity.Text, 3.4e+38 ));
  detector.setFilterByInertia( CheckBoxInertiaFilter.Checked, StrToFlt( EditMinInertia.Text, 0.1), StrToFlt( EditMaxInertia.Text, 3.4e+38 ));
  detector.setFilterByConvexity( CheckBoxConvexityFilter.Checked, StrToFlt( EditMinConvexity.Text, 0.95), StrToFlt( EditMaxConvexity.Text, 3.4e+38 ));

  keyPoints := detector.detect( ImageEnView1.IEBitmap.GetIEVisionImage() );

  lblCount.Caption := 'Count: ' + IntToStr( keyPoints.size() );
  for i := 0 to keyPoints.size() - 1 do
  begin
    kp := keyPoints.getKeyPoint(i);

    // Draw onto bitmap
    with ImageEnView1.IEBitmap.Canvas do
    begin
      Pen.Color := clRed;
      Pen.Width := 4;
      Brush.Style := bsClear;
      x1 := kp.pt.x - kp.size / 2;
      y1 := kp.pt.y - kp.size / 2;
      x2 := kp.pt.x + kp.size / 2;
      y2 := kp.pt.y + kp.size / 2;
      Ellipse( Round(x1), Round(y1), Round(x2), Round(y2));
    end;
  end;

  ImageEnView1.Update();
end;


Blob Detection vs SeparateObjects

// Load test image
ImageEnView1.IO.LoadFromFile( 'D:\TestImage.jpg' );

  


// BLOB DETECTOR
detector := IEVisionLib().createBlobDetector();
detector.setFilterByInertia( False, 0.1, 3.4e+38 );
detector.setFilterByConvexity( False, 0.95, 3.4e+38 );
keyPoints := detector.detect( ImageEnView1.IEBitmap.GetIEVisionImage() );
// Draw points onto image
for i := 0 to keyPoints.size() - 1 do
begin
  kp := keyPoints.getKeyPoint(i);

  // Draw onto bitmap
  with ImageEnView1.IEBitmap.Canvas do
  begin
    Pen.Color := clRed;
    Pen.Width := 2;
    Brush.Style := bsClear;
    x1 := kp.pt.x - kp.size / 2;
    y1 := kp.pt.y - kp.size / 2;
    x2 := kp.pt.x + kp.size / 2;
    y2 := kp.pt.y + kp.size / 2;
    Ellipse( Round(x1), Round(y1), Round(x2), Round(y2));
  end;
end;
ImageEnView1.Proc.TextOut( Align_Text_Near_Left, Align_Text_Near_Top, Format( 'Found: %d', [ KeyPoints.size ]), 'Arial', 12, Text_Color, [fsBold] );
ImageEnView1.Update();

 


// SEPARATE OBJECTS
ImageEnView1.Proc.SaveUndo();
ImageEnView1.Proc.ConvertToBWThreshold( 80 );    // Better detection
rects := ImageEnView1.Proc.SeparateObjects( 4, True, 10 );
ImageEnView1.Proc.Undo();                        // Get full color image back
for i := 0 to rects.Count - 1 do
begin
  r := PRect(rects[i])^;

  // draw boxes
  with ImageEnView1.IEBitmap.Canvas do
  begin
    Pen.Color := clRed;
    Brush.Style := bsClear;
    Rectangle( r.Left, r.Top, r.Right + 1, r.Bottom + 1 );
  end;

  dispose( PRect( rects[i] ));
end;

// Output object count
ImageEnView1.Proc.TextOut( Align_Text_Near_Left, Align_Text_Near_Top, Format( 'Objects: %d', [ rects.Count ]), 'Arial', 10, clRed, [fsBold] );
ImageEnView1.Update;
rects.free;

 


See Also

SeparateObjects
DrawRects