diff --git a/modules/cudaimgproc/test/test_histogram.cpp b/modules/cudaimgproc/test/test_histogram.cpp index 0be400ab6..7c19cfd9c 100644 --- a/modules/cudaimgproc/test/test_histogram.cpp +++ b/modules/cudaimgproc/test/test_histogram.cpp @@ -107,7 +107,6 @@ CUDA_TEST_P(HistEven, Accuracy) Mat srcRoi = src(roi); cv::calcHist(&srcRoi, 1, channels, cv::Mat(), hist_gold, 1, histSize, ranges); - hist_gold = hist_gold.t(); hist_gold.convertTo(hist_gold, CV_32S); EXPECT_MAT_NEAR(hist_gold, hist, 0.0); diff --git a/modules/cudev/test/test_nd.cu b/modules/cudev/test/test_nd.cu index 2fc3f396b..fc41f4b1e 100644 --- a/modules/cudev/test/test_nd.cu +++ b/modules/cudev/test/test_nd.cu @@ -41,12 +41,6 @@ public: else ret.push_back(Range::all()); - if (dims == 1) - { - // Mat expects two ranges even in this case - ret.push_back(Range::all()); - } - return ret; } diff --git a/modules/face/src/facemarkAAM.cpp b/modules/face/src/facemarkAAM.cpp index 5e1370e3f..e9d845a89 100644 --- a/modules/face/src/facemarkAAM.cpp +++ b/modules/face/src/facemarkAAM.cpp @@ -243,7 +243,7 @@ void FacemarkAAMImpl::training(void* parameters){ /* get PCA Projection vectors */ Mat S; - getProjection(M.t(),S,param_max_n); + getProjection(M.t(), S, param_max_n); /* Create similarity eig*/ Mat shape_S,shape_Q; calcSimilarityEig(AAM.s0,S,AAM.Q,AAM.S); @@ -259,7 +259,7 @@ void FacemarkAAMImpl::training(void* parameters){ /*get the min and max of x and y coordinate*/ double min_x, max_x, min_y, max_y; - s0_scaled_m = s0_scaled_m.reshape(1); + s0_scaled_m = s0_scaled_m.reshape(1, (int)s0_scaled_m.total()); Mat s0_scaled_x = s0_scaled_m.col(0); Mat s0_scaled_y = s0_scaled_m.col(1); minMaxIdx(s0_scaled_x, &min_x, &max_x); @@ -287,7 +287,7 @@ void FacemarkAAMImpl::training(void* parameters){ if(params.verbose) printf("extract features from image #%i/%i\n", (int)(i+1), (int)images.size()); warped = warpImage(images[i],base_shape, facePoints[i], AAM.triangles, AAM.textures[scale].resolution,AAM.textures[scale].textureIdx); feat = getFeature(warped, AAM.textures[scale].ind1); - texture_feats.push_back(feat.t()); + texture_feats.push_back(feat.reshape(feat.channels(), 1)); } Mat T= texture_feats.t(); @@ -307,7 +307,7 @@ void FacemarkAAMImpl::training(void* parameters){ for(int i =0;i(c,fe_map); - U_data.push_back(ud.t()); + U_data.push_back(ud.reshape(ud.channels(), 1)); } Mat U = U_data.t(); AAM.textures[scale].AA = orthonormal(U); @@ -413,7 +413,7 @@ bool FacemarkAAMImpl::fitImpl( const Mat image, std::vector& landmarks, Mat Wx_dp, Wy_dp; createWarpJacobian(S, AAM.Q, AAM.triangles, AAM.textures[scl],Wx_dp, Wy_dp, Tp); - std::vector s0_init = Mat(Mat(R*scale*AAM.scales[scl]*Mat(Mat(s0).reshape(1)).t()).t()).reshape(2); + std::vector s0_init = Mat(Mat(R*scale*AAM.scales[scl]*Mat(Mat(s0).reshape(1, (int)s0.size())).t()).t()).reshape(2); std::vector curr_shape = Mat(Mat(s0_init)+Scalar(T.x,T.y)); curr_shape = Mat(1.0/scale*Mat(curr_shape)).reshape(2); @@ -444,8 +444,8 @@ bool FacemarkAAMImpl::fitImpl( const Mat image, std::vector& landmarks, AAM.textures[scl].resolution , AAM.textures[scl].textureIdx); - I = getFeature(warped, AAM.textures[scl].ind1); - II = getFeature(warped, AAM.textures[scl].ind2); + I = getFeature(warped, AAM.textures[scl].ind1).t(); + II = getFeature(warped, AAM.textures[scl].ind2).t(); if(t==0){ c = A.t()*(I-AAM.textures[scl].A0); //little bit different to matlab, probably due to datatype @@ -480,8 +480,8 @@ bool FacemarkAAMImpl::fitImpl( const Mat image, std::vector& landmarks, invert(Hfsic, iHfsic); /*compute dp dq and dc*/ - Mat dqp = iHfsic*Jfsic.t()*(II-AAM.textures[scl].AA0); - dc = AA.t()*(II-Mat(Irec_vec)-J*dqp); + Mat dqp = iHfsic*Jfsic.t()*(II-AAM.textures[scl].AA0.t()); + dc = AA.t()*(II-Mat(Irec_vec).t()-J*dqp); warpUpdate(curr_shape, dqp, s0,S, AAM.Q, AAM.triangles,Tp); } landmarks = Mat(scale*Mat(curr_shape)).reshape(2); @@ -602,16 +602,17 @@ Mat FacemarkAAMImpl::procrustes(std::vector P, std::vector Q, reduce(Ys,sumYs, 0, REDUCE_SUM); //calculate the normrnd - double normX = sqrt(Mat(sumXs.reshape(1)).at(0)+Mat(sumXs.reshape(1)).at(1)); - double normY = sqrt(Mat(sumYs.reshape(1)).at(0)+Mat(sumYs.reshape(1)).at(1)); + Point2f sumXs0 = sumXs.at(0), sumYs0 = sumYs.at(0); + double normX = sqrt(sumXs0.x + sumXs0.y); + double normY = sqrt(sumYs0.x + sumYs0.y); //normalization X0 = X0/normX; Y0 = Y0/normY; //reshape, convert to 2D Matrix - Mat Xn=X0.reshape(1); - Mat Yn=Y0.reshape(1); + Mat Xn=X0.reshape(1, (int)X0.total()); + Mat Yn=Y0.reshape(1, (int)Y0.total()); //calculate the covariance matrix Mat M = Xn.t()*Yn; @@ -634,7 +635,7 @@ Mat FacemarkAAMImpl::procrustes(std::vector P, std::vector Q, trans[1] = t.at(1); // calculate the recovered form - Mat Qmat = Mat(Q).reshape(1); + Mat Qmat = Mat(Q).reshape(1, (int)Q.size()); return Mat(scale*Qmat*rot+trans).clone(); } @@ -777,7 +778,7 @@ Mat FacemarkAAMImpl::orthonormal(Mat Mo){ return O.colRange(0,k).clone(); } -void FacemarkAAMImpl::calcSimilarityEig(std::vector s0,Mat S, Mat & Q_orth, Mat & S_orth){ +void FacemarkAAMImpl::calcSimilarityEig(std::vector s0, Mat S, Mat & Q_orth, Mat & S_orth){ int npts = (int)s0.size(); Mat Q = Mat::zeros(2*npts,4,CV_32FC1); @@ -792,7 +793,7 @@ void FacemarkAAMImpl::calcSimilarityEig(std::vector s0,Mat S, Mat & Q_o w.copyTo(c0); /*c1 = [-s0(npts:2*npts); s0(0:npts-1)]*/ - Mat s0_mat = Mat(s0).reshape(1); + Mat s0_mat = Mat(s0).reshape(1, (int)s0.size()); // s0_mat.convertTo(s0_mat, CV_64FC1); Mat swapper = Mat::zeros(2,npts,CV_32FC1); Mat s00 = s0_mat.col(0); @@ -826,11 +827,15 @@ void FacemarkAAMImpl::calcSimilarityEig(std::vector s0,Mat S, Mat & Q_o Mat allOrth = orthonormal(all.t()); Q_orth = allOrth.colRange(0,4).clone(); S_orth = allOrth.colRange(4,allOrth.cols).clone(); - } inline Mat FacemarkAAMImpl::linearize(Mat s){ // all x values and then all y values - return Mat(s.reshape(1).t()).reshape(1,2*s.rows); + int npoints = s.rows; + if (s.channels() > 1) { + npoints = (int)s.total(); + s = s.reshape(1, npoints); + } + return Mat(s.t()).reshape(1, 2*npoints); } inline Mat FacemarkAAMImpl::linearize(std::vector s){ // all x values and then all y values return linearize(Mat(s)); @@ -843,7 +848,7 @@ void FacemarkAAMImpl::delaunay(std::vector s, std::vector & tria std::vector tp; double min_x, max_x, min_y, max_y; - Mat S = Mat(s).reshape(1); + Mat S = Mat(s).reshape(1, (int)s.size()); Mat s_x = S.col(0); Mat s_y = S.col(1); minMaxIdx(s_x, &min_x, &max_x); @@ -954,8 +959,8 @@ Mat FacemarkAAMImpl::warpImage( source[1] = curr_shape[triangles[i][1]]; source[2] = curr_shape[triangles[i][2]]; - Mat target_mtx = Mat(target).reshape(1)-1.0; - Mat source_mtx = Mat(source).reshape(1)-1.0; + Mat target_mtx = Mat(target).reshape(1,(int)target.size())-1.0; + Mat source_mtx = Mat(source).reshape(1,(int)source.size())-1.0; Mat U = target_mtx.col(0); Mat V = target_mtx.col(1); Mat X = source_mtx.col(0); @@ -979,7 +984,7 @@ Mat FacemarkAAMImpl::warpImage( R=A.colRange(0,2); t=A.colRange(2,3); - Mat pts_ori = Mat(textureIdx[i]).reshape(1); + Mat pts_ori = Mat(textureIdx[i]).reshape(1, (int)textureIdx[i].size()); Mat pts = pts_ori.t(); //matlab Mat bx = pts_ori.col(0); Mat by = pts_ori.col(1); @@ -1081,8 +1086,9 @@ void FacemarkAAMImpl::warpUpdate(std::vector & shape, Mat delta, std::v Mat(ds0, Range((int)s0.size(),(int)s0.size()*2)).copyTo(c1); Mat s_new = computeWarpParts(shape,s0,ds0_mat, triangles, Tp); + s_new -= Mat(s0).reshape(1, (int)s0.size()); - Mat diff =linearize(Mat(s_new - Mat(s0).reshape(1))); + Mat diff = linearize(s_new); Mat r = Q.t()*diff; Mat p = S.t()*diff; @@ -1118,8 +1124,9 @@ Mat FacemarkAAMImpl::computeWarpParts(std::vector curr_shape,std::vecto source[2] = curr_shape[triangles[idx][2]]; A = getAffineTransform(target,source); + Mat p_m = Mat(p).reshape(1, (int)p.size()); - Mat(A*Mat(p)).reshape(2).copyTo(v); + Mat(A*p_m).reshape(2).copyTo(v); vx.push_back(v[0].x); vy.push_back(v[0].y); }// j @@ -1134,7 +1141,7 @@ Mat FacemarkAAMImpl::computeWarpParts(std::vector curr_shape,std::vecto new_shape.push_back(Point2f(mx,my)); } // s0.size() - return Mat(new_shape).reshape(1).clone(); + return Mat(new_shape).reshape(1, (int)new_shape.size()).clone(); } void FacemarkAAMImpl::gradient(const Mat M, Mat & gx, Mat & gy){ diff --git a/modules/face/src/facemarkLBF.cpp b/modules/face/src/facemarkLBF.cpp index df58c6319..1ca1eeb54 100644 --- a/modules/face/src/facemarkLBF.cpp +++ b/modules/face/src/facemarkLBF.cpp @@ -536,7 +536,7 @@ void FacemarkLBFImpl::prepareTrainingData(Mat img, std::vector facePoin std::vector & cropped, std::vector & shapes, std::vector &boxes) { Mat shape; - Mat _shape = Mat(facePoints).reshape(1); + Mat _shape = Mat(facePoints).reshape(1, (int)facePoints.size()); Rect box = getBBox(img, _shape); if(img.channels()>1){ @@ -1359,7 +1359,7 @@ Mat FacemarkLBFImpl::Regressor::supportVectorRegression( if(verbose) printf("Objective value = %lf\n", v); if(verbose) printf("nSV = %d\n",nSV); - return Mat(Mat(w).t()).clone(); + return Mat(w).reshape(2, 1).clone(); }//end diff --git a/modules/face/test/test_facemark_aam.cpp b/modules/face/test/test_facemark_aam.cpp index 5f4c520c6..14d8c0c35 100644 --- a/modules/face/test/test_facemark_aam.cpp +++ b/modules/face/test/test_facemark_aam.cpp @@ -108,7 +108,7 @@ TEST(CV_Face_FacemarkAAM, test_workflow) { Mat image; std::vector landmarks; - for(size_t i=0;i applyK(const Mat_& I, float k, float a=-0.3293f, float float gamma = std::pow(k, a); Mat_ J(I.size()); - pow(I, gamma, J); - J = J*beta; - + CV_Assert(I.isContinuous()); + size_t i, npix = I.total(); + const float* Iptr = I.ptr(); + float* Jptr = J.ptr(); + for (i = 0; i < npix; i++) { + Jptr[i] = pow(Iptr[i], gamma)*beta; + } return J; } @@ -293,15 +297,18 @@ static float entropy(const Mat_& I) float range[] = { 0, 256 }; const float* histRange = { range }; calcHist(&I_uchar, 1, NULL, Mat(), hist, 1, &histSize, &histRange); + double histsum = cv::sum(hist)[0]; - Mat_ hist_norm = hist / cv::sum(hist)[0]; + Mat_ hist_norm = hist / histsum; + int i, nbins = (int)hist_norm.total(); float E = 0; - for (int i = 0; i < hist_norm.rows; i++) + for (i = 0; i < nbins; i++) { - if (hist_norm(i,0) > 0) + float v = hist_norm(i); + if (v > 0) { - E += hist_norm(i,0) * std::log2(hist_norm(i,0)); + E += v * std::log2(v); } } @@ -487,7 +494,7 @@ static void BIMEF_impl(InputArray input_, OutputArray output_, float mu, float * // t: scene illumination map Mat_ t_b(imgDouble.size()); t_b.forEach( - [&](float &pixel, const int * position) -> void + [&](float &pixel, const int* position) -> void { pixel = std::max(std::max(imgDouble(position[0], position[1])[0], imgDouble(position[0], position[1])[1]), diff --git a/modules/mcc/src/colorspace.cpp b/modules/mcc/src/colorspace.cpp index 9dfe3f6e1..40fa5364b 100644 --- a/modules/mcc/src/colorspace.cpp +++ b/modules/mcc/src/colorspace.cpp @@ -120,13 +120,14 @@ void RGBBase_::calM() XYZg = Mat(xyY2XYZ({ xg, yg }), true); XYZb = Mat(xyY2XYZ({ xb, yb }), true); merge(std::vector { XYZr, XYZg, XYZb }, XYZ_rgbl); - XYZ_rgbl = XYZ_rgbl.reshape(1, XYZ_rgbl.rows); + XYZ_rgbl = XYZ_rgbl.reshape(1, (int)XYZ_rgbl.total()); Mat XYZw = Mat(getIlluminants(io), true); + XYZw = XYZw.reshape(1, (int)XYZw.total()); solve(XYZ_rgbl, XYZw, Srgb); merge(std::vector { Srgb.at(0) * XYZr, Srgb.at(1) * XYZg, Srgb.at(2) * XYZb }, M_to); - M_to = M_to.reshape(1, M_to.rows); + M_to = M_to.reshape(1, (int)M_to.total()); M_from = M_to.inv(); }; @@ -382,6 +383,8 @@ Mat XYZ::cam_(IO sio, IO dio, CAM method) const // Function from http://www.brucelindbloom.com/index.html?ColorCheckerRGB.html. Mat XYZws = Mat(getIlluminants(dio)); Mat XYZWd = Mat(getIlluminants(sio)); + XYZws = XYZws.reshape(1, (int)XYZws.total()); + XYZWd = XYZWd.reshape(1, (int)XYZWd.total()); Mat MA = MAs.at(method)[0]; Mat MA_inv = MAs.at(method)[1]; Mat M = MA_inv * Mat::diag((MA * XYZws) / (MA * XYZWd)) * MA; diff --git a/modules/rapid/src/rapid.cpp b/modules/rapid/src/rapid.cpp index 9a4cb5017..4a2fe8b7c 100644 --- a/modules/rapid/src/rapid.cpp +++ b/modules/rapid/src/rapid.cpp @@ -174,7 +174,7 @@ void extractLineBundle(int len, InputArray ctl2d, InputArray img, OutputArray bu CV_Assert(ctl2d.getMat().checkVector(2, CV_32F) > 0); Mat_ contour = ctl2d.getMat(); - const int N = contour.rows; + const int N = (int)contour.total(); const int W = len * 2 + 1; srcLocations.create(N, W, CV_16SC2); @@ -305,8 +305,8 @@ void convertCorrespondencies(InputArray _cols, InputArray _srcLocations, OutputA Mat opts3d; if(!_pts3d.empty()) { - CV_Assert(_cols.rows() == _pts3d.rows()); - pts3d = _pts3d.getMat(); + pts3d = _pts3d.getMat().t(); + CV_Assert(cols.rows == pts3d.rows); opts3d.create(0, 1, pts3d.type()); opts3d.reserve(cols.rows); } diff --git a/modules/wechat_qrcode/test/test_qrcode.cpp b/modules/wechat_qrcode/test/test_qrcode.cpp index ec2559b0e..5b11ea98d 100644 --- a/modules/wechat_qrcode/test/test_qrcode.cpp +++ b/modules/wechat_qrcode/test/test_qrcode.cpp @@ -321,7 +321,7 @@ TEST(Objdetect_QRCode_points_position, rotate45) { auto decoded_info1 = detector.detectAndDecode(image, points1); ASSERT_EQ(1ull, decoded_info1.size()); ASSERT_EQ(expect_msg, decoded_info1[0]); - EXPECT_NEAR(0, cvtest::norm(Mat(goldCorners), points1[0].reshape(1, 8), NORM_INF), 8.); + EXPECT_NEAR(0, cvtest::norm(Mat(goldCorners).reshape(1, (int)goldCorners.size()), points1[0].reshape(1, 8), NORM_INF), 8.); const double angle = 45; Point2f pc(image.cols/2.f, image.rows/2.f); @@ -338,7 +338,7 @@ TEST(Objdetect_QRCode_points_position, rotate45) { auto decoded_info2 = detector.detectAndDecode(image, points2); ASSERT_EQ(1ull, decoded_info2.size()); ASSERT_EQ(expect_msg, decoded_info2[0]); - EXPECT_NEAR(0, cvtest::norm(Mat(rotateGoldCorners), points2[0].reshape(1, 8), NORM_INF), 11.); + EXPECT_NEAR(0, cvtest::norm(Mat(rotateGoldCorners).reshape(1, (int)rotateGoldCorners.size()), points2[0].reshape(1, 8), NORM_INF), 11.); } INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode, testing::ValuesIn(qrcode_images_name)); diff --git a/modules/xphoto/test/test_oil_painting.cpp b/modules/xphoto/test/test_oil_painting.cpp index e7ef2fc16..589e85f3f 100644 --- a/modules/xphoto/test/test_oil_painting.cpp +++ b/modules/xphoto/test/test_oil_painting.cpp @@ -41,7 +41,7 @@ Mat testOilPainting(Mat imgSrc, int halfSize, int dynRatio, int colorSpace) double maxVal = 0; Point pMin, pMax; minMaxLoc(hist, 0, &maxVal, &pMin, &pMax); - mask.setTo(0, lum != static_cast(pMax.y)); + mask.setTo(0, lum != static_cast(pMax.x)); Scalar v = mean(imgSrc, mask); *vDst = Vec3b(static_cast(v[0]), static_cast(v[1]), static_cast(v[2])); } @@ -65,7 +65,7 @@ Mat testOilPainting(Mat imgSrc, int halfSize, int dynRatio, int colorSpace) double maxVal = 0; Point pMin, pMax; minMaxLoc(hist, 0, &maxVal, &pMin, &pMax); - mask.setTo(0, lum != static_cast(pMax.y)); + mask.setTo(0, lum != static_cast(pMax.x)); Scalar v = mean(imgSrc, mask); *vDst = static_cast(v[0]); } @@ -90,7 +90,8 @@ TEST(xphoto_oil_painting, regression) double maxVal; Point pIdx; minMaxLoc(p, NULL, &maxVal, NULL, &pIdx); - ASSERT_LE(p.at(pIdx), 2); + int v = p.at(pIdx); + ASSERT_LE(v, 2); } Mat orig2 = imread(folder + "exp1.png",IMREAD_GRAYSCALE); ASSERT_TRUE(!orig2.empty());