Skip to content

Commit

Permalink
convertTo/assignTo does not need a channel value
Browse files Browse the repository at this point in the history
  • Loading branch information
cv3d committed Sep 21, 2018
1 parent 295b988 commit 548acff
Show file tree
Hide file tree
Showing 111 changed files with 547 additions and 511 deletions.
6 changes: 3 additions & 3 deletions modules/calib3d/src/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ CV_IMPL int cvRodrigues2( const CvMat* src, CvMat* dst, CvMat* jacobian )
// R = cos(theta)*I + (1 - cos(theta))*r*rT + sin(theta)*[r_x]
Matx33d R = c*Matx33d::eye() + c1*rrt + s*r_x;

Mat(R).convertTo(cvarrToMat(dst), dst->type);
Mat(R).convertTo(cvarrToMat(dst), CV_MAT_DEPTH(dst->type));

if( jacobian )
{
Expand Down Expand Up @@ -3195,7 +3195,7 @@ static Mat prepareCameraMatrix(Mat& cameraMatrix0, int rtype)
{
Mat cameraMatrix = Mat::eye(3, 3, rtype);
if( cameraMatrix0.size() == cameraMatrix.size() )
cameraMatrix0.convertTo(cameraMatrix, rtype);
cameraMatrix0.convertTo(cameraMatrix, CV_MAT_DEPTH(rtype));
return cameraMatrix;
}

Expand All @@ -3215,7 +3215,7 @@ static Mat prepareDistCoeffs(Mat& distCoeffs0, int rtype, int outputSize = 14)
distCoeffs0.size() == Size(14, 1) )
{
Mat dstCoeffs(distCoeffs, Rect(0, 0, distCoeffs0.cols, distCoeffs0.rows));
distCoeffs0.convertTo(dstCoeffs, rtype);
distCoeffs0.convertTo(dstCoeffs, CV_MAT_DEPTH(rtype));
}
return distCoeffs;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/calib3d/src/chessboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void polyfit(const Mat& src_x, const Mat& src_y, Mat& dst, int order)
}
cv::Mat w;
solve(A,srcY,w,DECOMP_SVD);
w.convertTo(dst,std::max(std::max(src_x.depth(), src_y.depth()), CV_32F));
w.convertTo(dst, CV_MAX_DEPTH(src_x.depth(), src_y.depth(), CV_32F));
}

float calcSignedDistance(const cv::Vec2f &n,const cv::Point2f &a,const cv::Point2f &pt)
Expand Down Expand Up @@ -1196,7 +1196,7 @@ void Chessboard::Board::draw(cv::InputArray m,cv::OutputArray out,cv::InputArray
double maxVal,minVal;
cv::minMaxLoc(image, &minVal, &maxVal);
double scale = 255.0/(maxVal-minVal);
image.convertTo(image,CV_8UC1,scale,-scale*minVal);
image.convertTo(image,CV_8U,scale,-scale*minVal);
cv::applyColorMap(image,image,cv::COLORMAP_JET);
}

Expand Down
12 changes: 6 additions & 6 deletions modules/calib3d/src/compat_ptsetreg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ CV_IMPL int cvFindHomography( const CvMat* _src, const CvMat* _dst, CvMat* __H,
Hz.setTo(cv::Scalar::all(0));
return 0;
}
H0.convertTo(H, H.type());
H0.convertTo(H, H.depth());
return 1;
}

Expand Down Expand Up @@ -389,7 +389,7 @@ CV_IMPL int cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,

CV_Assert( FM0.cols == 3 && FM0.rows % 3 == 0 && FM.cols == 3 && FM.rows % 3 == 0 && FM.channels() == 1 );
cv::Mat FM1 = FM.rowRange(0, MIN(FM0.rows, FM.rows));
FM0.rowRange(0, FM1.rows).convertTo(FM1, FM1.type());
FM0.rowRange(0, FM1.rows).convertTo(FM1, FM1.depth());
return FM1.rows / 3;
}

