[+] CameraCalibrate

[+] Stereo

Signed-off-by: Laex <laex@bk.ru>
This commit is contained in:
Laex 2013-04-01 00:30:13 +04:00
parent 7d2ac4512f
commit 13286756ea
18 changed files with 1025 additions and 71 deletions

3
.gitignore vendored
View File

@ -10,3 +10,6 @@ __history
*.tvsconfig
/!DS!
*.skincfg
/bin/StereoSample/*.zip
/bin/StereoSample/Aloe

View File

@ -1,11 +1,6 @@
Delphi-OpenCV
Project is no longer divided by version OpenCL.
Project matching, the latest version of OpenCL.
The current version of OpenCL 2.4.4.
Development environment Delphi XE3.
=============
-------------
Project is no longer divided by version OpenCV.<br>
Project matching, the latest version of OpenCV.<br>
The current version of OpenCV 2.4.4.<br>
Development environment - Delphi XE3.

View File

@ -9,12 +9,16 @@ const
Core_Dll = 'opencv_core' + CV_Version + 'd.dll';
highgui_Dll = 'opencv_highgui' + CV_Version + 'd.dll';
imgproc_Dll = 'opencv_imgproc' + CV_Version + 'd.dll';
objdetect_dll ='opencv_objdetect' + CV_Version + 'd.dll';
objdetect_dll = 'opencv_objdetect' + CV_Version + 'd.dll';
legacy_dll = 'opencv_legacy' + CV_Version + 'd.dll';
calib3d_dll = 'opencv_calib3d' + CV_Version + 'd.dll';
{$ELSE}
Core_Dll = 'opencv_core' + CV_Version + '.dll';
highgui_Dll = 'opencv_highgui' + CV_Version + '.dll';
imgproc_Dll = 'opencv_imgproc' + CV_Version + '.dll';
objdetect_dll ='opencv_objdetect' + CV_Version + '.dll';
objdetect_dll = 'opencv_objdetect' + CV_Version + '.dll';
legacy_dll = 'opencv_legacy' + CV_Version + '.dll';
calib3d_dll = 'opencv_calib3d' + CV_Version + '.dll';
{$ENDIF}
implementation

View File

@ -0,0 +1,84 @@
unit calib3d;
interface
Uses Core.types_c, types_c;
{
/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
CVAPI(void) cvReprojectImageTo3D(
const CvArr* disparityImage,
CvArr* _3dImage,
const CvMat* Q,
int handleMissingValues CV_DEFAULT(0) );
}
procedure cvReprojectImageTo3D(
{ } const disparityImage: pCvMat;
{ } _3dImage: pIplImage;
{ } const Q: pCvMat;
{ } handleMissingValues: Integer = 0); cdecl;
Const
CV_CALIB_CB_ADAPTIVE_THRESH = 1;
CV_CALIB_CB_NORMALIZE_IMAGE = 2;
CV_CALIB_CB_FILTER_QUADS = 4;
CV_CALIB_CB_FAST_CHECK = 8;
{
/* Detects corners on a chessboard calibration pattern */
CVAPI(int) cvFindChessboardCorners(
const void* image,
CvSize pattern_size,
CvPoint2D32f* corners,
int* corner_count CV_DEFAULT(NULL),
int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) );
}
function cvFindChessboardCorners(const image: Pointer; pattern_size: TCvSize; corners: pCvPoint2D32f;
corner_count: pInteger = nil; flags: Integer = CV_CALIB_CB_ADAPTIVE_THRESH + CV_CALIB_CB_NORMALIZE_IMAGE)
: Integer; cdecl;
{
/* Draws individual chessboard corners or the whole chessboard detected */
CVAPI(void) cvDrawChessboardCorners(
CvArr* image,
CvSize pattern_size,
CvPoint2D32f* corners,
int count,
int pattern_was_found );
}
procedure cvDrawChessboardCorners(image: pIplImage; pattern_size: TCvSize; corners: pCvPoint2D32f; count: Integer;
pattern_was_found: Integer); cdecl;
{
/* Finds intrinsic and extrinsic camera parameters
from a few views of known calibration pattern */
CVAPI(double) cvCalibrateCamera2(
const CvMat* object_points,
const CvMat* image_points,
const CvMat* point_counts,
CvSize image_size,
CvMat* camera_matrix,
CvMat* distortion_coeffs,
CvMat* rotation_vectors CV_DEFAULT(NULL),
CvMat* translation_vectors CV_DEFAULT(NULL),
int flags CV_DEFAULT(0),
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) );
}
function cvCalibrateCamera2(const object_points: pCvMat; const image_points: pCvMat; const point_counts: pCvMat;
image_size: TCvSize; camera_matrix: pCvMat; distortion_coeffs: pCvMat; rotation_vectors: pCvMat { =nil };
translation_vectors: pCvMat { =nil }; flags: Integer { =0 };
term_crit: TCvTermCriteria { =cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON) }
): Double; cdecl;
implementation
Uses LibName;
procedure cvReprojectImageTo3D; external calib3d_dll;
function cvFindChessboardCorners; external calib3d_dll;
procedure cvDrawChessboardCorners; external calib3d_dll;
function cvCalibrateCamera2; external calib3d_dll;
end.

View File

@ -253,7 +253,8 @@ const
CVAPI(int) cvSaveImage( const char* filename, const CvArr* image, const int* params CV_DEFAULT(0) );
}
function cvSaveImage(const filename: pCVChar; const image: pIplImage; const params: PInteger = nil): Integer; cdecl;
//function cvSaveImage(const filename: pCVChar; const image: pIplImage; const params: PInteger = nil): Integer; cdecl;
function cvSaveImage(const filename: pCVChar; const image: pointer; const params: PInteger = nil): Integer; cdecl;
(* decode image stored in the buffer *)
// CVAPI(IplImage)cvDecodeImage(CvMat * buf, Integer iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));

View File

