Delphi-OpenCV/samples/LibTest/cvSetImageROI/cv_SetImageROI2.dpr
Laex 8540f5bd44 Add samples
Multidemo
[+] fback_c (cvCalcOpticalFlowFarneback)
[+] minarea (cvMinEnclosingCircle, cvMinAreaRect2)

Signed-off-by: Laex <laex@bk.ru>
2013-04-06 00:58:24 +04:00

81 lines
2.1 KiB
ObjectPascal

// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
program cv_SetImageROI2;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
uLibName in '..\..\..\include\uLibName.pas',
highgui_c in '..\..\..\include\highgui\highgui_c.pas',
core_c in '..\..\..\include\ñore\core_c.pas',
Core.types_c in '..\..\..\include\ñore\Core.types_c.pas',
imgproc.types_c in '..\..\..\include\imgproc\imgproc.types_c.pas',
imgproc_c in '..\..\..\include\imgproc\imgproc_c.pas',
legacy in '..\..\..\include\legacy\legacy.pas',
calib3d in '..\..\..\include\calib3d\calib3d.pas',
imgproc in '..\..\..\include\imgproc\imgproc.pas',
haar in '..\..\..\include\objdetect\haar.pas',
objdetect in '..\..\..\include\objdetect\objdetect.pas',
tracking in '..\..\..\include\video\tracking.pas',
Core in '..\..\..\include\ñore\core.pas'
;
Const
// èìÿ êàðòèíêè
filename = 'Resource\opencv_logo_with_text.png';
filename2 = 'Resource\cat2.jpg';
var
image: PIplImage = nil;
src: PIplImage = nil;
x: Integer;
y: Integer;
width: Integer;
height: Integer;
begin
try
image := cvLoadImage(filename, 1);
Writeln('[i] image: ', filename);
if not Assigned(image) then
Halt;
cvNamedWindow('origianl', CV_WINDOW_AUTOSIZE);
cvNamedWindow('ROI', CV_WINDOW_AUTOSIZE);
// çàäà¸ì ROI
x := 120;
y := 50;
// äîáàâî÷íîå èçîáðàæåíèå
src := cvLoadImage(filename2, 1);
if not Assigned(src) then
Halt;
// ðàçìåð ROI
width := src^.width;
height := src^.height;
cvShowImage('origianl', image);
// óñòàíàâëèâàåì ROI
cvSetImageROI(image, cvRect(x, y, width, height));
// îáíóëèì èçîáðàæåíèå
cvZero(image);
// êîïèðóåì èçîáðàæåíèå
cvCopy(src, image);
// ñáðàñûâàåì ROI
cvResetImageROI(image);
// ïîêàçûâàåì èçîáðàæåíèå
cvShowImage('ROI', image);
// æä¸ì íàæàòèÿ êëàâèøè
cvWaitKey(0);
// îñâîáîæäàåì ðåñóðñû
cvReleaseImage(image);
cvReleaseImage(src);
cvDestroyAllWindows;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.