ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Count objects in image
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

xequte

38182 Posts

Posted - Jun 05 2018 :  17:27:04  Show Profile  Reply
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

xequte

38182 Posts

Posted - Jun 12 2018 :  23:07:17  Show Profile  Reply
Or with new IEVision Blob Detector:



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

chouk

Algeria
26 Posts

Posted - Jun 14 2018 :  06:47:09  Show Profile  Reply
Hi,

Where is the link this demo for test ?

Thank's
Go to Top of Page

xequte

38182 Posts

Posted - Jun 15 2018 :  00:22:55  Show Profile  Reply
Please wait for the release of IEVision v4.5.0 in about a week.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: