2013-04-09 12:41:27 +02:00
( * / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Delphi-OpenCV Demo
// Copyright (C) 2013 Project Delphi-OpenCV
// ****************************************************************
// Contributor:
// laentir Valetov
// email:laex@bk.ru
// ****************************************************************
// You may retrieve the latest version of this file at the GitHub,
// located at git://github.com/Laex/Delphi-OpenCV.git
// ****************************************************************
// The contents of this file are used with permission, subject to
// the Mozilla Public License Version 1.1 (the "License"); you may
// not use this file except in compliance with the License. You may
// obtain a copy of the License at
// http://www.mozilla.org/MPL/MPL-1_1Final.html
//
// Software distributed under the License is distributed on an
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
// implied. See the License for the specific language governing
// rights and limitations under the License.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * )
2013-03-27 23:20:08 +01:00
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
2013-04-02 00:17:25 +02:00
program cvSplit_cvMerge;
2013-01-01 22:36:38 +01:00
{$APPTYPE CONSOLE}
{$R *.res}
uses
System. SysUtils,
2014-05-22 08:53:48 +02:00
opencv. highgui_c,
opencv. core_c,
opencv. core. types_c,
opencv. imgproc_c,
opencv. imgproc. types_c,
2014-05-20 07:10:43 +02:00
uResourcePaths;
2013-01-01 22:36:38 +01:00
const
2014-05-20 07:10:43 +02:00
filename = cResourceMedia + 'cat2.jpg' ;
2013-01-01 22:36:38 +01:00
2013-05-21 10:53:30 +02:00
var
2013-01-01 22:36:38 +01:00
image: pIplImage = nil ;
gray: pIplImage = nil ;
dst: pIplImage = nil ;
dst2: pIplImage = nil ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD> RGB-<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-01-01 22:36:38 +01:00
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
2013-04-18 08:34:16 +02:00
try
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
image : = cvLoadImage( filename, 1 ) ;
WriteLn( Format( '[i] image: %s' , [ filename] ) ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
cvNamedWindow( 'original' , CV_WINDOW_AUTOSIZE) ;
cvShowImage( 'original' , image) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <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> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD>
gray : = cvCreateImage( cvGetSize( image) , image^ . depth, 1 ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <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> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD>
cvConvertImage( image, gray, CV_BGR2GRAY) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
cvNamedWindow( 'gray' , 1 ) ;
cvShowImage( 'gray' , gray) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
dst : = cvCreateImage( cvGetSize( gray) , IPL_DEPTH_8U, 1 ) ;
dst2 : = cvCreateImage( cvGetSize( gray) , IPL_DEPTH_8U, 1 ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <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> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD>
cvThreshold( gray, dst, 5 0 , 2 5 0 , CV_THRESH_BINARY) ;
cvAdaptiveThreshold( gray, dst2, 2 5 0 , CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY, 7 , 1 ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <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) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// :=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
//
// <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>
//
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
r : = cvCreateImage( cvGetSize( image) , IPL_DEPTH_8U, 1 ) ;
g : = cvCreateImage( cvGetSize( image) , IPL_DEPTH_8U, 1 ) ;
b : = cvCreateImage( cvGetSize( image) , IPL_DEPTH_8U, 1 ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD>
cvSplit( image, b, g, r, 0 ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <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 ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63>
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) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <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, 5 0 , 2 5 0 , CV_THRESH_BINARY) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
cvReleaseImage( & temp) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <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) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
//
// <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> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD>
//
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
t1 : = cvCreateImage( cvGetSize( image) , IPL_DEPTH_8U, 1 ) ;
t2 : = cvCreateImage( cvGetSize( image) , IPL_DEPTH_8U, 1 ) ;
t3 : = cvCreateImage( cvGetSize( image) , IPL_DEPTH_8U, 1 ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <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, 5 0 , 2 5 0 , CV_THRESH_BINARY) ;
cvThreshold( g, t2, 5 0 , 2 5 0 , CV_THRESH_BINARY) ;
cvThreshold( b, t3, 5 0 , 2 5 0 , CV_THRESH_BINARY) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
cvMerge( t3, t2, t1, 0 , image) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
cvNamedWindow( 'RGB cvThreshold 2' , 1 ) ;
cvShowImage( 'RGB cvThreshold 2' , image) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
cvReleaseImage( & t1) ;
cvReleaseImage( & t2) ;
cvReleaseImage( & t3) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// :=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
cvWaitKey( 0 ) ;
2013-01-01 22:36:38 +01:00
2013-04-18 08:34:16 +02:00
// <20> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63> c<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( ) ;
2013-04-05 13:36:47 +02:00
except
on E: Exception do
2013-04-18 08:34:16 +02:00
WriteLn( E. ClassName, ': ' , E. Message ) ;
2013-04-05 13:36:47 +02:00
end ;
2013-04-18 08:34:16 +02:00
2013-01-01 22:36:38 +01:00
end .