mirror of
https://github.com/Laex/Delphi-OpenCV.git
synced 2024-11-16 00:05:52 +01:00
130 lines
3.6 KiB
ObjectPascal
130 lines
3.6 KiB
ObjectPascal
|
program SplitMerge;
|
|||
|
|
|||
|
{$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';
|
|||
|
|
|||
|
const
|
|||
|
filename = 'cat2.jpg';
|
|||
|
|
|||
|
Var
|
|||
|
image: pIplImage = nil;
|
|||
|
gray: pIplImage = nil;
|
|||
|
dst: pIplImage = nil;
|
|||
|
dst2: pIplImage = nil;
|
|||
|
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> RGB-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
r: pIplImage = nil;
|
|||
|
g: pIplImage = nil;
|
|||
|
b: pIplImage = nil;
|
|||
|
temp: pIplImage = nil;
|
|||
|
|
|||
|
t1, t2, t3: pIplImage; // <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
begin
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
image := cvLoadImage(filename, 1);
|
|||
|
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', image);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
gray := cvCreateImage(cvGetSize(image), image^.depth, 1);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvConvertImage(image, gray, CV_BGR2GRAY);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvNamedWindow('gray', 1);
|
|||
|
cvShowImage('gray', gray);
|
|||
|
|
|||
|
dst := cvCreateImage(cvGetSize(gray), IPL_DEPTH_8U, 1);
|
|||
|
dst2 := cvCreateImage(cvGetSize(gray), IPL_DEPTH_8U, 1);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvThreshold(gray, dst, 50, 250, CV_THRESH_BINARY);
|
|||
|
cvAdaptiveThreshold(gray, 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', 1);
|
|||
|
cvShowImage('cvThreshold', dst);
|
|||
|
cvNamedWindow('cvAdaptiveThreshold', 1);
|
|||
|
cvShowImage('cvAdaptiveThreshold', dst2);
|
|||
|
|
|||
|
// :=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
|
|||
|
//
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> RGB-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//
|
|||
|
|
|||
|
r := cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
|
|||
|
g := cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
|
|||
|
b := cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
cvSplit(image, b, g, r, 0);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
temp := cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvAddWeighted(r, 1.0 / 3.0, g, 1.0 / 3.0, 0.0, temp);
|
|||
|
cvAddWeighted(temp, 2.0 / 3.0, b, 1.0 / 3.0, 0.0, temp);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvThreshold(temp, dst, 50, 250, CV_THRESH_BINARY);
|
|||
|
|
|||
|
cvReleaseImage(&temp);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvNamedWindow('RGB cvThreshold', 1);
|
|||
|
cvShowImage('RGB cvThreshold', dst);
|
|||
|
|
|||
|
//
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//
|
|||
|
|
|||
|
t1 := cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
|
|||
|
t2 := cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
|
|||
|
t3 := cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvThreshold(r, t1, 50, 250, CV_THRESH_BINARY);
|
|||
|
cvThreshold(g, t2, 50, 250, CV_THRESH_BINARY);
|
|||
|
cvThreshold(b, t3, 50, 250, CV_THRESH_BINARY);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvMerge(t3, t2, t1, 0, image);
|
|||
|
|
|||
|
cvNamedWindow('RGB cvThreshold 2', 1);
|
|||
|
cvShowImage('RGB cvThreshold 2', image);
|
|||
|
|
|||
|
cvReleaseImage(&t1);
|
|||
|
cvReleaseImage(&t2);
|
|||
|
cvReleaseImage(&t3);
|
|||
|
|
|||
|
// :=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
|
|||
|
|
|||
|
// <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(image);
|
|||
|
cvReleaseImage(gray);
|
|||
|
cvReleaseImage(dst);
|
|||
|
cvReleaseImage(dst2);
|
|||
|
cvReleaseImage(r);
|
|||
|
cvReleaseImage(g);
|
|||
|
cvReleaseImage(b);
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
cvDestroyAllWindows();
|
|||
|
|
|||
|
end.
|