Merge pull request #3938 from paroj:triangulatecpp

pull/3948/head
Vadim Pisarevsky 10 years ago
commit 99d0fcf49d
  1. 57
      modules/calib3d/src/triangulate.cpp
  2. 8
      modules/core/include/opencv2/core.hpp

@ -63,8 +63,7 @@ cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2, CvMat* projPoints1, CvMa
!CV_IS_MAT(points4D) ) !CV_IS_MAT(points4D) )
CV_Error( CV_StsUnsupportedFormat, "Input parameters must be matrices" ); CV_Error( CV_StsUnsupportedFormat, "Input parameters must be matrices" );
int numPoints; int numPoints = projPoints1->cols;
numPoints = projPoints1->cols;
if( numPoints < 1 ) if( numPoints < 1 )
CV_Error( CV_StsOutOfRange, "Number of points must be more than zero" ); CV_Error( CV_StsOutOfRange, "Number of points must be more than zero" );
@ -82,57 +81,39 @@ cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2, CvMat* projPoints1, CvMa
projMatr2->cols != 4 || projMatr2->rows != 3) projMatr2->cols != 4 || projMatr2->rows != 3)
CV_Error( CV_StsUnmatchedSizes, "Size of projection matrices must be 3x4" ); CV_Error( CV_StsUnmatchedSizes, "Size of projection matrices must be 3x4" );
CvMat matrA; // preallocate SVD matrices on stack
double matrA_dat[24]; cv::Matx<double, 6, 4> matrA;
matrA = cvMat(6,4,CV_64F,matrA_dat); cv::Matx<double, 6, 4> matrU;
cv::Matx<double, 4, 1> matrW;
cv::Matx<double, 4, 4> matrV;
//CvMat matrU; CvMat* projPoints[2] = {projPoints1, projPoints2};
CvMat matrW; CvMat* projMatrs[2] = {projMatr1, projMatr2};
CvMat matrV;
//double matrU_dat[9*9];
double matrW_dat[6*4];
double matrV_dat[4*4];
//matrU = cvMat(6,6,CV_64F,matrU_dat);
matrW = cvMat(6,4,CV_64F,matrW_dat);
matrV = cvMat(4,4,CV_64F,matrV_dat);
CvMat* projPoints[2];
CvMat* projMatrs[2];
projPoints[0] = projPoints1;
projPoints[1] = projPoints2;
projMatrs[0] = projMatr1;
projMatrs[1] = projMatr2;
/* Solve system for each point */ /* Solve system for each point */
int i,j; for( int i = 0; i < numPoints; i++ )/* For each point */
for( i = 0; i < numPoints; i++ )/* For each point */
{ {
/* Fill matrix for current point */ /* Fill matrix for current point */
for( j = 0; j < 2; j++ )/* For each view */ for( int j = 0; j < 2; j++ )/* For each view */
{ {
double x,y; double x,y;
x = cvmGet(projPoints[j],0,i); x = cvmGet(projPoints[j],0,i);
y = cvmGet(projPoints[j],1,i); y = cvmGet(projPoints[j],1,i);
for( int k = 0; k < 4; k++ ) for( int k = 0; k < 4; k++ )
{ {
cvmSet(&matrA, j*3+0, k, x * cvmGet(projMatrs[j],2,k) - cvmGet(projMatrs[j],0,k) ); matrA(j*3+0, k) = x * cvmGet(projMatrs[j],2,k) - cvmGet(projMatrs[j],0,k);
cvmSet(&matrA, j*3+1, k, y * cvmGet(projMatrs[j],2,k) - cvmGet(projMatrs[j],1,k) ); matrA(j*3+1, k) = y * cvmGet(projMatrs[j],2,k) - cvmGet(projMatrs[j],1,k);
cvmSet(&matrA, j*3+2, k, x * cvmGet(projMatrs[j],1,k) - y * cvmGet(projMatrs[j],0,k) ); matrA(j*3+2, k) = x * cvmGet(projMatrs[j],1,k) - y * cvmGet(projMatrs[j],0,k);
} }
} }
/* Solve system for current point */ /* Solve system for current point */
{ cv::SVD::compute(matrA, matrW, matrU, matrV);
cvSVD(&matrA,&matrW,0,&matrV,CV_SVD_V_T);
/* Copy computed point */ /* Copy computed point */
cvmSet(points4D,0,i,cvmGet(&matrV,3,0));/* X */ cvmSet(points4D,0,i,matrV(3,0));/* X */
cvmSet(points4D,1,i,cvmGet(&matrV,3,1));/* Y */ cvmSet(points4D,1,i,matrV(3,1));/* Y */
cvmSet(points4D,2,i,cvmGet(&matrV,3,2));/* Z */ cvmSet(points4D,2,i,matrV(3,2));/* Z */
cvmSet(points4D,3,i,cvmGet(&matrV,3,3));/* W */ cvmSet(points4D,3,i,matrV(3,3));/* W */
}
} }
#if 0 #if 0

@ -2451,9 +2451,7 @@ matrix. The Singular Value Decomposition is used to solve least-square
problems, under-determined linear systems, invert matrices, compute problems, under-determined linear systems, invert matrices, compute
condition numbers, and so on. condition numbers, and so on.
For a faster operation, you can pass flags=SVD::MODIFY_A|... to modify If you want to compute a condition number of a matrix or an absolute value of
the decomposed matrix when it is not necessary to preserve it. If you
want to compute a condition number of a matrix or an absolute value of
its determinant, you do not need `u` and `vt`. You can pass its determinant, you do not need `u` and `vt`. You can pass
flags=SVD::NO_UV|... . Another flag SVD::FULL_UV indicates that full-size u flags=SVD::NO_UV|... . Another flag SVD::FULL_UV indicates that full-size u
and vt must be computed, which is not necessary most of the time. and vt must be computed, which is not necessary most of the time.
@ -2464,8 +2462,8 @@ class CV_EXPORTS SVD
{ {
public: public:
enum Flags { enum Flags {
/** use the algorithm to modify the decomposed matrix; it can save space and speed up /** allow the algorithm to modify the decomposed matrix; it can save space and speed up
processing */ processing. currently ignored. */
MODIFY_A = 1, MODIFY_A = 1,
/** indicates that only a vector of singular values `w` is to be processed, while u and vt /** indicates that only a vector of singular values `w` is to be processed, while u and vt
will be set to empty matrices */ will be set to empty matrices */

Loading…
Cancel
Save