Delphi-OpenCV/samples/HoughLines/cv_HoughLines2.dpr

78 lines
1.9 KiB
ObjectPascal
Raw Normal View History

// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
program cv_HoughLines2;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
core_c in '..\..\include\<5C>ore\core_c.pas',
Core.types_c in '..\..\include\<5C>ore\Core.types_c.pas',
highgui_c in '..\..\include\highgui\highgui_c.pas',
imgproc.types_c in '..\..\include\imgproc\imgproc.types_c.pas',
imgproc_c in '..\..\include\imgproc\imgproc_c.pas',
LibName in '..\..\include\LibName.pas';
const
filename = 'Resource\opencv_logo_with_text_sm.png';
Var
src :pIplImage= Nil;
dst :pIplImage=Nil;
color_dst:pIplImage=Nil;
storage:pCvMemStorage;
i:Integer;
lines:pCvSeq;
line:pCvPointArray;
begin
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
src := cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE);
WriteLn(Format('[i] image: %s', [filename]));
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
storage := cvCreateMemStorage(0);
lines := nil;
i := 0;
dst := cvCreateImage( cvGetSize(src), 8, 1 );
color_dst := cvCreateImage( cvGetSize(src), 8, 3 );
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cvCanny( src, dst, 50, 200, 3 );
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cvCvtColor( dst, color_dst, CV_GRAY2BGR );
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
lines := cvHoughLines2( dst, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 50, 50, 10 );
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
for i := 0 to lines^.total-1 do
begin
line := pCvPointArray(cvGetSeqElem(lines,i));
cvLine(color_dst, line^[0], line^[1], CV_RGB(255,0,0), 3, CV_AA, 0 );
end;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cvNamedWindow( 'Source', 1 );
cvShowImage( 'Source', src );
cvNamedWindow( 'Hough', 1 );
cvShowImage( 'Hough', color_dst );
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cvWaitKey(0);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cvReleaseMemStorage(storage);
cvReleaseImage(src);
cvReleaseImage(dst);
cvReleaseImage(color_dst);
cvDestroyAllWindows();
end.