Example code to find and count all blobs in this image:
// Show layer rects around objects
var
rects: TList;
i: integer;
count: integer;
begin
ImageEnView1.Proc.ConvertToBWThreshold(80); // <= 80 = sensible parameter
rects := ImageEnView1.Proc.SeparateObjects(4, false);
ImageEnView1.Proc.Undo(); // Revert image
count := 0;
for i := 0 to rects.Count-1 do
begin
with PRect(rects[i])^ do
begin
if (Right-Left > 10) and (Bottom-Top > 10) then // Exclude small objects
begin
// Add Layers
ImageEnView1.LayersAdd( iesRectangle, Rect( Left, Top, Right + 1, Bottom + 1), clRed, 2 );
inc(count);
end;
end;
dispose(PRect(rects[i]));
end;
rects.free;
ImageEnView1.Update;
ShowMessage('Found ' + IntToStr(count) + ' objects');
End;
// Draw red box onto image
var
rects: TList;
i: integer;
count: integer;
begin
ImageEnView1.Proc.ConvertToBWThreshold(80); // <= 80 = sensible parameter
rects := ImageEnView1.Proc.SeparateObjects(4, false);
// Needed to draw red rectangles around found objects!
ImageEnView1.Proc.ConvertTo24Bit();
count := 0;
for i := 0 to rects.Count-1 do
begin
with PRect(rects[i])^ do
begin
if (Right-Left > 10) and (Bottom-Top > 10) then // Exclude small objects
begin
// draw boxes
with ImageEnView1.IEBitmap.Canvas do
begin
Pen.Color:=clRed;
Brush.Style:=bsClear;
Rectangle(Left,Top,Right+1,Bottom+1);
end;
inc(count);
end;
end;
dispose(PRect(rects[i]));
end;
rects.free;
ImageEnView1.Update;
ShowMessage('Found ' + IntToStr(count) + ' objects');
End;
Nigel
Xequte Software
www.imageen.com