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-31 22:30:13 +02:00
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
program CameraCalibrate;
2013-04-09 12:41:27 +02:00
{$APPTYPE CONSOLE}
{$POINTERMATH ON}
2013-03-31 22:30:13 +02:00
{$R *.res}
uses
System. SysUtils,
2013-04-09 12:41:27 +02:00
uLibName in '..\..\..\include\uLibName.pas' ,
highgui_c in '..\..\..\include\highgui\highgui_c.pas' ,
2013-04-18 08:34:16 +02:00
core_c in '..\..\..\include\core\core_c.pas' ,
Core. types_c in '..\..\..\include\core\Core.types_c.pas' ,
2013-04-09 12:41:27 +02:00
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' ,
imgproc in '..\..\..\include\imgproc\imgproc.pas' ,
haar in '..\..\..\include\objdetect\haar.pas' ,
objdetect in '..\..\..\include\objdetect\objdetect.pas' ,
tracking in '..\..\..\include\video\tracking.pas' ,
2013-04-18 08:34:16 +02:00
Core in '..\..\..\include\core\core.pas' ;
2013-03-31 22:30:13 +02:00
Var
2013-05-10 17:51:52 +02:00
// Setting the input list //<2F> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> c<EFBFBD> <63>
n_boards: Integer = 0 ;
// We are waiting for 20 frames with views chessboard//<2F> <> <EFBFBD> <EFBFBD> 20 <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63>
board_dt: Integer = 2 0 ;
2013-03-31 22:30:13 +02:00
board_w: Integer ;
board_h: Integer ;
board_n: Integer ;
board_sz: TCvSize;
2013-04-16 08:40:44 +02:00
capture: pCvCapture = nil ;
2013-03-31 22:30:13 +02:00
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 ;
begin
try
2013-04-02 00:17:25 +02:00
if ParamCount = 3 then
2013-03-31 22:30:13 +02:00
begin
2013-04-02 00:17:25 +02:00
board_w : = StrToInt( ParamStr( 1 ) ) ;
board_h : = StrToInt( ParamStr( 2 ) ) ;
n_boards : = StrToInt( ParamStr( 3 ) ) ;
end
else
begin
board_w : = 7 ;
board_h : = 3 ;
n_boards : = 1 0 ;
2013-03-31 22:30:13 +02:00
end ;
board_n : = board_w * board_h;
2013-04-02 00:17:25 +02:00
Writeln( 'Cells: ' , board_n) ;
2013-03-31 22:30:13 +02:00
board_sz : = cvSize( board_w, board_h) ;
2013-04-02 00:17:25 +02:00
capture : = cvCreateCameraCapture( CV_CAP_ANY) ;
2013-03-31 22:30:13 +02:00
assert( Assigned( capture) ) ;
cvNamedWindow( 'Calibration' ) ;
2013-05-10 17:51:52 +02:00
// Allocates memory for data storage//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-03-31 22:30:13 +02:00
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) ;
2013-04-02 00:17:25 +02:00
corners : = AllocMem( SizeOf( TCvPoint2D32f) * board_n) ;
2013-03-31 22:30:13 +02:00
image : = cvQueryFrame( capture) ;
gray_image : = cvCreateImage( cvGetSize( image) , 8 , 1 ) ; // subpixel
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> n_boards
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (<28> c<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> c<EFBFBD> <63> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
2013-05-10 17:51:52 +02:00
///
// IMAGE CAPTURE in the cycles with angles until we got n_boards
// Total capture (all the angles on the board WERE FOUND)
2013-03-31 22:30:13 +02:00
while ( successes < n_boards) do
begin
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <EFBFBD> <EFBFBD> board_dt <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <EFBFBD> <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> <20> <> c<EFBFBD> <63>
2013-05-10 17:51:52 +02:00
// Skip the "board_dt" frames supplied by the user to move the board
2013-05-12 00:43:40 +02:00
if ( ( frame mod board_dt) = 0 ) then //At this point - the error is found and corrected CLubfitter73
2013-03-31 22:30:13 +02:00
begin
2013-04-02 00:17:25 +02:00
Writeln( 'Successes: ' , successes) ;
2013-05-10 17:51:52 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63>
// Find the corners of the chessboard
2013-03-31 22:30:13 +02:00
found : = cvFindChessboardCorners( image, board_sz, corners, @ corner_count, CV_CALIB_CB_ADAPTIVE_THRESH or
CV_CALIB_CB_FILTER_QUADS) ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <20> <> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
2013-05-10 17:51:52 +02:00
// Getting a sub-pixel accuracy on these corners
2013-03-31 22:30:13 +02:00
cvCvtColor( image, gray_image, CV_BGR2GRAY) ;
cvFindCornerSubPix( gray_image, corners, corner_count, cvSize( 1 1 , 1 1 ) , cvSize( - 1 , - 1 ) ,
cvTermCriteria( CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 3 0 , 0.1 ) ) ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <EFBFBD> <20> <> <EFBFBD>
2013-05-10 17:51:52 +02:00
// Let's draw it
2013-03-31 22:30:13 +02:00
cvDrawChessboardCorners( image, board_sz, corners, corner_count, found) ;
cvShowImage( 'Calibration' , image) ;
2013-04-18 08:34:16 +02:00
// <20> c<EFBFBD> <63> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-05-10 17:51:52 +02:00
// If we got a good board, add it to our data
2013-03-31 22:30:13 +02:00
if ( corner_count = board_n) then
begin
step : = successes * board_n;
i : = step;
j : = 0 ;
2013-05-12 00:43:40 +02:00
while j < board_n do //At this point - the error is found and corrected CLubfitter73
2013-03-31 22:30:13 +02:00
begin
2013-04-09 12:41:27 +02:00
pSingle( CV_MAT_ELEM( image_points^ , SizeOf( Single ) , i, 0 ) ) ^ : = corners[ j] . x;
pSingle( CV_MAT_ELEM( image_points^ , SizeOf( Single ) , i, 1 ) ) ^ : = corners[ j] . y;
pSingle( CV_MAT_ELEM( object_points^ , SizeOf( Single ) , i, 0 ) ) ^ : = j / board_w;
pSingle( CV_MAT_ELEM( object_points^ , SizeOf( Single ) , i, 1 ) ) ^ : = j div board_w;
pSingle( CV_MAT_ELEM( object_points^ , SizeOf( Single ) , i, 2 ) ) ^ : = 0 ;
2013-03-31 22:30:13 +02:00
Inc( i) ;
Inc( j) ;
end ;
2013-04-09 12:41:27 +02:00
pInteger( CV_MAT_ELEM( point_counts^ , SizeOf( Integer ) , successes, 0 ) ) ^ : = board_n;
2013-03-31 22:30:13 +02:00
Inc( successes) ;
end ;
end ; // end skip board_dt between chessboard capture
// Handle pause/unpause and ESC
c : = cvWaitKey( 1 5 ) ;
if ( c = Ord( 'p' ) ) then
begin
c : = 0 ;
while ( c < > Ord( 'p' ) ) and ( c < > 2 7 ) do
begin
2013-04-02 00:17:25 +02:00
c : = cvWaitKey( 5 0 ) ;
2013-03-31 22:30:13 +02:00
end ;
end ;
if ( c = 2 7 ) then
2013-04-15 18:14:12 +02:00
begin
2013-05-10 17:51:52 +02:00
// release resources//<2F> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63> c<EFBFBD>
// cvReleaseImage(mapx); - This has zero//<2F> <> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// cvReleaseImage(mapy); - This has zero//<2F> <> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-04-15 18:14:12 +02:00
cvReleaseImage( gray_image) ;
2013-05-10 17:51:52 +02:00
// cvReleaseImage(image); - this can not be//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-04-18 08:34:16 +02:00
// c<> . http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=cvqueryframe#IplImage*%20cvQueryFrame%28CvCapture*%20capture%29
2013-04-16 08:40:44 +02:00
// Note
// OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image
// stored inside the video capturing structure. It is not allowed to modify
// or release the image! You can copy the frame using cvCloneImage()
// and then do whatever you want with the copy.
//
2013-04-15 18:14:12 +02:00
cvReleaseMat( object_points) ;
cvReleaseMat( image_points) ;
cvReleaseMat( point_counts) ;
cvReleaseMat( intrinsic_matrix) ;
cvReleaseMat( distortion_coeffs) ;
cvReleaseCapture( capture) ;
cvDestroyAllWindows;
2013-03-31 22:30:13 +02:00
Halt;
2013-04-15 18:14:12 +02:00
end ;
2013-05-10 17:51:52 +02:00
image : = cvQueryFrame( capture) ; // We get the following picture//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-05-12 00:43:40 +02:00
Inc( frame) ; //At this point - the error is found and corrected CLubfitter73
2013-05-10 17:51:52 +02:00
end ;
2013-03-31 22:30:13 +02:00
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> , c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-05-10 17:51:52 +02:00
// MATRIX is allocated to that amount of a chessboard, how much was FOUND
2013-03-31 22:30:13 +02:00
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) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-05-10 17:51:52 +02:00
// Move point in the matrix of the correct size of
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
2013-05-10 17:51:52 +02:00
// Below, we describe it in detail in the next two cycles.
2013-03-31 22:30:13 +02:00
i : = 0 ;
While i < successes * board_n do
begin
2013-04-09 12:41:27 +02:00
pSingle( CV_MAT_ELEM( image_points2^ , SizeOf( Single ) , i, 0 ) ) ^ : =
pSingle( CV_MAT_ELEM( image_points^ , SizeOf( Single ) , i, 0 ) ) ^ ;
pSingle( CV_MAT_ELEM( image_points2^ , SizeOf( Single ) , i, 1 ) ) ^ : =
pSingle( CV_MAT_ELEM( image_points^ , SizeOf( Single ) , i, 1 ) ) ^ ;
pSingle( CV_MAT_ELEM( object_points2^ , SizeOf( Single ) , i, 0 ) ) ^ : =
pSingle( CV_MAT_ELEM( object_points^ , SizeOf( Single ) , i, 0 ) ) ^ ;
pSingle( CV_MAT_ELEM( object_points2^ , SizeOf( Single ) , i, 1 ) ) ^ : =
pSingle( CV_MAT_ELEM( object_points^ , SizeOf( Single ) , i, 1 ) ) ^ ;
pSingle( CV_MAT_ELEM( object_points2^ , SizeOf( Single ) , i, 2 ) ) ^ : =
pSingle( CV_MAT_ELEM( object_points^ , SizeOf( Single ) , i, 2 ) ) ^ ;
2013-03-31 22:30:13 +02:00
Inc( i) ;
end ;
i : = 0 ;
While i < successes do
2013-05-10 17:51:52 +02:00
begin // There are the same number//<2F> <> <EFBFBD> c<EFBFBD> <20> c<EFBFBD> <20> <> <20> <> <20> <> c<EFBFBD> <63>
2013-04-09 12:41:27 +02:00
pInteger( CV_MAT_ELEM( point_counts2^ , SizeOf( Integer ) , i, 0 ) ) ^ : =
pInteger( CV_MAT_ELEM( point_counts^ , SizeOf( Integer ) , i, 0 ) ) ^ ;
2013-03-31 22:30:13 +02:00
Inc( i) ;
end ;
cvReleaseMat( object_points) ;
cvReleaseMat( image_points) ;
cvReleaseMat( point_counts) ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> c<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> .
2013-03-31 22:30:13 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> , <20> <> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2013-04-18 08:34:16 +02:00
// <20> ccc<63> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 1.0
2013-05-10 17:51:52 +02:00
///
// For these points we have all thumbnails corners of chess board that we need.
// Initialize the matrix of internal parameters so that the two focal
// Distance will have a ratio of 1.0
2013-03-31 22:30:13 +02:00
2013-04-02 00:17:25 +02:00
cvZero( intrinsic_matrix) ;
// pSingle(CV_MAT_ELEM(intrinsic_matrix^, CV_32FC1, 0, 0))^ := 1;
// pSingle(CV_MAT_ELEM(intrinsic_matrix^, CV_32FC1, 1, 1))^ := 1;
// pSingle(CV_MAT_ELEM(intrinsic_matrix^, CV_32FC1, 2, 2))^ := 1;
2013-05-12 00:43:40 +02:00
// pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 0, 0))^ := 520.0;
// pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 1, 1))^ := 520.0;
// pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 2, 2))^ := 1;
// pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 0, 2))^ := 70.0;
// pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 1, 2))^ := 70.0;
//At this point - the error is found and corrected CLubfitter73
pSingle( CV_MAT_ELEM( intrinsic_matrix^ , SizeOf( Single ) , 0 , 0 ) ) ^ : = 1 ;
pSingle( CV_MAT_ELEM( intrinsic_matrix^ , SizeOf( Single ) , 1 , 1 ) ) ^ : = 1 ;
2013-04-02 00:17:25 +02:00
for i : = 0 to intrinsic_matrix^ . rows - 1 do
begin
for j : = 0 to intrinsic_matrix^ . cols - 1 do
2013-04-09 12:41:27 +02:00
Write( Format( '%.0f ' , [ pSingle( CV_MAT_ELEM( intrinsic_matrix^ , SizeOf( Single ) , i, j) ) ^ ] ) ) ;
2013-04-02 00:17:25 +02:00
Writeln;
end ;
Writeln;
2013-03-31 22:30:13 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> !
2013-05-10 17:51:52 +02:00
// Calibrating the camera!
2013-03-31 22:30:13 +02:00
cvCalibrateCamera2( object_points2, image_points2, point_counts2, cvGetSize( image) , intrinsic_matrix,
2013-04-02 00:17:25 +02:00
distortion_coeffs, nil , nil ,
// {}0,
2013-05-12 00:43:40 +02:00
{ } CV_CALIB_FIX_ASPECT_RATIO,
// {}CV_CALIB_USE_INTRINSIC_GUESS,
2013-04-02 00:17:25 +02:00
{ } cvTermCriteria( CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 3 0 , DBL_EPSILON) ) ;
2013-03-31 22:30:13 +02:00
2013-05-10 17:51:52 +02:00
// <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> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// Parameters and maintains internal distortion
2013-04-02 00:17:25 +02:00
cvSave( 'result\Intrinsics.xml' , intrinsic_matrix) ;
cvSave( 'result\Distortion.xml' , distortion_coeffs) ;
// -------------------------------------------------------------
2013-03-31 22:30:13 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> :
2013-05-10 17:51:52 +02:00
// Loading examples of these matrices back into the program:
2013-04-02 00:17:25 +02:00
intrinsic : = cvLoad( 'result\Intrinsics.xml' ) ;
Distortion : = cvLoad( 'result\Distortion.xml' ) ;
2013-03-31 22:30:13 +02:00
2013-04-18 08:34:16 +02:00
// c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> c<EFBFBD> <63> <EFBFBD> c<EFBFBD> <63> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// <20> <> <EFBFBD> <20> c<EFBFBD> <63> <20> <> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
2013-05-10 17:51:52 +02:00
// Construct a map andictorcii, we will use for all pocleduyuschih frames.
2013-03-31 22:30:13 +02:00
mapx : = cvCreateImage( cvGetSize( image) , IPL_DEPTH_32F, 1 ) ;
mapy : = cvCreateImage( cvGetSize( image) , IPL_DEPTH_32F, 1 ) ;
cvInitUndistortMap( intrinsic, Distortion, mapx, mapy) ;
2013-04-18 08:34:16 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , c<> <63> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> c<> <63> <EFBFBD> <EFBFBD>
// <20> <20> <> <EFBFBD> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
2013-05-10 17:51:52 +02:00
// Display on the screen is what gets camera - raw image
2013-03-31 22:30:13 +02:00
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( 1 5 ) ;
if ( c = Ord( 'p' ) ) then
begin
c : = 0 ;
while ( c < > Ord( 'p' ) ) and ( c < > 2 7 ) do
begin
c : = cvWaitKey( 2 5 0 ) ;
end ;
end ;
if ( c = 2 7 ) then
break;
image : = cvQueryFrame( capture) ;
end ;
2013-05-10 17:51:52 +02:00
// release resources//<2F> c<EFBFBD> <63> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> c<EFBFBD> <63> c<EFBFBD>
2013-04-15 18:14:12 +02:00
cvReleaseImage( mapx) ;
cvReleaseImage( mapy) ;
cvReleaseImage( gray_image) ;
cvReleaseMat( intrinsic_matrix) ;
cvReleaseMat( distortion_coeffs) ;
cvReleaseMat( object_points2) ;
cvReleaseMat( image_points2) ;
cvReleaseMat( point_counts2) ;
cvReleaseCapture( capture) ;
cvDestroyAllWindows;
2013-03-31 22:30:13 +02:00
except
on E: Exception do
Writeln( E. ClassName, ': ' , E. Message ) ;
end ;
end .