Expand Down Expand Up @@ -417,14 +417,14 @@ CV_IMPL void cvComputeCorrespondEpilines( const CvMat* points, int pointImageID,
else
{
transpose( lines, lines );
lines.convertTo( lines0, lines0.type() );
lines.convertTo( lines0, lines0.depth() );
}
}
else
{
CV_Assert( lines.size() == lines0.size() );
if( lines.data != lines0.data )
lines.convertTo(lines0, lines0.type());
lines.convertTo(lines0, lines0.depth());
}
}

Expand Down Expand Up @@ -459,13 +459,13 @@ CV_IMPL void cvConvertPointsHomogeneous( const CvMat* _src, CvMat* _dst )
else
{
transpose( dst, dst );
dst.convertTo( dst0, dst0.type() );
dst.convertTo(dst0, dst0.depth());
}
}
else
{
CV_Assert( dst.size() == dst0.size() );
if( dst.data != dst0.data )
dst.convertTo(dst0, dst0.type());
dst.convertTo(dst0, dst0.depth());
}
}
2 changes: 1 addition & 1 deletion modules/calib3d/src/dls.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ class EigenvalueDecomposition {
// Convert the given input matrix to double. Is there any way to
// prevent allocating the temporary memory? Only used for copying
// into working memory and deallocated after.
src.getMat().convertTo(tmp, CV_64FC1);
src.getMat().convertTo(tmp, CV_64F);
// Get dimension of the matrix.
this->n = tmp.cols;
// Allocate the matrix data to work on.
Expand Down
54 changes: 27 additions & 27 deletions modules/calib3d/src/fisheye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input

Mat(Matx33d(new_f[0], 0, new_c[0],
0, new_f[1], new_c[1],
0, 0, 1)).convertTo(P, P.empty() ? K.type() : P.type());
0, 0, 1)).convertTo(P, P.empty() ? K.depth() : P.depth());
}


Expand Down Expand Up @@ -664,9 +664,9 @@ void cv::fisheye::stereoRectify( InputArray K1, InputArray D1, InputArray K2, In

// apply to both views
Matx33d ri1 = wr * r_r.t();
Mat(ri1, false).convertTo(R1, R1.empty() ? CV_64F : R1.type());
Mat(ri1, false).convertTo(R1, R1.empty() ? CV_64F : R1.depth());
Matx33d ri2 = wr * r_r;
Mat(ri2, false).convertTo(R2, R2.empty() ? CV_64F : R2.type());
Mat(ri2, false).convertTo(R2, R2.empty() ? CV_64F : R2.depth());
Vec3d tnew = ri2 * tvec;

// calculate projection/camera matrices. these contain the relevant rectified image internal params (fx, fy=fx, cx, cy)
Expand All @@ -687,11 +687,11 @@ void cv::fisheye::stereoRectify( InputArray K1, InputArray D1, InputArray K2, In

Mat(Matx34d(fc_new, 0, cc_new[0].x, 0,
0, fc_new, cc_new[0].y, 0,
0, 0, 1, 0), false).convertTo(P1, P1.empty() ? CV_64F : P1.type());
0, 0, 1, 0), false).convertTo(P1, P1.empty() ? CV_64F : P1.depth());

Mat(Matx34d(fc_new, 0, cc_new[1].x, tnew[0]*fc_new, // baseline * focal length;,
0, fc_new, cc_new[1].y, 0,
0, 0, 1, 0), false).convertTo(P2, P2.empty() ? CV_64F : P2.type());
0, 0, 1, 0), false).convertTo(P2, P2.empty() ? CV_64F : P2.depth());

