Delphi-OpenCV/samples/LibTest/cvThreshold/cvThreshold_cvAdaptiveThreshold.dpr

58 lines
1.4 KiB
ObjectPascal
Raw Normal View History

// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
program cvThreshold_cvAdaptiveThreshold;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
{$I ..\..\uses_include.inc}
;
const
filename = 'Resource\cat2.jpg';
var
src: pIplImage = nil;
dst: pIplImage = nil;
dst2: pIplImage = nil;
begin
try
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
src := cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE);
WriteLn(Format('[i] image: %s', [filename]));
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cvNamedWindow('original', CV_WINDOW_AUTOSIZE);
cvShowImage('original', src);
dst := cvCreateImage(cvSize(src^.width, src^.height), IPL_DEPTH_8U, 1);
dst2 := cvCreateImage(cvSize(src^.width, src^.height), IPL_DEPTH_8U, 1);
cvThreshold(src, dst, 50, 250, CV_THRESH_BINARY);
cvAdaptiveThreshold(src, dst2, 250, CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY, 7, 1);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cvNamedWindow('cvThreshold', CV_WINDOW_AUTOSIZE);
cvShowImage('cvThreshold', dst);
cvNamedWindow('cvAdaptiveThreshold', CV_WINDOW_AUTOSIZE);
cvShowImage('cvAdaptiveThreshold', dst2);
// <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>
cvReleaseImage(src);
cvReleaseImage(dst);
cvReleaseImage(dst2);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
cvDestroyAllWindows;
except
on E: Exception do
WriteLn(E.ClassName, ': ', E.Message);
end;
end.