program cv_LoadImage;{$APPTYPECONSOLE}
uses
System.SysUtils,
ocv.highgui_c,
ocv.core_c,
ocv.core.types_c,
ocv.imgproc_c,
uResourcePaths;const// declare image filenameIMAGE_FILE_NAME= cResourceMedia +'opencv_logo_with_text.png';var// declare an opencv image pointer variableimage: pIplImage;
begin
try// load image from file// REMARK: all opencv strings are PAnsiChar, pay attention to this// when using with Delphi 2010/2009image:=cvLoadImage(IMAGE_FILE_NAME);// create display windowcvNamedWindow('image');// display image inside "image" windowcvShowImage('image', image);// wait until user keypresscvWaitKey();// release image memorycvReleaseImage(image);// close and release all display windows
cvDestroyAllWindows;
except
on E: Exception doWriteln(E.ClassName,': ',E.Message);
end;
end.
2.加载图片并输出图片属性
program cv_LoadImage2;{$APPTYPECONSOLE}{$R*.res}
uses
System.SysUtils,
ocv.highgui_c,
ocv.core_c,
ocv.core.types_c,
ocv.imgproc_c,
uResourcePaths;const
filename = cResourceMedia +'opencv_logo_with_text.png';varimage: pIplImage = nil;src: pIplImage = nil;
begin
tryimage:=cvLoadImage(filename,1);ifAssigned(image) then
begin
src:=cvCloneImage(image);ifAssigned(src) then
begin
cvNamedWindow('original',CV_WINDOW_AUTOSIZE);cvShowImage('original', image);WriteLn('src');with src^do
begin
WriteLn(Format('[i] channels: %d',[nChannels]));WriteLn(Format('[i] pixel depth: %d bits',[depth]));WriteLn(Format('[i] width: %d pixels',[width]));WriteLn(Format('[i] height: %d pixels',[height]));WriteLn(Format('[i] image size: %d bytes',[imageSize]));WriteLn(Format('[i] width step: %d bytes',[widthStep]));
end;
WriteLn;WriteLn('original');with image^do
begin
WriteLn(Format('[i] channels: %d',[nChannels]));WriteLn(Format('[i] pixel depth: %d bits',[depth]));WriteLn(Format('[i] width: %d pixels',[width]));WriteLn(Format('[i] height: %d pixels',[height]));WriteLn(Format('[i] image size: %d bytes',[imageSize]));WriteLn(Format('[i] width step: %d bytes',[widthStep]));
end;cvWaitKey(0);cvReleaseImage(image);cvReleaseImage(src);cvDestroyWindow('original');
end;
end;
except
on E: Exception doWriteLn(E.ClassName,': ',E.Message);
end;
end.