calibrationMatrixValues: bind C++ function in C instead of vice versa

pull/6480/head
Pavel Rojtberg 9 years ago
parent 6e5e5d87df
commit 86959310f9
  1. 85
      modules/calib3d/src/calibration.cpp

@ -1626,58 +1626,24 @@ void cvCalibrationMatrixValues( const CvMat *calibMatr, CvSize imgSize,
double apertureWidth, double apertureHeight, double *fovx, double *fovy, double apertureWidth, double apertureHeight, double *fovx, double *fovy,
double *focalLength, CvPoint2D64f *principalPoint, double *pasp ) double *focalLength, CvPoint2D64f *principalPoint, double *pasp )
{ {
double alphax, alphay, mx, my;
int imgWidth = imgSize.width, imgHeight = imgSize.height;
/* Validate parameters. */ /* Validate parameters. */
if(calibMatr == 0) if(calibMatr == 0)
CV_Error(CV_StsNullPtr, "Some of parameters is a NULL pointer!"); CV_Error(CV_StsNullPtr, "Some of parameters is a NULL pointer!");
if(!CV_IS_MAT(calibMatr)) if(!CV_IS_MAT(calibMatr))
CV_Error(CV_StsUnsupportedFormat, "Input parameters must be a matrices!"); CV_Error(CV_StsUnsupportedFormat, "Input parameters must be a matrices!");
if(calibMatr->cols != 3 || calibMatr->rows != 3) double dummy;
CV_Error(CV_StsUnmatchedSizes, "Size of matrices must be 3x3!"); Point2d pp;
cv::calibrationMatrixValues(cvarrToMat(calibMatr), imgSize, apertureWidth, apertureHeight,
alphax = cvmGet(calibMatr, 0, 0); fovx ? *fovx : dummy,
alphay = cvmGet(calibMatr, 1, 1); fovy ? *fovy : dummy,
assert(imgWidth != 0 && imgHeight != 0 && alphax != 0.0 && alphay != 0.0); focalLength ? *focalLength : dummy,
pp,
/* Calculate pixel aspect ratio. */ pasp ? *pasp : dummy);
if(pasp)
*pasp = alphay / alphax;
/* Calculate number of pixel per realworld unit. */
if(apertureWidth != 0.0 && apertureHeight != 0.0) {
mx = imgWidth / apertureWidth;
my = imgHeight / apertureHeight;
} else {
mx = 1.0;
if(pasp)
my = *pasp;
else
my = 1.0;
}
/* Calculate fovx and fovy. */
if(fovx)
*fovx = 2 * atan(imgWidth / (2 * alphax)) * 180.0 / CV_PI;
if(fovy)
*fovy = 2 * atan(imgHeight / (2 * alphay)) * 180.0 / CV_PI;
/* Calculate focal length. */
if(focalLength)
*focalLength = alphax / mx;
/* Calculate principle point. */
if(principalPoint) if(principalPoint)
*principalPoint = cvPoint2D64f(cvmGet(calibMatr, 0, 2) / mx, cvmGet(calibMatr, 1, 2) / my); *principalPoint = cvPoint2D64f(pp.x, pp.y);
} }
@ -3369,10 +3335,35 @@ void cv::calibrationMatrixValues( InputArray _cameraMatrix, Size imageSize,
double& fovx, double& fovy, double& focalLength, double& fovx, double& fovy, double& focalLength,
Point2d& principalPoint, double& aspectRatio ) Point2d& principalPoint, double& aspectRatio )
{ {
Mat cameraMatrix = _cameraMatrix.getMat(); if(_cameraMatrix.size() != Size(3, 3))
CvMat c_cameraMatrix = cameraMatrix; CV_Error(CV_StsUnmatchedSizes, "Size of cameraMatrix must be 3x3!");
cvCalibrationMatrixValues( &c_cameraMatrix, imageSize, apertureWidth, apertureHeight,
&fovx, &fovy, &focalLength, (CvPoint2D64f*)&principalPoint, &aspectRatio ); Matx33d K = _cameraMatrix.getMat();
CV_DbgAssert(imageSize.width != 0 && imageSize.height != 0 && K(0, 0) != 0.0 && K(1, 1) != 0.0);
/* Calculate pixel aspect ratio. */
aspectRatio = K(1, 1) / K(0, 0);
/* Calculate number of pixel per realworld unit. */
double mx, my;
if(apertureWidth != 0.0 && apertureHeight != 0.0) {
mx = imageSize.width / apertureWidth;
my = imageSize.height / apertureHeight;
} else {
mx = 1.0;
my = aspectRatio;
}
/* Calculate fovx and fovy. */
fovx = 2 * atan(imageSize.width / (2 * K(0, 0))) * 180.0 / CV_PI;
fovy = 2 * atan(imageSize.height / (2 * K(1, 1))) * 180.0 / CV_PI;
/* Calculate focal length. */
focalLength = K(0, 0) / mx;
/* Calculate principle point. */
principalPoint = Point2d(K(0, 2) / mx, K(1, 2) / my);
} }
double cv::stereoCalibrate( InputArrayOfArrays _objectPoints, double cv::stereoCalibrate( InputArrayOfArrays _objectPoints,

Loading…
Cancel
Save