ImageEn, unit ievision

TIEVisionImage.detectLines

TIEVisionImage.detectLines


Declaration

function detectLines(detector: TIEVisionLinesDetector = ievBinaryDescriptor): TIEVisionVectorScalarInt32; safecall;


Description

Detect lines using a Binary Descriptor or LSD Detector.

Parameter Description
detector Detection algorithm to use

Note: You can draw the lines to a canvas using DrawLines


Demo

Demo  Demos\IEVision\LinesDetectVideo\LinesDetectVideo.dpr


Example

var
  lines: TIEVisionVectorScalarInt32;
  i: integer;
begin
  ImageEnView1.IO.LoadFromFile('input.jpg');
  lines := ImageEnView1.IEBitmap.GetIEVisionImage().detectLines(ievBinaryDescriptor);
  // draw results
  ImageEnView1.IEBitmap.PixelFormat := ie24RGB;
  ImageEnView1.IEBitmap.Origin := ieboBOTTOMLEFT;
  for i := 0 to lines.size() - 1 do
  begin
    with lines.getScalarInt32(i) do
    begin
      with ImageEnView1.IEBitmap.Canvas do
      begin
        Pen.Width := 2;
        Pen.Color := TRGB2TColor(CreateRGB(Random(255), Random(255), Random(255)));
        MoveTo(val[0], val[1]);
        LineTo(val[2], val[3]);
      end;
    end;
  end;
  ImageEnView1.Update();
end;


Comparison of Line Detection Methods

// BINARY DESCRIPTOR
lines := ImageEnView1.IEBitmap.GetIEVisionImage().detectLines( ievBinaryDescriptor );
for i := 0 to lines.size() - 1 do
begin
  sc := lines.getScalarInt32(i);

  with ImageEnView1.IEBitmap.Canvas do
  begin
    Pen.Width := 2;
    Pen.Color := clRed;
    MoveTo( sc.val[0], sc.val[1] );
    LineTo( sc.val[2], sc.val[3] );
  end;
end;
ImageEnView1.Proc.TextOut( Align_Text_Near_Left, Align_Text_Near_Top, Format( 'Lines: %d', [ lines.size ]), 'Arial', 12, Text_Color, [fsBold] );
ImageEnView1.Update();

   


// LSD DETECTOR
lines := ImageEnView1.IEBitmap.GetIEVisionImage().detectLines( ievLSDDetector );
for i := 0 to lines.size() - 1 do
begin
  sc := lines.getScalarInt32(i);

  with ImageEnView1.IEBitmap.Canvas do
  begin
    Pen.Width := 2;
    Pen.Color := clRed;
    MoveTo( sc.val[0], sc.val[1] );
    LineTo( sc.val[2], sc.val[3] );
  end;
end;
ImageEnView1.Proc.TextOut( Align_Text_Near_Left, Align_Text_Near_Top, Format( 'Lines: %d', [ lines.size ]), 'Arial', 12, Text_Color, [fsBold] );
ImageEnView1.Update();

   


// HOUGH TRANSFORM
ImageEnView1.IEBitmap.PixelFormat := ie8g;
ImageEnView1.IEBitmap.GetIEVisionImage().blur( IEVisionSize(3, 3), IEVisionPoint(-1, -1) );
ImageEnView1.IEBitmap.GetIEVisionImage().canny( 50, 200, 3 );
lines := ImageEnView1.IEBitmap.GetIEVisionImage().houghLinesP( 1, PI / 180, 200, 100, 10 );
for i := 0 to lines.size() - 1 do
begin
  sc := lines.getScalarInt32(i);

  with ImageEnView1.IEBitmap.Canvas do
  begin
    Pen.Width := 2;
    Pen.Color := clRed;
    MoveTo( sc.val[0], sc.val[1] );
    LineTo( sc.val[2], sc.val[3] );
  end;
end;
ImageEnView1.Proc.TextOut( Align_Text_Near_Left, Align_Text_Near_Top, Format( 'Lines: %d', [ lines.size ]), 'Arial', 12, Text_Color, [fsBold] );
ImageEnView1.Update();