@ -22,7 +22,7 @@ interface
*)
uses
Core.types_c, imgproc.types_c;
Core.types_c, imgproc.types_c, types_c;
(* M///////////////////////////////////////////////////////////////////////////////////////
//
@ -234,13 +234,22 @@ procedure cvResize(const src: TCvArr; dst: TCvArr; interpolation: Integer = CV_I
// var)CVAPI(CvMat)cvGetPerspectiveTransform(CvPoint2D32f * src: ); var dst: vPoint2D32f;
// var map_matrix: CvMat);
//
// (* Performs generic geometric transformation using the specified coordinate maps *)
// CVAPI(
// procedure)cvRemap(var Converts mapx & mapy from floating -
// point to Integer formats for cvRemap * )CVAPI(
// procedure)cvConvertMaps(CvArr * mapx: v1: cvScalarAll(0))): Integer; (; var mapy: CvArr;
// var mapxy: CvArr; var mapalpha: CvArr);
//
{
/* Performs generic geometric transformation using the specified coordinate maps */
CVAPI(void) cvRemap(
const CvArr* src,
CvArr* dst,
const CvArr* mapx,
const CvArr* mapy,
int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS),
CvScalar fillval CV_DEFAULT(cvScalarAll(0)) );
}
procedure cvRemap(const src: pIplImage; dst: pIplImage; const mapx: pIplImage; const mapy: pIplImage;
flags: Integer { =CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS }; fillval: TCvScalar { =cvScalarAll(0) }
); cdecl;
// (* Performs forward or inverse log-polar image transform *)
// CVAPI(
// procedure)cvLogPolar(var Performs forward or inverse linear - polar image transform * )CVAPI(
@ -251,12 +260,20 @@ procedure cvResize(const src: TCvArr; dst: TCvArr; interpolation: Integer = CV_I
// function flags CV_DEFAULT(v1: CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS)): Integer; (; var dst: CvArr;
// var camera_matrix: vMat; var distortion_coeffs: vMat; var new_camera_matrix CV_DEFAULT(0): vMat);
//
// (* Computes transformation map from intrinsic camera parameters
// that can used by cvRemap *)
// CVAPI(
// procedure)cvInitUndistortMap(var camera_matrix: CvMat; var distortion_coeffs: vMat; var mapx: CvArr;
// var mapy: CvArr);
//
{
/* Computes transformation map from intrinsic camera parameters
that can used by cvRemap */
CVAPI(void) cvInitUndistortMap(
const CvMat* camera_matrix,
const CvMat* distortion_coeffs,
CvArr* mapx,
CvArr* mapy );
}
procedure cvInitUndistortMap(const camera_matrix: pCvMat; const distortion_coeffs: pCvMat; mapx: pIplImage;
mapy: pIplImage); cdecl;
// (* Computes undistortion+rectification map for a head of stereo camera *)
// CVAPI(
// procedure)cvInitUndistortRectifyMap(var camera_matrix: CvMat; var dist_coeffs: vMat;
@ -650,12 +667,11 @@ function cvApproxPoly(
// (* calculates probabilistic density (divides one histogram by another) *)
// CVAPI(procedure) cvCalcProbDensity(
{/* equalizes histogram of 8-bit single-channel image */
CVAPI(void) cvEqualizeHist( const CvArr* src, CvArr* dst );
{ /* equalizes histogram of 8-bit single-channel image */
CVAPI(void) cvEqualizeHist( const CvArr* src, CvArr* dst );
}
procedure cvEqualizeHist( const src,dst:pIplImage); cdecl;
procedure cvEqualizeHist(const src, dst: pIplImage); cdecl;
//
//
@ -753,6 +769,21 @@ procedure cvCanny(const image: pIplImage; edges: pIplImage; threshold1: double;
// : Integer aperture_size CV_DEFAULT(v1: 3)): Integer; (; var)CVAPI(
// procedure)cvCornerHarris(CvArr * image: where M is 2 x2 gradient covariation matrix for each pixel;
// var harris_responce: CvArr; block_size:
{
/* Adjust corner position using some sort of gradient search */
CVAPI(void) cvFindCornerSubPix(
const CvArr* image,
CvPoint2D32f* corners,
int count,
CvSize win,
CvSize zero_zone,
CvTermCriteria criteria );
}
procedure cvFindCornerSubPix(const image: pIplImage; corners: pCvPoint2D32f; count: Integer; win: TCvSize;
zero_zone: TCvSize; criteria: TCvTermCriteria); cdecl;
// function; var Adjust corner position using some sort of gradient search * )CVAPI(
// procedure)cvFindCornerSubPix(CvArr * image: Integer aperture_size CV_DEFAULT(v1: 0.04)): Integer; (;
// var corners: CvPoint2D32f; count: Integer; win: CvSize; zero_zone: CvSize;
@ -864,5 +895,8 @@ procedure cvIntegral; external imgproc_Dll;
function cvFindContours; external imgproc_Dll;
function cvApproxPoly; external imgproc_Dll;
procedure cvEqualizeHist; external imgproc_Dll;
procedure cvFindCornerSubPix; external imgproc_Dll;
procedure cvInitUndistortMap; external imgproc_Dll;
procedure cvRemap; external imgproc_Dll;
end.

55
include/legacy/legacy.pas Normal file
View File

@ -0,0 +1,55 @@
unit legacy;
interface
Uses Core.types_c;
Type
pCvStereoGCState = ^TCvStereoGCState;
TCvStereoGCState = packed record
Ithreshold: Integer;
interactionRadius: Integer;
K, lambda, lambda1, lambda2: Single;
occlusionCost: Integer;
minDisparity: Integer;
numberOfDisparities: Integer;
maxIters: Integer;
left: pCvMat;
right: pCvMat;
dispLeft: pCvMat;
dispRight: pCvMat;
ptrLeft: pCvMat;
ptrRight: pCvMat;
vtxBuf: pCvMat;
edgeBuf: pCvMat;
end;
// CVAPI(CvStereoGCState*) cvCreateStereoGCState( int numberOfDisparities, int maxIters );
function cvCreateStereoGCState(numberOfDisparities: Integer; maxIters: Integer): pCvStereoGCState; cdecl;
{
CVAPI(void) cvFindStereoCorrespondenceGC(
const CvArr* left,
const CvArr* right,
CvArr* disparityLeft,
CvArr* disparityRight,
CvStereoGCState* state,
int useDisparityGuess CV_DEFAULT(0) );
}
procedure cvFindStereoCorrespondenceGC(const left: pIplImage; const right: pIplImage; disparityLeft: pCvMat;
disparityRight: pCvMat; state: pCvStereoGCState; useDisparityGuess: Integer = 0); cdecl;
// CVAPI(void) cvReleaseStereoGCState( CvStereoGCState** state );
procedure cvReleaseStereoGCState(Var state: pCvStereoGCState); cdecl;
implementation
Uses LibName;
function cvCreateStereoGCState; external legacy_Dll;
procedure cvFindStereoCorrespondenceGC; external legacy_Dll;
procedure cvReleaseStereoGCState; external legacy_Dll;
end.

View File

@ -506,7 +506,7 @@ const
{$EXTERNALSYM CV_32S}
CV_32F = 5;
{$EXTERNALSYM CV_32F}
CV_64F = 6;
CV_64F = 6; // Double
{$EXTERNALSYM CV_64F}
CV_USRTYPE1 = 7;
{$EXTERNALSYM CV_USRTYPE1}
@ -558,10 +558,6 @@ const
const
CV_16SC(n)CV_MAKETYPE(CV_16S, (n));
const
CV_32SC1 = CV_MAKETYPE(CV_32S, 1);
{$EXTERNALSYM CV_32SC1}
const
CV_32SC2 = CV_MAKETYPE(CV_32S, 2);
{$EXTERNALSYM CV_32SC2}
@ -832,7 +828,8 @@ type
(* ************************************** CvRect **************************************** *)
type
pCvRect=^TCvRect;
pCvRect = ^TCvRect;
TCvRect = packed record
x: Integer;
y: Integer;
@ -950,7 +947,8 @@ type
(* ************************************************************************************** *)
(* ******************************* Memory storage *************************************** *)
type
pCvMemBlock=^TCvMemBlock;
pCvMemBlock = ^TCvMemBlock;
TCvMemBlock = packed record
prev: pCvMemBlock;
next: pCvMemBlock;
@ -2111,6 +2109,7 @@ function CV_MAT_TYPE(flags: Integer): Integer;
function CV_ELEM_SIZE(_type: Integer): Integer;
function CV_MAT_CN(flags: Integer): Integer;
function CV_32FC1: Integer;
function CV_32SC1: Integer;
function CV_MAKETYPE(depth, cn: Integer): Integer;
// #define CV_MAT_ELEM( mat, elemtype, row, col ) \
// (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
@ -2160,6 +2159,11 @@ begin
Result := (CV_MAT_CN(_type) shl ((((SizeOf(Integer) div 4 + 1) * 16384 or $3A50) shr CV_MAT_DEPTH(_type) * 2) and 3));
end;
function CV_32SC1: Integer;
begin
Result := CV_MAKETYPE(CV_32S, 1);
end;
function CV_32FC1: Integer;
begin
Result := CV_MAKETYPE(CV_32F, 1);

View File

@ -154,13 +154,15 @@ const
// function
// function CV_DEFAULT(v1: CV_AUTOSTEP)): Integer;
{
(* Allocates and initializes CvMat header and allocates data *)
CVAPI(CvMat)cvCreateMat(Integer rows, Integer cols, Integer cType): Pointer;
}
function cvCreateMat(rows: Integer; cols: Integer; cType: Integer): pCvMat; cdecl;
// (* Allocates and initializes CvMat header and allocates data *)
// CVAPI(CvMat)cvCreateMat(Integer rows, Integer cols, Integer cType): Pointer;
/// * Releases CvMat header and deallocates matrix data
// (reference counting is used for data) */
// CVAPI(void) cvReleaseMat( CvMat** mat );
/// * Releases CvMat header and deallocates matrix data
// (reference counting is used for data) */
// CVAPI(void) cvReleaseMat( CvMat** mat );
procedure cvReleaseMat(Var mat: pCvMat); cdecl;
@ -193,11 +195,11 @@ procedure cvReleaseMat(Var mat: pCvMat); cdecl;
// CVAPI(CvMat) cvCloneMat( CvMat* mat: step value)): Integer;
{
(* Makes a new matrix from <rect> subrectangle of input array.
No data is copied *)
CVAPI(CvMat)cvGetSubRect(CvArr * arr, CvMat * submat, CvRect rect);
(* Makes a new matrix from <rect> subrectangle of input array.
No data is copied *)
CVAPI(CvMat)cvGetSubRect(CvArr * arr, CvMat * submat, CvRect rect);
}
function cvGetSubRect(arr:pIplImage; submat:pIplImage; rect:TCvRect):pIplImage; cdecl;
function cvGetSubRect(arr: pIplImage; submat: pIplImage; rect: TCvRect): pIplImage; cdecl;
// const cvGetSubArr = cvGetSubRect;
@ -530,7 +532,8 @@ procedure cvCvtPlaneToPix(
#define cvConvert( src, dst ) cvConvertScale( (src), (dst), 1, 0 )
}
procedure cvConvertScale(const src: pIplImage; dst: pIplImage; scale: double = 1; shift: double = 0); cdecl;
procedure cvConvertScale(const src: pIplImage; dst: pIplImage; scale: double = 1; shift: double = 0); cdecl; overload;
procedure cvConvertScale(const src: pCvMat; dst: pCvMat; scale: double = 1; shift: double = 0); cdecl; overload;
procedure cvConvert(const src: pIplImage; dst: pIplImage);
// (* Performs linear transformation on every source array element,
@ -1036,8 +1039,6 @@ function cvCreateMemStorage(block_size: Integer = 0): pCvMemStorage; cdecl;
}
procedure cvReleaseMemStorage(var storage: pCvMemStorage); cdecl;
// (* Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos)
// to reuse memory allocated for the storage - cvClearSeq,cvClearSet Args: array of const
// do not free any memory.
@ -1358,20 +1359,19 @@ procedure cvLine(img: pIplImage; pt1, pt2: TCvPoint; color: TCvScalar; thickness
shift: Integer = 0); cdecl;
//
{
/* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2),
if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn */
CVAPI(void) cvRectangle(
CvArr* img,
CvPoint pt1,
CvPoint pt2,
CvScalar color,
int thickness CV_DEFAULT(1),
int line_type CV_DEFAULT(8),
int shift CV_DEFAULT(0));
/* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2),
if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn */
CVAPI(void) cvRectangle(
CvArr* img,
CvPoint pt1,
CvPoint pt2,
CvScalar color,
int thickness CV_DEFAULT(1),
int line_type CV_DEFAULT(8),
int shift CV_DEFAULT(0));
}
procedure cvRectangle(img: pIplImage; pt1, pt2: TCvPoint; color: TCvScalar; thickness: Integer = 1; line_type: Integer = 8;
shift: Integer = 0); cdecl;
procedure cvRectangle(img: pIplImage; pt1, pt2: TCvPoint; color: TCvScalar; thickness: Integer = 1;
line_type: Integer = 8; shift: Integer = 0); cdecl;
// (* Draws a rectangle specified by a CvRect structure *)
// procedure cvRectangleR(8: v1: ); shift CV_DEFAULT(0): Integer): Integer;
@ -1984,7 +1984,12 @@ procedure cvAnd; external Core_Dll;
procedure cvCvtPixToPlane; external Core_Dll name 'cvSplit';
procedure cvCvtPlaneToPix; external Core_Dll name 'cvMerge';
procedure cvConvertScale; external Core_Dll;
// procedure cvConvertScale; external Core_Dll;
procedure cvConvertScale(const src: pIplImage; dst: pIplImage; scale: double = 1; shift: double = 0); cdecl;
external Core_Dll name 'cvConvertScale';
procedure cvConvertScale(const src: pCvMat; dst: pCvMat; scale: double = 1; shift: double = 0); cdecl;
external Core_Dll name 'cvConvertScale';
procedure cvScale; external Core_Dll name 'cvConvertScale';
procedure cvCvtScale; external Core_Dll name 'cvConvertScale';
@ -2020,7 +2025,7 @@ end;
function cvGetTickFrequency: double;
begin
Result := getTickFrequency() * 1E-6;
Result := GetTickFrequency() * 1E-6;
end;
procedure cvFlip; external Core_Dll;
@ -2028,5 +2033,6 @@ procedure cvMirror; external Core_Dll name 'cvFlip';
procedure cvRectangle; external Core_Dll;
function cvGetSubRect; external Core_Dll;
procedure cvClearMemStorage; external Core_Dll;
function cvCreateMat; external Core_Dll;
end.

47
include/сore/types_c.pas Normal file
View File

@ -0,0 +1,47 @@
unit types_c;
interface
const
// Íàèìåíüøåå ÷èñëî äëÿ êîòîðîãî âûïîëíÿåòñÿ óñëîâèå 1.0+DBL_EPSILON != 1.0
DBL_EPSILON = 2.2204460492503131E-016;
Type
pCvPoint2D32f = ^TCvPoint2D32f;
TCvPoint2D32f = packed record
x: Single;
y: Single;
end;
// *********************************** CvTermCriteria *************************************/
const
CV_TERMCRIT_ITER = 1;
CV_TERMCRIT_NUMBER = CV_TERMCRIT_ITER;
CV_TERMCRIT_EPS = 2;
Type
pCvTermCriteria = ^TCvTermCriteria;
TCvTermCriteria = packed record
_type: Integer;
// may be combination of
// CV_TERMCRIT_ITER
// CV_TERMCRIT_EPS
max_iter: Integer;
epsilon: double;
end;
function CvTermCriteria(_type: Integer; max_iter: Integer; epsilon: double): TCvTermCriteria; inline;
implementation
function CvTermCriteria(_type: Integer; max_iter: Integer; epsilon: double): TCvTermCriteria;
begin
Result._type := _type;
Result.max_iter := max_iter;
Result.epsilon := epsilon;
end;
end.

View File

@ -0,0 +1,277 @@
// ×òåíèå øèðèíû è âûñîòû øàõìàòíîé äîñêè,
// ÷òåíèå è êîëëåêöèîíèðîâàíèå çàïðîøåííîãî êîëè÷åñòâà âèäîâ
// è êàëèáðîâêà êàìåðû
// calib.cpp
// Èíèöèàëèçàöèÿ âõîäíûõ äàííûõ:
// calib board_w board_h number_of_views
//
// Íàæàòèå p - óñòàíîâêà/âûêëþ÷åíèå ïàóçû, ESC - âûõîä
{$APPTYPE CONSOLE}
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
program CameraCalibrate;
{$R *.res}
uses
System.SysUtils,
LibName in '..\..\include\LibName.pas',
highgui_c in '..\..\include\highgui\highgui_c.pas',
core_c in '..\..\include\ñore\core_c.pas',
Core.types_c in '..\..\include\ñ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\ñore\types_c.pas';
Type
pCvPoint2D32fArray = ^TCvPoint2D32fArray;
TCvPoint2D32fArray = array [0 .. 1] of TCvPoint2D32f;
Const
float = SizeOf(Single);
Var
n_boards: Integer = 0; // Óñòàíîâèì âõîäíîé ñïèñîê
board_dt: Integer = 20; // Æäåì 20 ôðåéìîâ ñ âèäàìè øàõìàòíîé äîñêè
board_w: Integer;
board_h: Integer;
board_n: Integer;
board_sz: TCvSize;
capture: pCvCapture;
image_points: pCvMat;
object_points: pCvMat;
point_counts: pCvMat;
intrinsic_matrix: pCvMat;
distortion_coeffs: pCvMat;
corners: pCvPoint2D32f;
corner_count: Integer;
successes: Integer = 0;
step: Integer = 0;
frame: Integer = 0;
image: pIplImage;
gray_image: pIplImage;
found: Integer;
i, j: Integer;
c: Integer;
object_points2: pCvMat;
image_points2: pCvMat;
point_counts2: pCvMat;
intrinsic: pCvMat;
Distortion: pCvMat;
mapx: pIplImage;
mapy: pIplImage;
t: pIplImage;
s: Single;
procedure CV_MAT_ELEMS(const Mat: pCvMat; const x, y: Integer; const Value: Single); overload;
Var
P: Pointer;
begin
P := Pointer(Integer(Mat^.data) + SizeOf(Value) * x * Mat^.step + SizeOf(Value) * y);
Move(Value, P^, SizeOf(Value));
end;
function CV_MAT_ELEMS(const Mat: pCvMat; const x, y: Integer): Single; overload;
begin
Result := pSingle(Integer(Mat^.data) + SizeOf(Result) * x * Mat^.step + SizeOf(Result) * y)^;
end;
procedure CV_MAT_ELEMI(const Mat: pCvMat; const x, y: Integer; const Value: Integer); overload;
Var
P: Pointer;
begin
P := Pointer(Integer(Mat^.data) + SizeOf(Value) * x * Mat^.step + SizeOf(Value) * y);
Move(Value, P^, SizeOf(Value));
end;
function CV_MAT_ELEMI(const Mat: pCvMat; const x, y: Integer): Integer; overload;
begin
Result := pInteger(Integer(Mat^.data) + SizeOf(Result) * x * Mat^.step + SizeOf(Result) * y)^;
end;
begin
try
if ParamCount <> 3 then
begin
Writeln('ERROR: Wrong number of input parameters');
Halt;
end;
board_w := StrToInt(ParamStr(1));
board_h := StrToInt(ParamStr(2));
n_boards := StrToInt(ParamStr(3));
board_n := board_w * board_h;
board_sz := cvSize(board_w, board_h);
capture := cvCreateCameraCapture(0);
assert(Assigned(capture));
cvNamedWindow('Calibration');
// ÂÛÄÅËßÅÌ ÕÐÀÍÈËÈÙÅ ÏÀÌßÒÈ
image_points := cvCreateMat(n_boards * board_n, 2, CV_32FC1);
object_points := cvCreateMat(n_boards * board_n, 3, CV_32FC1);
point_counts := cvCreateMat(n_boards, 1, CV_32SC1);
intrinsic_matrix := cvCreateMat(3, 3, CV_32FC1);
distortion_coeffs := cvCreateMat(5, 1, CV_32FC1);
corners := AllocMem(SizeOf(CvPoint2D32f) * board_n);
image := cvQueryFrame(capture);
gray_image := cvCreateImage(cvGetSize(image), 8, 1); // subpixel
// ÇÀÕÂÀÒ Â ÖÈÊËÅ ÈÇÎÁÐÀÆÅÍÈÉ Ñ ÓÃËÀÌÈ ÏÎÊÀ ÌÛ ÍÅ ÏËÎÓ×ÈÌ n_boards
// ÏÎËÍÛÕ ÇÀÕÂÀÒÎÂ (ÂÑÅ ÓÃËÛ ÍÀ ÄÎÑÊÅ ÁÛËÈ ÍÀÉÄÅÍÛ)
//
while (successes < n_boards) do
begin
// Ïðîïóñêàåì board_dt ôðåéìîâ, ïðåäîñòàâëåííûå ïîëüçîâàòåëåì, äâèãàþùèì äîñêó
if ((frame div board_dt) = 0) then
begin
// Íàõîäèì óãëû øàõìàòíîé äîñêè:
found := cvFindChessboardCorners(image, board_sz, corners, @corner_count, CV_CALIB_CB_ADAPTIVE_THRESH or
CV_CALIB_CB_FILTER_QUADS);
// Ïîëó÷åíèå ñóáïèêñåëüíîé òî÷íîñòè íà ýòèõ óãëàõ
cvCvtColor(image, gray_image, CV_BGR2GRAY);
cvFindCornerSubPix(gray_image, corners, corner_count, cvSize(11, 11), cvSize(-1, -1),
cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
// Íàðèñóåì ýòî
cvDrawChessboardCorners(image, board_sz, corners, corner_count, found);
cvShowImage('Calibration', image);
// Åñëè ìû ïîëó÷èëè õîðîøóþ äîñêó, äîáàâèì åå ê íàøèì äàííûì
if (corner_count = board_n) then
begin
step := successes * board_n;
i := step;
j := 0;
while j < board_n do
begin
Inc(i);
Inc(j);
CV_MAT_ELEMS(image_points, i, 0, pCvPoint2D32fArray(corners)^[j].x);
CV_MAT_ELEMS(image_points, i, 1, pCvPoint2D32fArray(corners)^[j].y);
CV_MAT_ELEMS(object_points, i, 0, j / board_w);
CV_MAT_ELEMS(object_points, i, 1, j div board_w);
CV_MAT_ELEMS(object_points, i, 2, 0);
end;
CV_MAT_ELEMI(point_counts, successes, 0, board_n);
Inc(successes);
end;
end; // end skip board_dt between chessboard capture
// Handle pause/unpause and ESC
c := cvWaitKey(15);
if (c = Ord('p')) then
begin
c := 0;
while (c <> Ord('p')) and (c <> 27) do
begin
c := cvWaitKey(250);
end;
end;
if (c = 27) then
Halt;
image := cvQueryFrame(capture); // Ïîëó÷àåì ñëåäóþùåå èçîáðàæåíèå
end; // ÊÎÍÅÖ ÊÎËËÅÊÖÈÎÍÈÐÎÂÀÍÈÅ ÖÈÊËÎÌ WHILE.
// ÂÛÄÅËßÅÌ ÌÀÒÐÈÖÛ Ê ÒÀÊÎÌÓ ÊÎËÈ×ÅÑÒÂÓ ØÀÕÌÀÒÍÛÕ ÄÎÑÊ, ÑÊÎËÜÊÎ ÁÛËÎ ÍÀÉÄÅÍÎ
object_points2 := cvCreateMat(successes * board_n, 3, CV_32FC1);
image_points2 := cvCreateMat(successes * board_n, 2, CV_32FC1);
point_counts2 := cvCreateMat(successes, 1, CV_32SC1);
// ÏÅÐÅÌÅÙÀÅÌ ÒÎ×ÊÈ Â ÌÀÒÐÈÖÛ ÏÐÀÂÈËÜÍÎÃÎ ÐÀÇÌÅÐÀ
// Íèæå ìû îïèøåì ýòî äåòàëüíî â ñëåäóþùèõ äâóõ öèêëàõ.
// Ìû ìîæåì âìåñòî ýòîãî íàïèñàòü:
// image_points->rows := object_points->rows := \
// successes*board_n; point_counts->rows := successes;
i := 0;
While i < successes * board_n do
begin
Inc(i);
CV_MAT_ELEMS(image_points2, i, 0, CV_MAT_ELEMS(image_points, i, 0));
CV_MAT_ELEMS(image_points2, i, 1, CV_MAT_ELEMS(image_points, i, 1));
CV_MAT_ELEMS(object_points2, i, 0, CV_MAT_ELEMS(object_points, i, 0));
CV_MAT_ELEMS(object_points2, i, 1, CV_MAT_ELEMS(object_points, i, 1));
CV_MAT_ELEMS(object_points2, i, 2, CV_MAT_ELEMS(object_points, i, 2));
end;
i := 0;
While i < successes do
begin // Çäåñü âñå òå æå ÷èñëà
Inc(i);
CV_MAT_ELEMI(point_counts2, i, 0, CV_MAT_ELEMI(point_counts, i, 0));
end;
cvReleaseMat(object_points);
cvReleaseMat(image_points);
cvReleaseMat(point_counts);
// Äëÿ ýòèõ òî÷åê ìû èìååì âñå óãëû øàõìàòíîé äîñêè, êîòîðûå íàì íóæíû.
// Èíèöèàëèçèðóåì ìàòðèöó âíóòðåííèõ ïàðàìåòðîâ òàê, ÷òî îáà ôîêàëüíûõ
// ðàññòîÿíèÿ áóäóò èìåòü ñîîòíîøåíèå 1.0
CV_MAT_ELEMS(intrinsic_matrix, 0, 0, 1);
CV_MAT_ELEMS(intrinsic_matrix, 1, 1, 1);
// ÊÀËÈÁÐÓÅÌ ÊÀÌÅÐÓ!
cvCalibrateCamera2(object_points2, image_points2, point_counts2, cvGetSize(image), intrinsic_matrix,
distortion_coeffs, nil, nil, 0, // CV_CALIB_FIX_ASPECT_RATIO
cvTermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 30, DBL_EPSILON));
// ÑÎÕÐÀÍßÅÌ ÂÍÓÒÐÅÍÍÈÅ ÏÀÐÀÌÅÒÐÛ È ÄÈÑÒÎÐÑÈÞ
cvSave('Intrinsics.xml', intrinsic_matrix);
cvSave('Distortion.xml', distortion_coeffs);
// ÏÐÈÌÅÐ ÇÀÃÐÓÇÊÈ ÝÒÈÕ ÌÀÒÐÈÖ ÍÀÇÀÄ Â ÏÐÎÃÐÀÌÌÌÓ:
intrinsic := cvLoad('Intrinsics.xml');
Distortion := cvLoad('Distortion.xml');
// Ñòðîèì êàðòó àíäèñòîðñèè, êîòîðóþ ìû áóäåì èñïîëüçîâàòü
// äëÿ âñåõ ïîñëåäóþùèõ êàäðîâ.
//
mapx := cvCreateImage(cvGetSize(image), IPL_DEPTH_32F, 1);
mapy := cvCreateImage(cvGetSize(image), IPL_DEPTH_32F, 1);
cvInitUndistortMap(intrinsic, Distortion, mapx, mapy);
// Òîëüêî êàìåðà ñíèìàåò, ñðàçó âèäèì ñûðîå
// è íåèñêàæåííîå èçîáðàæåíèå.
//
cvNamedWindow('Undistort');
while Assigned(image) do
begin
t := cvCloneImage(image);
cvShowImage('Calibration', image); // Show raw image
cvRemap(t, image, mapx, mapy, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, cvScalarAll(0)); // Undistort image
cvReleaseImage(t);
cvShowImage('Undistort', image); // Show corrected image
// Handle pause/unpause and ESC
c := cvWaitKey(15);
if (c = Ord('p')) then
begin
c := 0;
while (c <> Ord('p')) and (c <> 27) do
begin
c := cvWaitKey(250);
end;
end;
if (c = 27) then
break;
image := cvQueryFrame(capture);
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

View File

@ -0,0 +1,164 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{81D5962E-0A30-4ADE-996C-FA0F82BC01A3}</ProjectGuid>
<MainSource>CameraCalibrate.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Console</AppType>
<FrameworkType>None</FrameworkType>
<ProjectVersion>14.4</ProjectVersion>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
<Cfg_2_Win32>true</Cfg_2_Win32>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_E>false</DCC_E>
<VerInfo_Locale>1049</VerInfo_Locale>
<DCC_F>false</DCC_F>
<DCC_K>false</DCC_K>
<DCC_N>false</DCC_N>
<DCC_ExeOutput>..\..\bin\</DCC_ExeOutput>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace)</DCC_Namespace>
<Manifest_File>None</Manifest_File>
<DCC_ImageBase>00400000</DCC_ImageBase>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=;CFBundleDisplayName=;CFBundleIdentifier=;CFBundleVersion=;CFBundlePackageType=;CFBundleSignature=;CFBundleAllowMixedLocalizations=;CFBundleExecutable=</VerInfo_Keys>
<DCC_S>false</DCC_S>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<Debugger_RunParams>500 400 10</Debugger_RunParams>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<DCC_Namespace>System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_DebugInformation>false</DCC_DebugInformation>
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
<DCC_Optimize>false</DCC_Optimize>
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<Manifest_File>None</Manifest_File>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="..\..\include\LibName.pas"/>
<DCCReference Include="..\..\include\highgui\highgui_c.pas"/>
<DCCReference Include="..\..\include\сore\core_c.pas"/>
<DCCReference Include="..\..\include\сore\Core.types_c.pas"/>
<DCCReference Include="..\..\include\imgproc\imgproc.types_c.pas"/>
<DCCReference Include="..\..\include\imgproc\imgproc_c.pas"/>
<DCCReference Include="..\..\include\legacy\legacy.pas"/>
<DCCReference Include="..\..\include\calib3d\calib3d.pas"/>
<DCCReference Include="..\..\include\сore\types_c.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType/>
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">CameraCalibrate.dpr</Source>
</Source>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">0</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1049</VersionInfo>
<VersionInfo Name="CodePage">1251</VersionInfo>
</VersionInfo>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription"/>
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"/>
<VersionInfoKeys Name="LegalCopyright"/>
<VersionInfoKeys Name="LegalTrademarks"/>
<VersionInfoKeys Name="OriginalFilename"/>
<VersionInfoKeys Name="ProductName"/>
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"/>
<VersionInfoKeys Name="CFBundleName"/>
<VersionInfoKeys Name="CFBundleDisplayName"/>
<VersionInfoKeys Name="CFBundleIdentifier"/>
<VersionInfoKeys Name="CFBundleVersion"/>
<VersionInfoKeys Name="CFBundlePackageType"/>
<VersionInfoKeys Name="CFBundleSignature"/>
<VersionInfoKeys Name="CFBundleAllowMixedLocalizations"/>
<VersionInfoKeys Name="CFBundleExecutable"/>
</VersionInfoKeys>
</Delphi.Personality>
<Platforms>
<Platform value="OSX32">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
</Project>
<!-- EurekaLog First Line
[Exception Log]
EurekaLog Version=7001
Activate=0
DeleteMapAfterCompile=1
idEurekaLog=1
idEurekaLogDetailed=1
idMSClassic=1
idStepsToReproduce=1
ProjectID="{3523D48F-62EE-4A83-B09D-44E273C62429}"
TextsCollection="Russian"
EurekaLog Last Line -->

Binary file not shown.

View File

@ -64,7 +64,7 @@
<DCC_Optimize>false</DCC_Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<Debugger_RunParams>--cascade=resource\haarcascade_frontalface_alt.xml le</Debugger_RunParams>
<Debugger_RunParams>--cascade=resource\haarcascade_frontalface_alt.xml 0</Debugger_RunParams>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
</PropertyGroup>
@ -151,5 +151,4 @@
<!-- EurekaLog First Line
[Exception Log]
EurekaLog Version=7001
Encrypt Password=""
EurekaLog Last Line -->

View File

@ -117,6 +117,12 @@
<Projects Include="FaceDetect\FaceDetect.dproj">
<Dependencies/>
</Projects>
<Projects Include="Stereo\Stereo.dproj">
<Dependencies/>
</Projects>
<Projects Include="CameraCalibrate\CameraCalibrate.dproj">
<Dependencies/>
</Projects>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Default.Personality.12</Borland.Personality>
@ -467,14 +473,32 @@
<Target Name="FaceDetect:Make">
<MSBuild Projects="FaceDetect\FaceDetect.dproj" Targets="Make"/>
</Target>
<Target Name="Stereo">
<MSBuild Projects="Stereo\Stereo.dproj"/>
</Target>
<Target Name="Stereo:Clean">
<MSBuild Projects="Stereo\Stereo.dproj" Targets="Clean"/>
</Target>
<Target Name="Stereo:Make">
<MSBuild Projects="Stereo\Stereo.dproj" Targets="Make"/>
</Target>
<Target Name="CameraCalibrate">
<MSBuild Projects="CameraCalibrate\CameraCalibrate.dproj"/>
</Target>
<Target Name="CameraCalibrate:Clean">
<MSBuild Projects="CameraCalibrate\CameraCalibrate.dproj" Targets="Clean"/>
</Target>
<Target Name="CameraCalibrate:Make">
<MSBuild Projects="CameraCalibrate\CameraCalibrate.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
<CallTarget Targets="HelloWorld;cv_LoadImage;cv_LoadVideo;VideoProcessing;cv_LoadImage2;cv_CreateTrackbar;cv_CreateCameraCapture;cv_CreateVideoWriter;cv_SetMouseCallback;cv_Smooth;cv_Resize;cv_SetImageROI;cv_SetImageROI2;cv_Save;cv_RandInt;cv_Erode__cv_Dilate;cv_MorphologyEx;cv_CvtColor;cv_AddWeighted;cv_FloodFill;cv_SetImageROI__cv_AddWeighted;cv_Threshold__cv_AdaptiveThreshold;cv_InRangeS;ImageTransform_SplitMerge;cv_And;cv_CvtPixToPlane;cv_CopyMakeBorder;cv_Sobel;cv_Laplace;cv_Canny;cv_Sub;cv_HoughLines2;cv_HoughCircles;cv_Integral;cv_FindContours;CameraCaptureAndFindContours;cv_GetSubRect;FaceDetect"/>
<CallTarget Targets="HelloWorld;cv_LoadImage;cv_LoadVideo;VideoProcessing;cv_LoadImage2;cv_CreateTrackbar;cv_CreateCameraCapture;cv_CreateVideoWriter;cv_SetMouseCallback;cv_Smooth;cv_Resize;cv_SetImageROI;cv_SetImageROI2;cv_Save;cv_RandInt;cv_Erode__cv_Dilate;cv_MorphologyEx;cv_CvtColor;cv_AddWeighted;cv_FloodFill;cv_SetImageROI__cv_AddWeighted;cv_Threshold__cv_AdaptiveThreshold;cv_InRangeS;ImageTransform_SplitMerge;cv_And;cv_CvtPixToPlane;cv_CopyMakeBorder;cv_Sobel;cv_Laplace;cv_Canny;cv_Sub;cv_HoughLines2;cv_HoughCircles;cv_Integral;cv_FindContours;CameraCaptureAndFindContours;cv_GetSubRect;FaceDetect;Stereo;CameraCalibrate"/>
</Target>
<Target Name="Clean">
<CallTarget Targets="HelloWorld:Clean;cv_LoadImage:Clean;cv_LoadVideo:Clean;VideoProcessing:Clean;cv_LoadImage2:Clean;cv_CreateTrackbar:Clean;cv_CreateCameraCapture:Clean;cv_CreateVideoWriter:Clean;cv_SetMouseCallback:Clean;cv_Smooth:Clean;cv_Resize:Clean;cv_SetImageROI:Clean;cv_SetImageROI2:Clean;cv_Save:Clean;cv_RandInt:Clean;cv_Erode__cv_Dilate:Clean;cv_MorphologyEx:Clean;cv_CvtColor:Clean;cv_AddWeighted:Clean;cv_FloodFill:Clean;cv_SetImageROI__cv_AddWeighted:Clean;cv_Threshold__cv_AdaptiveThreshold:Clean;cv_InRangeS:Clean;ImageTransform_SplitMerge:Clean;cv_And:Clean;cv_CvtPixToPlane:Clean;cv_CopyMakeBorder:Clean;cv_Sobel:Clean;cv_Laplace:Clean;cv_Canny:Clean;cv_Sub:Clean;cv_HoughLines2:Clean;cv_HoughCircles:Clean;cv_Integral:Clean;cv_FindContours:Clean;CameraCaptureAndFindContours:Clean;cv_GetSubRect:Clean;FaceDetect:Clean"/>
<CallTarget Targets="HelloWorld:Clean;cv_LoadImage:Clean;cv_LoadVideo:Clean;VideoProcessing:Clean;cv_LoadImage2:Clean;cv_CreateTrackbar:Clean;cv_CreateCameraCapture:Clean;cv_CreateVideoWriter:Clean;cv_SetMouseCallback:Clean;cv_Smooth:Clean;cv_Resize:Clean;cv_SetImageROI:Clean;cv_SetImageROI2:Clean;cv_Save:Clean;cv_RandInt:Clean;cv_Erode__cv_Dilate:Clean;cv_MorphologyEx:Clean;cv_CvtColor:Clean;cv_AddWeighted:Clean;cv_FloodFill:Clean;cv_SetImageROI__cv_AddWeighted:Clean;cv_Threshold__cv_AdaptiveThreshold:Clean;cv_InRangeS:Clean;ImageTransform_SplitMerge:Clean;cv_And:Clean;cv_CvtPixToPlane:Clean;cv_CopyMakeBorder:Clean;cv_Sobel:Clean;cv_Laplace:Clean;cv_Canny:Clean;cv_Sub:Clean;cv_HoughLines2:Clean;cv_HoughCircles:Clean;cv_Integral:Clean;cv_FindContours:Clean;CameraCaptureAndFindContours:Clean;cv_GetSubRect:Clean;FaceDetect:Clean;Stereo:Clean;CameraCalibrate:Clean"/>
</Target>
<Target Name="Make">
<CallTarget Targets="HelloWorld:Make;cv_LoadImage:Make;cv_LoadVideo:Make;VideoProcessing:Make;cv_LoadImage2:Make;cv_CreateTrackbar:Make;cv_CreateCameraCapture:Make;cv_CreateVideoWriter:Make;cv_SetMouseCallback:Make;cv_Smooth:Make;cv_Resize:Make;cv_SetImageROI:Make;cv_SetImageROI2:Make;cv_Save:Make;cv_RandInt:Make;cv_Erode__cv_Dilate:Make;cv_MorphologyEx:Make;cv_CvtColor:Make;cv_AddWeighted:Make;cv_FloodFill:Make;cv_SetImageROI__cv_AddWeighted:Make;cv_Threshold__cv_AdaptiveThreshold:Make;cv_InRangeS:Make;ImageTransform_SplitMerge:Make;cv_And:Make;cv_CvtPixToPlane:Make;cv_CopyMakeBorder:Make;cv_Sobel:Make;cv_Laplace:Make;cv_Canny:Make;cv_Sub:Make;cv_HoughLines2:Make;cv_HoughCircles:Make;cv_Integral:Make;cv_FindContours:Make;CameraCaptureAndFindContours:Make;cv_GetSubRect:Make;FaceDetect:Make"/>
<CallTarget Targets="HelloWorld:Make;cv_LoadImage:Make;cv_LoadVideo:Make;VideoProcessing:Make;cv_LoadImage2:Make;cv_CreateTrackbar:Make;cv_CreateCameraCapture:Make;cv_CreateVideoWriter:Make;cv_SetMouseCallback:Make;cv_Smooth:Make;cv_Resize:Make;cv_SetImageROI:Make;cv_SetImageROI2:Make;cv_Save:Make;cv_RandInt:Make;cv_Erode__cv_Dilate:Make;cv_MorphologyEx:Make;cv_CvtColor:Make;cv_AddWeighted:Make;cv_FloodFill:Make;cv_SetImageROI__cv_AddWeighted:Make;cv_Threshold__cv_AdaptiveThreshold:Make;cv_InRangeS:Make;ImageTransform_SplitMerge:Make;cv_And:Make;cv_CvtPixToPlane:Make;cv_CopyMakeBorder:Make;cv_Sobel:Make;cv_Laplace:Make;cv_Canny:Make;cv_Sub:Make;cv_HoughLines2:Make;cv_HoughCircles:Make;cv_Integral:Make;cv_FindContours:Make;CameraCaptureAndFindContours:Make;cv_GetSubRect:Make;FaceDetect:Make;Stereo:Make;CameraCalibrate:Make"/>
</Target>
<Import Project="$(BDS)\Bin\CodeGear.Group.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')"/>
</Project>

102
samples/Stereo/Stereo.dpr Normal file
View File

@ -0,0 +1,102 @@
{$APPTYPE CONSOLE}
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
program Stereo;
{$R *.res}
uses
System.SysUtils,
LibName in '..\..\include\LibName.pas',
highgui_c in '..\..\include\highgui\highgui_c.pas',
core_c in '..\..\include\ñore\core_c.pas',
Core.types_c in '..\..\include\ñ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';
Const
Image_Left = 'StereoSample\Aloe\view0.png';
Image_Right = 'StereoSample\Aloe\view1.png';
// Êîëè÷åñòâî ðàçëè÷èé
ndisparity = 16;
// Êîëè÷åñòâî èòåðàöèé
mIter = 2;
Type
TDoubleArray = array [0 .. 15] 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
// çàãðóçêà òåñòîâûõ êàðòèíîê
image_ := cvLoadImage(Image_Left, 1);
image1_ := cvLoadImage(Image_Right, 1);
// ñîçäàíèå äîïîëíèòåëüíûõ èçîáðàæåíèé
image_g := cvCreateImage(cvSize(image_^.width, image_^.height), 8, 1);
image1_g := cvCreateImage(cvSize(image_^.width, image_^.height), 8, 1);
size := cvGetSize(image_);
// ñîçäàíèå ìàòðèö
disparity_left := cvCreateMat(size.height, size.width, CV_16S);
disparity_right := cvCreateMat(size.height, size.width, CV_16S);
// ïåðåâîä èçîáðàæåíèé ê ãðàäàöèÿì ñåðîãî
cvCvtColor(image_, image_g, CV_BGR2GRAY);
cvCvtColor(image1_, image1_g, CV_BGR2GRAY);
// çàäàíèå íà÷àëüíûõ ïàðàìåòðîâ ñòåðåîçðåíèÿ
//
state := cvCreateStereoGCState(ndisparity, mIter);
// âûïîëíåíèå îñíîâíîé ôóíêöèè ñòåðåîçðåíèÿ, âîçâðàùàþùåé ìàòðèöó 3d
cvFindStereoCorrespondenceGC(image_g, image1_g, disparity_left, disparity_right, state, 0);
cvReleaseStereoGCState(state);
// âûâîä ìàòðèöû â ôàéë
disparity_left_visual := cvCreateMat(size.height, size.width, CV_8U);
cvConvertScale(disparity_left, disparity_left_visual, -16);
cvSave('disparity.png', disparity_left_visual);
cvSaveImage('disparity.jpg', disparity_left_visual);
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)[10] := 0;
pDoubleArray(Q^.data)[11] := 524.04542174159019;
pDoubleArray(Q^.data)[12] := 0;
pDoubleArray(Q^.data)[13] := 0;
pDoubleArray(Q^.data)[14] := -0.30009508961926923;
pDoubleArray(Q^.data)[15] := 1.2438668093184739;
_3dImage := cvCreateImage(size, IPL_DEPTH_32F, 3);
cvReprojectImageTo3D(disparity_left_visual, _3dImage, Q);
cvSave('disparity1.png', _3dImage);
cvSaveImage('disparity1.jpg', _3dImage);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

155
samples/Stereo/Stereo.dproj Normal file
View File

@ -0,0 +1,155 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{5ADEFA32-1E0D-45B5-AB6B-B0E697C32BC3}</ProjectGuid>
<MainSource>Stereo.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Console</AppType>
<FrameworkType>None</FrameworkType>
<ProjectVersion>14.4</ProjectVersion>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
<Cfg_2_Win32>true</Cfg_2_Win32>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_E>false</DCC_E>
<VerInfo_Locale>1049</VerInfo_Locale>
<DCC_F>false</DCC_F>
<DCC_K>false</DCC_K>
<DCC_N>false</DCC_N>
<DCC_ExeOutput>..\..\Bin\</DCC_ExeOutput>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace)</DCC_Namespace>
<Manifest_File>None</Manifest_File>
<DCC_ImageBase>00400000</DCC_ImageBase>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=;CFBundleDisplayName=;CFBundleIdentifier=;CFBundleVersion=;CFBundlePackageType=;CFBundleSignature=;CFBundleAllowMixedLocalizations=;CFBundleExecutable=</VerInfo_Keys>
<DCC_S>false</DCC_S>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_DebugInformation>false</DCC_DebugInformation>
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
<DCC_Optimize>false</DCC_Optimize>
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<Manifest_File>None</Manifest_File>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="..\..\include\LibName.pas"/>
<DCCReference Include="..\..\include\highgui\highgui_c.pas"/>
<DCCReference Include="..\..\include\сore\core_c.pas"/>
<DCCReference Include="..\..\include\сore\Core.types_c.pas"/>
<DCCReference Include="..\..\include\imgproc\imgproc.types_c.pas"/>
<DCCReference Include="..\..\include\imgproc\imgproc_c.pas"/>
<DCCReference Include="..\..\include\legacy\legacy.pas"/>
<DCCReference Include="..\..\include\calib3d\calib3d.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType/>
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">Stereo.dpr</Source>
</Source>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">0</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1049</VersionInfo>
<VersionInfo Name="CodePage">1251</VersionInfo>
</VersionInfo>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription"/>
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"/>
<VersionInfoKeys Name="LegalCopyright"/>
<VersionInfoKeys Name="LegalTrademarks"/>
<VersionInfoKeys Name="OriginalFilename"/>
<VersionInfoKeys Name="ProductName"/>
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"/>
<VersionInfoKeys Name="CFBundleName"/>
<VersionInfoKeys Name="CFBundleDisplayName"/>
<VersionInfoKeys Name="CFBundleIdentifier"/>
<VersionInfoKeys Name="CFBundleVersion"/>
<VersionInfoKeys Name="CFBundlePackageType"/>
<VersionInfoKeys Name="CFBundleSignature"/>
<VersionInfoKeys Name="CFBundleAllowMixedLocalizations"/>
<VersionInfoKeys Name="CFBundleExecutable"/>
</VersionInfoKeys>
</Delphi.Personality>
<Platforms>
<Platform value="OSX32">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
</Project>
<!-- EurekaLog First Line
[Exception Log]
EurekaLog Version=7001
Encrypt Password=""
EurekaLog Last Line -->

BIN
samples/Stereo/Stereo.res Normal file

Binary file not shown.