AutoSegment Example for Delphi

procedure TForm1.Button1Click(Sender: TObject);
var
   nSegID: Integer;
begin
   LEADMrc1.BaseBackColor := RGB(200, 255, 255);
   LEADMrc1.BaseForeColor := RGB(0, 80, 0);
   LEADMrc1.CombineFactor := 20;
   LEADMrc1.CombineFlags := COMBINE_TRY;
   LEADMrc1.Sensitivity := 25;
   LEADMrc1.ImageType := IMAGETYPE_SCANNED;
   LEADMrc1.AutoSegment(LEADImage1, 60, 60);
   LEADMrc1.EnumSegments();
   LEADMrc1.CombineFlags:= COMBINE_FORCE;
   LEADMrc1.CombineSegments(0, 1);
   LEADMrc1.SaveSegmentation('C:\segments.sgm');
   LEADMrcDst.LoadSegmentation(LEADImage1, 'C:\segments.sgm');
   LEADMrc1.StopSegmentation();
   LEADMrc1.StartSegmentation(LEADImage1);
   nSegID:= LEADMrc1.CreateNewSegment(LEADImage1, 10, 10, 100, 100, SEGTYPE_PICTURE);
   LEADMrc1.SetSegmentData(LEADImage1, nSegID, 0, 0, 10, 10, SEGTYPE_TEXT_1BIT_BW);
   LEADMrcDst.StopSegmentation();
   LEADMrcDst.CopySegmentationData(LEADMrc1);
   LEADMrc1.EnumSegments();
   LEADMrc1.DeleteSegment(nSegID);
   LEADMrcDst.StopSegmentation();
   LEADMrc1.StopSegmentation();
end;


procedure TForm1.LEADMrc1EnumSegments(SegmentID, SegmentLeft, SegmentTop, SegmentRight, SegmentBottom: Integer; SegmentType: Cardinal);
begin
   LEADImage1. DrawPenWidth:= 2;
   LEADImage1. DrawFillStyle:= bsClear;
   LEADImage1. DrawMode:= pmCopy;

   if (SegmentType = SEGTYPE_TEXT_1BIT_BW) then
      LEADImage1. DrawPenColor:= clBlack
   else if (SegmentType = SEGTYPE_TEXT_1BIT_COLOR) then
      LEADImage1.DrawPenColor:= clYellow
   else if (SegmentType = SEGTYPE_TEXT_2BIT_COLOR) then
      LEADImage1.DrawPenColor:= clGreen
   else if (SegmentType = SEGTYPE_GRAYSCALE_2BIT) then
      LEADImage1.DrawPenColor:= clBlue
   else if (SegmentType = SEGTYPE_GRAYSCALE_8BIT) then
      LEADImage1.DrawPenColor:= clWhite
   else if (SegmentType = SEGTYPE_PICTURE) then
      LEADImage1.DrawPenColor:= clRed;

   LEADImage1.DrawRectangle(SegmentLeft, SegmentTop, SegmentRight - SegmentLeft, SegmentBottom - SegmentTop);
end;