2015-06-29 10:25:41 +02:00
( *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Delphi- OpenCV Demo
Copyright ( C) 2 0 1 3 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
2014-05-22 16:23:41 +02:00
2015-06-29 10:25:41 +02:00
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-31 22:30:13 +02:00
program Stereo;
2013-04-09 12:41:27 +02:00
{$APPTYPE CONSOLE}
2013-03-31 22:30:13 +02:00
{$R *.res}
uses
System. SysUtils,
2014-05-22 16:23:41 +02:00
ocv. highgui_c,
ocv. core_c,
ocv. core. types_c,
ocv. imgproc_c,
ocv. imgproc. types_c,
ocv. legacy,
ocv. calib3d_c;
2013-03-31 22:30:13 +02:00
2013-05-21 10:53:30 +02:00
const
2015-06-29 10:25:41 +02:00
Image_Left = '..\..\resource\StereoSample\Aloe\view2.png' ;
Image_Right = '..\..\resource\StereoSample\Aloe\view3.png' ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-03-31 22:30:13 +02:00
ndisparity = 1 6 ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-03-31 22:30:13 +02:00
mIter = 2 ;
2013-05-21 10:53:30 +02:00
type
2013-03-31 22:30:13 +02:00
TDoubleArray = array [ 0 .. 1 5 ] of Double ;
pDoubleArray = ^ TDoubleArray;
2013-05-21 10:53:30 +02:00
var
2013-03-31 22:30:13 +02:00
image_: pIplImage = nil ;
image1_: pIplImage = nil ;
image_g: pIplImage = nil ;
image1_g: pIplImage = nil ;
disparity_left: pCvMat;
disparity_right: pCvMat;
size: TCvSize;
state: pCvStereoGCState;
disparity_left_visual: pCvMat;
Q: pCvMat;
_3dImage: pIplImage;
begin
try
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-03-31 22:30:13 +02:00
image_ : = cvLoadImage( Image_Left, 1 ) ;
image1_ : = cvLoadImage( Image_Right, 1 ) ;
2013-04-18 08:34:16 +02:00
// c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-03-31 22:30:13 +02:00
image_g : = cvCreateImage( cvSize( image_^ . width, image_^ . height) , 8 , 1 ) ;
image1_g : = cvCreateImage( cvSize( image_^ . width, image_^ . height) , 8 , 1 ) ;
size : = cvGetSize( image_) ;
2013-04-18 08:34:16 +02:00
// c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-03-31 22:30:13 +02:00
disparity_left : = cvCreateMat( size. height, size. width, CV_16S) ;
disparity_right : = cvCreateMat( size. height, size. width, CV_16S) ;
2013-04-18 08:34:16 +02:00
// <20> <> <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>
2013-03-31 22:30:13 +02:00
cvCvtColor( image_, image_g, CV_BGR2GRAY) ;
cvCvtColor( image1_, image1_g, CV_BGR2GRAY) ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-03-31 22:30:13 +02:00
//
state : = cvCreateStereoGCState( ndisparity, mIter) ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 3d
2013-03-31 22:30:13 +02:00
cvFindStereoCorrespondenceGC( image_g, image1_g, disparity_left, disparity_right, state, 0 ) ;
cvReleaseStereoGCState( state) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD>
disparity_left_visual : = cvCreateMat( size. height, size. width, CV_8U) ;
cvConvertScale( disparity_left, disparity_left_visual, - 1 6 ) ;
2014-05-20 07:58:18 +02:00
cvSave( '..\..\resource\result\disparity.png' , disparity_left_visual) ;
cvSaveImage( '..\..\resource\result\disparity.jpg' , disparity_left_visual) ;
2013-03-31 22:30:13 +02:00
Q : = cvCreateMat( 4 , 4 , CV_64F) ;
pDoubleArray( Q^ . data) [ 0 ] : = 1 ;
pDoubleArray( Q^ . data) [ 1 ] : = 0 ;
pDoubleArray( Q^ . data) [ 2 ] : = 0 ;
pDoubleArray( Q^ . data) [ 3 ] : = - 327.73883438110352 ;
pDoubleArray( Q^ . data) [ 4 ] : = 0 ;
pDoubleArray( Q^ . data) [ 5 ] : = 1 ;
pDoubleArray( Q^ . data) [ 6 ] : = 0 ;
pDoubleArray( Q^ . data) [ 7 ] : = - 239.84486865997314 ;
pDoubleArray( Q^ . data) [ 8 ] : = 0 ;
pDoubleArray( Q^ . data) [ 9 ] : = 0 ;
pDoubleArray( Q^ . data) [ 1 0 ] : = 0 ;
pDoubleArray( Q^ . data) [ 1 1 ] : = 524.04542174159019 ;
pDoubleArray( Q^ . data) [ 1 2 ] : = 0 ;
pDoubleArray( Q^ . data) [ 1 3 ] : = 0 ;
pDoubleArray( Q^ . data) [ 1 4 ] : = - 0.30009508961926923 ;
pDoubleArray( Q^ . data) [ 1 5 ] : = 1.2438668093184739 ;
_3dImage : = cvCreateImage( size, IPL_DEPTH_32F, 3 ) ;
cvReprojectImageTo3D( disparity_left_visual, _3dImage, Q) ;
2014-05-20 07:58:18 +02:00
cvSave( '..\..\resource\result\disparity1.png' , _3dImage) ;
cvSaveImage( '..\..\resource\result\disparity1.jpg' , _3dImage) ;
2013-03-31 22:30:13 +02:00
except
on E: Exception do
Writeln( E. ClassName, ': ' , E. Message ) ;
end ;
end .