2013-03-31 22:30:13 +02:00
{$APPTYPE CONSOLE}
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
program Stereo;
{$R *.res}
uses
System. SysUtils,
2013-04-02 00:17:25 +02:00
uLibName in '..\..\..\include\uLibName.pas' ,
highgui_c in '..\..\..\include\highgui\highgui_c.pas' ,
core_c in '..\..\..\include\<5C> ore\core_c.pas' ,
Core. types_c in '..\..\..\include\<5C> 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' ,
types_c in '..\..\..\include\<5C> ore\types_c.pas' ;
2013-03-31 22:30:13 +02:00
Const
Image_Left = 'StereoSample\Aloe\view0.png' ;
Image_Right = 'StereoSample\Aloe\view1.png' ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
ndisparity = 1 6 ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
mIter = 2 ;
Type
TDoubleArray = array [ 0 .. 1 5 ] of Double ;
pDoubleArray = ^ TDoubleArray;
Var
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
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
image_ : = cvLoadImage( Image_Left, 1 ) ;
image1_ : = cvLoadImage( Image_Right, 1 ) ;
// <20> <> <EFBFBD> <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>
image_g : = cvCreateImage( cvSize( image_^ . width, image_^ . height) , 8 , 1 ) ;
image1_g : = cvCreateImage( cvSize( image_^ . width, image_^ . height) , 8 , 1 ) ;
size : = cvGetSize( image_) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
disparity_left : = cvCreateMat( size. height, size. width, CV_16S) ;
disparity_right : = cvCreateMat( size. height, size. width, CV_16S) ;
// <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> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
cvCvtColor( image_, image_g, CV_BGR2GRAY) ;
cvCvtColor( image1_, image1_g, CV_BGR2GRAY) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
//
state : = cvCreateStereoGCState( ndisparity, mIter) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <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
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 ) ;
2013-04-02 00:17:25 +02:00
cvSave( 'result\disparity.png' , disparity_left_visual) ;
cvSaveImage( '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) ;
2013-04-02 00:17:25 +02:00
cvSave( 'result\disparity1.png' , _3dImage) ;
cvSaveImage( 'result\disparity1.jpg' , _3dImage) ;
2013-03-31 22:30:13 +02:00
except
on E: Exception do
Writeln( E. ClassName, ': ' , E. Message ) ;
end ;
end .