if (Q.needed())
Mat(Matx44d(1, 0, 0, -cc_new[0].x,
Expand Down Expand Up @@ -747,8 +747,8 @@ double cv::fisheye::calibrate(InputArrayOfArrays objectPoints, InputArrayOfArray
Vec4d _D;
if (flags & CALIB_USE_INTRINSIC_GUESS)
{
K.getMat().convertTo(_K, CV_64FC1);
D.getMat().convertTo(_D, CV_64FC1);
K.getMat().convertTo(_K, CV_64F);
D.getMat().convertTo(_D, CV_64F);
finalParam.Init(Vec2d(_K(0,0), _K(1, 1)),
Vec2d(_K(0,2), _K(1, 2)),
Vec4d(flags & CALIB_FIX_K1 ? 0 : _D[0],
Expand Down Expand Up @@ -810,8 +810,8 @@ double cv::fisheye::calibrate(InputArrayOfArrays objectPoints, InputArrayOfArray
0, finalParam.f[1], finalParam.c[1],
0, 0, 1);

if (K.needed()) cv::Mat(_K).convertTo(K, K.empty() ? CV_64FC1 : K.type());
if (D.needed()) cv::Mat(finalParam.k).convertTo(D, D.empty() ? CV_64FC1 : D.type());
if (K.needed()) cv::Mat(_K).convertTo(K, K.empty() ? CV_64F : K.depth());
if (D.needed()) cv::Mat(finalParam.k).convertTo(D, D.empty() ? CV_64F : D.depth());
if (rvecs.isMatVector())
{
int N = (int)objectPoints.total();
Expand All @@ -832,8 +832,8 @@ double cv::fisheye::calibrate(InputArrayOfArrays objectPoints, InputArrayOfArray
}
else
{
if (rvecs.needed()) cv::Mat(omc).convertTo(rvecs, rvecs.empty() ? CV_64FC3 : rvecs.type());
if (tvecs.needed()) cv::Mat(Tc).convertTo(tvecs, tvecs.empty() ? CV_64FC3 : tvecs.type());
if (rvecs.needed()) cv::Mat(omc).convertTo(rvecs, rvecs.empty() ? CV_64F : rvecs.depth());
if (tvecs.needed()) cv::Mat(Tc).convertTo(tvecs, tvecs.empty() ? CV_64F : tvecs.depth());
}

return rms;
Expand Down Expand Up @@ -880,10 +880,10 @@ double cv::fisheye::stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayO

Matx33d _K1, _K2;
Vec4d _D1, _D2;
if (!K1.empty()) K1.getMat().convertTo(_K1, CV_64FC1);
if (!D1.empty()) D1.getMat().convertTo(_D1, CV_64FC1);
if (!K2.empty()) K2.getMat().convertTo(_K2, CV_64FC1);
if (!D2.empty()) D2.getMat().convertTo(_D2, CV_64FC1);
if (!K1.empty()) K1.getMat().convertTo(_K1, CV_64F);
if (!D1.empty()) D1.getMat().convertTo(_D1, CV_64F);
if (!K2.empty()) K2.getMat().convertTo(_K2, CV_64F);
if (!D2.empty()) D2.getMat().convertTo(_D2, CV_64F);

std::vector<Vec3d> rvecs1(n_images), tvecs1(n_images), rvecs2(n_images), tvecs2(n_images);

Expand Down Expand Up @@ -1070,12 +1070,12 @@ double cv::fisheye::stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayO
Mat _R;
Rodrigues(omcur, _R);

if (K1.needed()) cv::Mat(_K1).convertTo(K1, K1.empty() ? CV_64FC1 : K1.type());
if (K2.needed()) cv::Mat(_K2).convertTo(K2, K2.empty() ? CV_64FC1 : K2.type());
if (D1.needed()) cv::Mat(intrinsicLeft.k).convertTo(D1, D1.empty() ? CV_64FC1 : D1.type());
if (D2.needed()) cv::Mat(intrinsicRight.k).convertTo(D2, D2.empty() ? CV_64FC1 : D2.type());
if (R.needed()) _R.convertTo(R, R.empty() ? CV_64FC1 : R.type());
if (T.needed()) cv::Mat(Tcur).convertTo(T, T.empty() ? CV_64FC1 : T.type());
if (K1.needed()) cv::Mat(_K1).convertTo(K1, K1.empty() ? CV_64F : K1.depth());
if (K2.needed()) cv::Mat(_K2).convertTo(K2, K2.empty() ? CV_64F : K2.depth());
if (D1.needed()) cv::Mat(intrinsicLeft.k).convertTo(D1, D1.empty() ? CV_64F : D1.depth());
if (D2.needed()) cv::Mat(intrinsicRight.k).convertTo(D2, D2.empty() ? CV_64F : D2.depth());
if (R.needed()) _R.convertTo(R, R.empty() ? CV_64F : R.depth());
if (T.needed()) cv::Mat(Tcur).convertTo(T, T.empty() ? CV_64F : T.depth());

return rms;
}
Expand Down Expand Up @@ -1404,8 +1404,8 @@ void cv::internal::CalibrateExtrinsics(InputArrayOfArrays objectPoints, InputArr
Mat omckk, Tckk, JJ_kk;
Mat image, object;

objectPoints.getMat(image_idx).convertTo(object, CV_64FC3);
imagePoints.getMat (image_idx).convertTo(image, CV_64FC2);
objectPoints.getMat(image_idx).convertTo(object, CV_64F);
imagePoints.getMat (image_idx).convertTo(image, CV_64F);

bool imT = image.rows < image.cols;
bool obT = object.rows < object.cols;
Expand Down Expand Up @@ -1442,8 +1442,8 @@ void cv::internal::ComputeJacobians(InputArrayOfArrays objectPoints, InputArrayO
for (int image_idx = 0; image_idx < n; ++image_idx)
{
Mat image, object;
objectPoints.getMat(image_idx).convertTo(object, CV_64FC3);
imagePoints.getMat (image_idx).convertTo(image, CV_64FC2);
objectPoints.getMat(image_idx).convertTo(object, CV_64F);
imagePoints.getMat (image_idx).convertTo(image, CV_64F);

bool imT = image.rows < image.cols;
Mat om(omc.getMat().col(image_idx)), T(Tc.getMat().col(image_idx));
Expand Down Expand Up @@ -1507,8 +1507,8 @@ void cv::internal::EstimateUncertainties(InputArrayOfArrays objectPoints, InputA
for (int image_idx = 0; image_idx < (int)objectPoints.total(); ++image_idx)
{
Mat image, object;
objectPoints.getMat(image_idx).convertTo(object, CV_64FC3);
imagePoints.getMat (image_idx).convertTo(image, CV_64FC2);
objectPoints.getMat(image_idx).convertTo(object, CV_64F);
imagePoints.getMat (image_idx).convertTo(image, CV_64F);

bool imT = image.rows < image.cols;

Expand Down
2 changes: 1 addition & 1 deletion modules/calib3d/src/five-point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ void cv::decomposeEssentialMat( InputArray _E, OutputArray _R1, OutputArray _R2,
if (determinant(Vt) < 0) Vt *= -1.;

Mat W = (Mat_<double>(3, 3) << 0, 1, 0, -1, 0, 0, 0, 0, 1);
W.convertTo(W, E.type());
W.convertTo(W, E.depth());

Mat R1, R2, t;
R1 = U * W * Vt;
Expand Down
4 changes: 2 additions & 2 deletions modules/calib3d/src/fundam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class HomographyEstimatorCallback CV_FINAL : public PointSetRegistrator::Callbac
eigen( _LtL, matW, matV );
_Htemp = _invHnorm*_H0;
_H0 = _Htemp*_Hnorm2;
_H0.convertTo(_model, _H0.type(), 1./_H0.at<double>(2,2) );
_H0.convertTo(_model, _H0.depth(), 1./_H0.at<double>(2,2) );

return 1;
}
Expand Down Expand Up @@ -334,7 +334,7 @@ static bool createAndRunRHORegistrator(double confidence,
(float*)tmpH.data);

/* Convert float homography to double precision. */
tmpH.convertTo(_H, CV_64FC1);
tmpH.convertTo(_H, CV_64F);

/* Maps non-zero mask elements to 1, for the sake of the test case. */
for(int k=0;k<npoints;k++){
Expand Down
2 changes: 1 addition & 1 deletion modules/calib3d/src/levmarq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class LMSolverImpl CV_FINAL : public LMSolver
if( param0.size != x.size )
transpose(x, x);

x.convertTo(param0, ptype);
x.convertTo(param0, CV_MAT_DEPTH(ptype));
if( iter == maxIters )
iter = -iter;

Expand Down
8 changes: 4 additions & 4 deletions modules/calib3d/src/ptsetreg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,9 @@ Mat estimateAffine2D(InputArray _from, InputArray _to, OutputArray _inliers,
if (from.type() != CV_32FC2 || to.type() != CV_32FC2)
{
Mat tmp1, tmp2;
from.convertTo(tmp1, CV_32FC2);
from.convertTo(tmp1, CV_32F);
from = tmp1;
to.convertTo(tmp2, CV_32FC2);
to.convertTo(tmp2, CV_32F);
to = tmp2;
}
// convert to N x 1 vectors
Expand Down Expand Up @@ -895,9 +895,9 @@ Mat estimateAffinePartial2D(InputArray _from, InputArray _to, OutputArray _inlie
if (from.type() != CV_32FC2 || to.type() != CV_32FC2)
{
Mat tmp1, tmp2;
from.convertTo(tmp1, CV_32FC2);
from.convertTo(tmp1, CV_32F);
from = tmp1;
to.convertTo(tmp2, CV_32FC2);
to.convertTo(tmp2, CV_32F);
to = tmp2;
}
// convert to N x 1 vectors
Expand Down
6 changes: 3 additions & 3 deletions modules/calib3d/src/stereobm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,8 @@ class StereoBMImpl CV_FINAL : public StereoBM

if( params.speckleRange >= 0 && params.speckleWindowSize > 0 )
filterSpeckles(disparr.getMat(), FILTERED, params.speckleWindowSize, params.speckleRange, slidingSumBuf);
if (dtype == CV_32F)
disparr.getUMat().convertTo(disparr, CV_32FC1, 1./(1 << disp_shift), 0);
if (dtype == CV_32FC1)
disparr.getUMat().convertTo(disparr, CV_32F, 1./(1 << disp_shift), 0);
CV_IMPL_ADD(CV_IMPL_OCL);
return;
}
Expand Down Expand Up @@ -1240,7 +1240,7 @@ class StereoBMImpl CV_FINAL : public StereoBM
filterSpeckles(disp, FILTERED, params.speckleWindowSize, params.speckleRange, slidingSumBuf);

if (disp0.data != disp.data)
disp.convertTo(disp0, disp0.type(), 1./(1 << disp_shift), 0);
disp.convertTo(disp0, disp0.depth(), 1./(1 << disp_shift), 0);
}

int getMinDisparity() const CV_OVERRIDE { return params.minDisparity; }
Expand Down
4 changes: 2 additions & 2 deletions modules/calib3d/test/test_cameracalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ void CV_CameraCalibrationTest_CPP::project( int pointCount, CvPoint3D64f* _objec
vector<Point2f> imagePoints;
cvtest::Rodrigues( rmat, rvec );

objectPoints.convertTo( objectPoints, CV_32FC1 );
objectPoints.convertTo( objectPoints, CV_32F );
projectPoints( objectPoints, rvec, tvec,
cameraMatrix, distCoeffs, imagePoints );
vector<Point2f>::const_iterator it = imagePoints.begin();
Expand Down Expand Up @@ -1774,7 +1774,7 @@ void CV_StereoCalibrationTest::run( int )
newHomogeneousPoints1 = newHomogeneousPoints1.reshape(1);
newHomogeneousPoints2 = newHomogeneousPoints2.reshape(1);
Mat typedF;
F.convertTo(typedF, newHomogeneousPoints1.type());
F.convertTo(typedF, newHomogeneousPoints1.depth());
for (int i = 0; i < newHomogeneousPoints1.rows; ++i)
{
Mat error = newHomogeneousPoints2.row(i) * typedF * newHomogeneousPoints1.row(i).t();
Expand Down
16 changes: 8 additions & 8 deletions modules/calib3d/test/test_fundam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,19 +696,19 @@ void CV_RodriguesTest::run_func()
{
if( J1.size() != J1_0.size() )
J1 = J1.t();
J1.convertTo(J1_0, J1_0.type());
J1.convertTo(J1_0, J1_0.depth());
}
if( J2.data != J2_0.data )
{
if( J2.size() != J2_0.size() )
J2 = J2.t();
J2.convertTo(J2_0, J2_0.type());
J2.convertTo(J2_0, J2_0.depth());
}
}
if( M.data != M0.data )
M.reshape(M0.channels(), M0.rows).convertTo(M0, M0.type());
M.reshape(M0.channels(), M0.rows).convertTo(M0, M0.depth());
if( v2.data != v2_0.data )
v2.reshape(v2_0.channels(), v2_0.rows).convertTo(v2_0, v2_0.type());
v2.reshape(v2_0.channels(), v2_0.rows).convertTo(v2_0, v2_0.depth());
}
}

Expand Down Expand Up @@ -938,7 +938,7 @@ void CV_FundamentalMatTest::fill_array( int test_case_idx, int i, int j, Mat& ar
t[3] = cvtest::randReal(rng)*cube_size;
t[7] = cvtest::randReal(rng)*cube_size;
t[11] = cvtest::randReal(rng)*cube_size;
Mat( 3, 4, CV_64F, t ).convertTo(arr, arr.type());
Mat(3, 4, CV_64FC1, t).convertTo(arr, arr.depth());
}
break;
case 4:
Expand All @@ -947,7 +947,7 @@ void CV_FundamentalMatTest::fill_array( int test_case_idx, int i, int j, Mat& ar
t[2] = (img_size*0.5 + cvtest::randReal(rng)*4. - 2.)*t[0];
t[5] = (img_size*0.5 + cvtest::randReal(rng)*4. - 2.)*t[4];
t[8] = 1.;
Mat( 3, 3, CV_64F, t ).convertTo( arr, arr.type() );
Mat(3, 3, CV_64FC1, t).convertTo(arr, arr.depth());
break;
}
}
Expand Down Expand Up @@ -1240,15 +1240,15 @@ void CV_EssentialMatTest::fill_array( int test_case_idx, int i, int j, Mat& arr
t[3] = cvtest::randReal(rng)*cube_size;
t[7] = cvtest::randReal(rng)*cube_size;
t[11] = cvtest::randReal(rng)*cube_size;
Mat( 3, 4, CV_64F, t ).convertTo(arr, arr.type());
Mat(3, 4, CV_64FC1, t).convertTo(arr, arr.depth());
}
break;
case 4:
t[0] = t[4] = cvtest::randReal(rng)*(max_f - min_f) + min_f;
t[2] = (img_size*0.5 + cvtest::randReal(rng)*4. - 2.)*t[0];
t[5] = (img_size*0.5 + cvtest::randReal(rng)*4. - 2.)*t[4];
t[8] = 1.;
Mat( 3, 3, CV_64F, t ).convertTo( arr, arr.type() );
Mat(3, 3, CV_64FC1, t).convertTo(arr, arr.depth());
break;
}
}
Expand Down
Loading

0 comments on commit 548acff

Please sign in to comment.