From 3000519bea4b00787696441bb44ae3df37952d3f Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 2 May 2024 20:28:46 +0300 Subject: [PATCH 1/5] Fixed Wredundant-move produced by GCC 13.2 (Ubuntu 24.04). --- modules/face/src/facemarkLBF.cpp | 8 ++++---- modules/face/src/mace.cpp | 2 +- modules/rgbd/perf/perf_tsdf.cpp | 2 +- modules/rgbd/test/ocl/test_tsdf.cpp | 2 +- modules/rgbd/test/test_colored_kinfu.cpp | 8 ++++---- modules/rgbd/test/test_kinfu.cpp | 4 ++-- modules/rgbd/test/test_tsdf.cpp | 2 +- modules/videostab/src/global_motion.cpp | 16 ++++++++-------- .../test/test_sparse_match_interpolator.cpp | 8 ++++---- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/modules/face/src/facemarkLBF.cpp b/modules/face/src/facemarkLBF.cpp index df58c6319b7..ce66a419463 100644 --- a/modules/face/src/facemarkLBF.cpp +++ b/modules/face/src/facemarkLBF.cpp @@ -667,7 +667,7 @@ Mat FacemarkLBFImpl::BBox::project(const Mat &shape) const { res(i, 0) = (shape_(i, 0) - x_center) / x_scale; res(i, 1) = (shape_(i, 1) - y_center) / y_scale; } - return std::move(res); + return res; } // Project relative shape to absolute shape binding to this bbox @@ -678,7 +678,7 @@ Mat FacemarkLBFImpl::BBox::reproject(const Mat &shape) const { res(i, 0) = shape_(i, 0)*x_scale + x_center; res(i, 1) = shape_(i, 1)*y_scale + y_center; } - return std::move(res); + return res; } Mat FacemarkLBFImpl::getMeanShape(std::vector >_shapes, std::vector &bboxes) { @@ -1039,7 +1039,7 @@ Mat FacemarkLBFImpl::RandomForest::generateLBF(Mat &img, Mat ¤t_shape, BBo lbf_feat(i*trees_n + j) = (i*trees_n + j)*base + code; } } - return std::move(lbf_feat); + return lbf_feat; } void FacemarkLBFImpl::RandomForest::write(FileStorage fs, int k) { @@ -1381,7 +1381,7 @@ Mat FacemarkLBFImpl::Regressor::globalRegressionPredict(const Mat &lbf, int stag for (int j = 0; j < lbf.cols; j++) y += w_ptr[lbf_ptr[j]]; delta_shape(i, 1) = y; } - return std::move(delta_shape); + return delta_shape; } // Regressor::globalRegressionPredict Mat FacemarkLBFImpl::Regressor::predict(Mat &img, BBox &bbox) { diff --git a/modules/face/src/mace.cpp b/modules/face/src/mace.cpp index 2c09560bfe5..71762fe4128 100644 --- a/modules/face/src/mace.cpp +++ b/modules/face/src/mace.cpp @@ -106,7 +106,7 @@ struct MACEImpl CV_FINAL : MACE { complexInput.copyTo(dftImg(Rect(0,0,IMGSIZE,IMGSIZE))); dft(dftImg, dftImg); - return std::move(dftImg); + return dftImg; } diff --git a/modules/rgbd/perf/perf_tsdf.cpp b/modules/rgbd/perf/perf_tsdf.cpp index da928f98f22..efce51b53e3 100644 --- a/modules/rgbd/perf/perf_tsdf.cpp +++ b/modules/rgbd/perf/perf_tsdf.cpp @@ -139,7 +139,7 @@ struct SemisphereScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor, onlySemisphere)); - return std::move(frame); + return frame; } std::vector getPoses() override diff --git a/modules/rgbd/test/ocl/test_tsdf.cpp b/modules/rgbd/test/ocl/test_tsdf.cpp index 1c55e1f4001..bedce1a562e 100644 --- a/modules/rgbd/test/ocl/test_tsdf.cpp +++ b/modules/rgbd/test/ocl/test_tsdf.cpp @@ -143,7 +143,7 @@ struct SemisphereScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor, onlySemisphere)); - return std::move(frame); + return frame; } std::vector getPoses() override diff --git a/modules/rgbd/test/test_colored_kinfu.cpp b/modules/rgbd/test/test_colored_kinfu.cpp index 4303b260e3e..e92c56d8b7e 100644 --- a/modules/rgbd/test/test_colored_kinfu.cpp +++ b/modules/rgbd/test/test_colored_kinfu.cpp @@ -206,7 +206,7 @@ struct CubeSpheresScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor)); - return std::move(frame); + return frame; } Mat rgb(Affine3f pose) override @@ -217,7 +217,7 @@ struct CubeSpheresScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderColorInvoker(frame, pose, reproj, depthFactor)); - return std::move(frame); + return frame; } std::vector getPoses() override @@ -313,7 +313,7 @@ struct RotatingScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor)); - return std::move(frame); + return frame; } Mat rgb(Affine3f pose) override @@ -324,7 +324,7 @@ struct RotatingScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderColorInvoker(frame, pose, reproj, depthFactor)); - return std::move(frame); + return frame; } std::vector getPoses() override diff --git a/modules/rgbd/test/test_kinfu.cpp b/modules/rgbd/test/test_kinfu.cpp index 18059013ee7..c9a52e576f3 100644 --- a/modules/rgbd/test/test_kinfu.cpp +++ b/modules/rgbd/test/test_kinfu.cpp @@ -141,7 +141,7 @@ struct CubeSpheresScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor)); - return std::move(frame); + return frame; } std::vector getPoses() override @@ -237,7 +237,7 @@ struct RotatingScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor)); - return std::move(frame); + return frame; } std::vector getPoses() override diff --git a/modules/rgbd/test/test_tsdf.cpp b/modules/rgbd/test/test_tsdf.cpp index 31a137854c3..16ed492dd00 100644 --- a/modules/rgbd/test/test_tsdf.cpp +++ b/modules/rgbd/test/test_tsdf.cpp @@ -140,7 +140,7 @@ struct SemisphereScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor, onlySemisphere)); - return std::move(frame); + return frame; } std::vector getPoses() override diff --git a/modules/videostab/src/global_motion.cpp b/modules/videostab/src/global_motion.cpp index 5bef5b1e74f..a30c5caba6e 100644 --- a/modules/videostab/src/global_motion.cpp +++ b/modules/videostab/src/global_motion.cpp @@ -113,7 +113,7 @@ static Mat normalizePoints(int npoints, Point2f *points) T(0,0) = T(1,1) = s; T(0,2) = -cx*s; T(1,2) = -cy*s; - return std::move(T); + return T; } @@ -138,7 +138,7 @@ static Mat estimateGlobMotionLeastSquaresTranslation( *rmse = std::sqrt(*rmse / npoints); } - return std::move(M); + return M; } @@ -219,7 +219,7 @@ static Mat estimateGlobMotionLeastSquaresRotation( *rmse = std::sqrt(*rmse / npoints); } - return std::move(M); + return M; } static Mat estimateGlobMotionLeastSquaresRigid( @@ -273,7 +273,7 @@ static Mat estimateGlobMotionLeastSquaresRigid( *rmse = std::sqrt(*rmse / npoints); } - return std::move(M); + return M; } @@ -484,7 +484,7 @@ Mat estimateGlobalMotionRansac( if (ninliers) *ninliers = ninliersMax; - return std::move(bestM); + return bestM; } @@ -527,7 +527,7 @@ Mat MotionEstimatorRansacL2::estimate(InputArray points0, InputArray points1, bo if (ok) *ok = false; } - return std::move(M); + return M; } @@ -681,7 +681,7 @@ Mat FromFileMotionReader::estimate(const Mat &/*frame0*/, const Mat &/*frame1*/, >> M(1,0) >> M(1,1) >> M(1,2) >> M(2,0) >> M(2,1) >> M(2,2) >> ok_; if (ok) *ok = ok_; - return std::move(M); + return M; } @@ -701,7 +701,7 @@ Mat ToFileMotionWriter::estimate(const Mat &frame0, const Mat &frame1, bool *ok) << M(1,0) << " " << M(1,1) << " " << M(1,2) << " " << M(2,0) << " " << M(2,1) << " " << M(2,2) << " " << ok_ << std::endl; if (ok) *ok = ok_; - return std::move(M); + return M; } diff --git a/modules/ximgproc/test/test_sparse_match_interpolator.cpp b/modules/ximgproc/test/test_sparse_match_interpolator.cpp index 261d6109bf9..33b6df21161 100644 --- a/modules/ximgproc/test/test_sparse_match_interpolator.cpp +++ b/modules/ximgproc/test/test_sparse_match_interpolator.cpp @@ -20,12 +20,12 @@ Mat readOpticalFlow( const String& path ) Mat_ flow; std::ifstream file(path.c_str(), std::ios_base::binary); if ( !file.good() ) - return std::move(flow); // no file - return empty matrix + return flow; // no file - return empty matrix float tag; file.read((char*) &tag, sizeof(float)); if ( tag != FLOW_TAG_FLOAT ) - return std::move(flow); + return flow; int width, height; @@ -44,14 +44,14 @@ Mat readOpticalFlow( const String& path ) if ( !file.good() ) { flow.release(); - return std::move(flow); + return flow; } flow(i, j) = u; } } file.close(); - return std::move(flow); + return flow; } CV_ENUM(GuideTypes, CV_8UC1, CV_8UC3) From d65f85d206311d1c18e7a225c433ff74532c794f Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 6 May 2024 17:18:02 +0300 Subject: [PATCH 2/5] Reduce Mat_ usage. --- modules/face/src/facemarkLBF.cpp | 17 ++++++++--------- modules/face/src/mace.cpp | 2 +- modules/videostab/src/global_motion.cpp | 2 +- .../test/test_sparse_match_interpolator.cpp | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/modules/face/src/facemarkLBF.cpp b/modules/face/src/facemarkLBF.cpp index ce66a419463..0b5b9a698aa 100644 --- a/modules/face/src/facemarkLBF.cpp +++ b/modules/face/src/facemarkLBF.cpp @@ -661,11 +661,10 @@ FacemarkLBFImpl::BBox::BBox(double _x, double _y, double w, double h) { // Project absolute shape to relative shape binding to this bbox Mat FacemarkLBFImpl::BBox::project(const Mat &shape) const { - Mat_ res(shape.rows, shape.cols); - const Mat_ &shape_ = (Mat_)shape; + Mat res(shape.rows, shape.cols, CV_64FC1); for (int i = 0; i < shape.rows; i++) { - res(i, 0) = (shape_(i, 0) - x_center) / x_scale; - res(i, 1) = (shape_(i, 1) - y_center) / y_scale; + res.at(i, 0) = (shape.at(i, 0) - x_center) / x_scale; + res.at(i, 1) = (shape.at(i, 1) - y_center) / y_scale; } return res; } @@ -997,7 +996,7 @@ void FacemarkLBFImpl::RandomForest::train(std::vector &imgs, std::vector lbf_feat(1, landmark_n*trees_n); + Mat lbf_feat(1, landmark_n*trees_n, CV_32SC1); double scale; Mat_ rotate; calcSimilarityTransform(bbox.project(current_shape), mean_shape, scale, rotate); @@ -1036,7 +1035,7 @@ Mat FacemarkLBFImpl::RandomForest::generateLBF(Mat &img, Mat ¤t_shape, BBo idx = 2 * idx + 1; } } - lbf_feat(i*trees_n + j) = (i*trees_n + j)*base + code; + lbf_feat.at(i*trees_n + j) = (i*trees_n + j)*base + code; } } return lbf_feat; @@ -1365,7 +1364,7 @@ Mat FacemarkLBFImpl::Regressor::supportVectorRegression( Mat FacemarkLBFImpl::Regressor::globalRegressionPredict(const Mat &lbf, int stage) { const Mat_ &weight = (Mat_)gl_regression_weights[stage]; - Mat_ delta_shape(weight.rows / 2, 2); + Mat delta_shape(weight.rows / 2, 2, CV_64FC1); const double *w_ptr = NULL; const int *lbf_ptr = lbf.ptr(0); @@ -1374,12 +1373,12 @@ Mat FacemarkLBFImpl::Regressor::globalRegressionPredict(const Mat &lbf, int stag w_ptr = weight.ptr(2 * i); double y = 0; for (int j = 0; j < lbf.cols; j++) y += w_ptr[lbf_ptr[j]]; - delta_shape(i, 0) = y; + delta_shape.at(i, 0) = y; w_ptr = weight.ptr(2 * i + 1); y = 0; for (int j = 0; j < lbf.cols; j++) y += w_ptr[lbf_ptr[j]]; - delta_shape(i, 1) = y; + delta_shape.at(i, 1) = y; } return delta_shape; } // Regressor::globalRegressionPredict diff --git a/modules/face/src/mace.cpp b/modules/face/src/mace.cpp index 71762fe4128..3b7a236828c 100644 --- a/modules/face/src/mace.cpp +++ b/modules/face/src/mace.cpp @@ -102,7 +102,7 @@ struct MACEImpl CV_FINAL : MACE { Mat complexInput; merge(input, 2, complexInput); - Mat_ dftImg(IMGSIZE*2, IMGSIZE*2, 0.0); + Mat dftImg(IMGSIZE*2, IMGSIZE*2, CV_64FC2, 0.0); complexInput.copyTo(dftImg(Rect(0,0,IMGSIZE,IMGSIZE))); dft(dftImg, dftImg); diff --git a/modules/videostab/src/global_motion.cpp b/modules/videostab/src/global_motion.cpp index a30c5caba6e..cbb483c350e 100644 --- a/modules/videostab/src/global_motion.cpp +++ b/modules/videostab/src/global_motion.cpp @@ -82,7 +82,7 @@ namespace videostab { // does isotropic normalization -static Mat normalizePoints(int npoints, Point2f *points) +static Mat_ normalizePoints(int npoints, Point2f *points) { float cx = 0.f, cy = 0.f; for (int i = 0; i < npoints; ++i) diff --git a/modules/ximgproc/test/test_sparse_match_interpolator.cpp b/modules/ximgproc/test/test_sparse_match_interpolator.cpp index 33b6df21161..f53a5add027 100644 --- a/modules/ximgproc/test/test_sparse_match_interpolator.cpp +++ b/modules/ximgproc/test/test_sparse_match_interpolator.cpp @@ -17,7 +17,7 @@ Mat readOpticalFlow( const String& path ) // CV_Assert(sizeof(float) == 4); //FIXME: ensure right sizes of int and float - here and in writeOpticalFlow() - Mat_ flow; + Mat flow; std::ifstream file(path.c_str(), std::ios_base::binary); if ( !file.good() ) return flow; // no file - return empty matrix @@ -32,7 +32,7 @@ Mat readOpticalFlow( const String& path ) file.read((char*) &width, 4); file.read((char*) &height, 4); - flow.create(height, width); + flow.create(height, width, CV_32FC2); for ( int i = 0; i < flow.rows; ++i ) { @@ -47,7 +47,7 @@ Mat readOpticalFlow( const String& path ) return flow; } - flow(i, j) = u; + flow.at(i, j) = u; } } file.close(); From a63bc9ba7054e6700f0a22e9eac76351088b61a8 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 7 May 2024 09:35:41 +0300 Subject: [PATCH 3/5] More test and warning fixes. --- modules/mcc/test/test_mcc.cpp | 4 +++- modules/rgbd/test/ocl/test_tsdf.cpp | 2 +- modules/rgbd/test/test_kinfu.cpp | 4 ++-- modules/rgbd/test/test_tsdf.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/mcc/test/test_mcc.cpp b/modules/mcc/test/test_mcc.cpp index 374b829b4b2..dd0dd28439d 100644 --- a/modules/mcc/test/test_mcc.cpp +++ b/modules/mcc/test/test_mcc.cpp @@ -102,7 +102,9 @@ TEST(CV_mcc_ccm_test, detect_Macbeth) // check Macbeth corners vector corners = checker->getBox(); - EXPECT_MAT_NEAR(gold_corners, corners, 3.6); // diff 3.57385 in ARM only + // diff 3.57385 corresponds to ARM v8 + // diff 4.37915 correspnds to Ubuntu 24.04 x86_64 configuration + EXPECT_MAT_NEAR(gold_corners, corners, 4.38); // read gold chartsRGB node = fs["chartsRGB"]; diff --git a/modules/rgbd/test/ocl/test_tsdf.cpp b/modules/rgbd/test/ocl/test_tsdf.cpp index bedce1a562e..fa3d593cb4f 100644 --- a/modules/rgbd/test/ocl/test_tsdf.cpp +++ b/modules/rgbd/test/ocl/test_tsdf.cpp @@ -143,7 +143,7 @@ struct SemisphereScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor, onlySemisphere)); - return frame; + return static_cast(frame); } std::vector getPoses() override diff --git a/modules/rgbd/test/test_kinfu.cpp b/modules/rgbd/test/test_kinfu.cpp index c9a52e576f3..e9c821f1577 100644 --- a/modules/rgbd/test/test_kinfu.cpp +++ b/modules/rgbd/test/test_kinfu.cpp @@ -141,7 +141,7 @@ struct CubeSpheresScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor)); - return frame; + return static_cast(frame); } std::vector getPoses() override @@ -237,7 +237,7 @@ struct RotatingScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor)); - return frame; + return static_cast(frame); } std::vector getPoses() override diff --git a/modules/rgbd/test/test_tsdf.cpp b/modules/rgbd/test/test_tsdf.cpp index 16ed492dd00..f5a88180923 100644 --- a/modules/rgbd/test/test_tsdf.cpp +++ b/modules/rgbd/test/test_tsdf.cpp @@ -140,7 +140,7 @@ struct SemisphereScene : Scene Range range(0, frame.rows); parallel_for_(range, RenderInvoker(frame, pose, reproj, depthFactor, onlySemisphere)); - return frame; + return static_cast(frame); } std::vector getPoses() override From 8305b2d5edcc24318b9869228b9444cbcdfe7d7d Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 14 May 2024 09:17:34 +0300 Subject: [PATCH 4/5] More warning fixes. --- modules/face/src/facemarkLBF.cpp | 7 ++- modules/rgbd/perf/perf_tsdf.cpp | 4 +- modules/rgbd/test/test_colored_kinfu.cpp | 12 ++--- modules/videostab/src/global_motion.cpp | 65 ++++++++++++------------ 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/modules/face/src/facemarkLBF.cpp b/modules/face/src/facemarkLBF.cpp index 0b5b9a698aa..49cd8f63fea 100644 --- a/modules/face/src/facemarkLBF.cpp +++ b/modules/face/src/facemarkLBF.cpp @@ -671,11 +671,10 @@ Mat FacemarkLBFImpl::BBox::project(const Mat &shape) const { // Project relative shape to absolute shape binding to this bbox Mat FacemarkLBFImpl::BBox::reproject(const Mat &shape) const { - Mat_ res(shape.rows, shape.cols); - const Mat_ &shape_ = (Mat_)shape; + Mat res(shape.rows, shape.cols, CV_64FC1); for (int i = 0; i < shape.rows; i++) { - res(i, 0) = shape_(i, 0)*x_scale + x_center; - res(i, 1) = shape_(i, 1)*y_scale + y_center; + res.at(i, 0) = shape.at(i, 0)*x_scale + x_center; + res.at(i, 1) = shape.at(i, 1)*y_scale + y_center; } return res; } diff --git a/modules/rgbd/perf/perf_tsdf.cpp b/modules/rgbd/perf/perf_tsdf.cpp index efce51b53e3..999ddb51673 100644 --- a/modules/rgbd/perf/perf_tsdf.cpp +++ b/modules/rgbd/perf/perf_tsdf.cpp @@ -91,7 +91,7 @@ struct Scene { virtual ~Scene() {} static Ptr create(Size sz, Matx33f _intr, float _depthFactor, bool onlySemisphere); - virtual Mat depth(Affine3f pose) = 0; + virtual Mat_ depth(const Affine3f& pose) = 0; virtual std::vector getPoses() = 0; }; @@ -131,7 +131,7 @@ struct SemisphereScene : Scene return res; } - Mat depth(Affine3f pose) override + Mat_ depth(const Affine3f& pose) override { Mat_ frame(frameSize); Reprojector reproj(intr); diff --git a/modules/rgbd/test/test_colored_kinfu.cpp b/modules/rgbd/test/test_colored_kinfu.cpp index e92c56d8b7e..0ff90704e93 100644 --- a/modules/rgbd/test/test_colored_kinfu.cpp +++ b/modules/rgbd/test/test_colored_kinfu.cpp @@ -158,8 +158,8 @@ struct Scene { virtual ~Scene() {} static Ptr create(int nScene, Size sz, Matx33f _intr, float _depthFactor); - virtual Mat depth(Affine3f pose) = 0; - virtual Mat rgb(Affine3f pose) = 0; + virtual Mat_ depth(const Affine3f& pose) = 0; + virtual Mat_ rgb(const Affine3f& pose) = 0; virtual std::vector getPoses() = 0; }; @@ -198,7 +198,7 @@ struct CubeSpheresScene : Scene return res; } - Mat depth(Affine3f pose) override + Mat_ depth(const Affine3f& pose) override { Mat_ frame(frameSize); Reprojector reproj(intr); @@ -209,7 +209,7 @@ struct CubeSpheresScene : Scene return frame; } - Mat rgb(Affine3f pose) override + Mat_ rgb(const Affine3f& pose) override { Mat_ frame(frameSize); Reprojector reproj(intr); @@ -305,7 +305,7 @@ struct RotatingScene : Scene return res; } - Mat depth(Affine3f pose) override + Mat_ depth(const Affine3f& pose) override { Mat_ frame(frameSize); Reprojector reproj(intr); @@ -316,7 +316,7 @@ struct RotatingScene : Scene return frame; } - Mat rgb(Affine3f pose) override + Mat_ rgb(const Affine3f& pose) override { Mat_ frame(frameSize); Reprojector reproj(intr); diff --git a/modules/videostab/src/global_motion.cpp b/modules/videostab/src/global_motion.cpp index cbb483c350e..eb42d6954d6 100644 --- a/modules/videostab/src/global_motion.cpp +++ b/modules/videostab/src/global_motion.cpp @@ -120,21 +120,21 @@ static Mat_ normalizePoints(int npoints, Point2f *points) static Mat estimateGlobMotionLeastSquaresTranslation( int npoints, Point2f *points0, Point2f *points1, float *rmse) { - Mat_ M = Mat::eye(3, 3, CV_32F); + Mat M = Mat::eye(3, 3, CV_32FC1); for (int i = 0; i < npoints; ++i) { - M(0,2) += points1[i].x - points0[i].x; - M(1,2) += points1[i].y - points0[i].y; + M.at(0,2) += points1[i].x - points0[i].x; + M.at(1,2) += points1[i].y - points0[i].y; } - M(0,2) /= npoints; - M(1,2) /= npoints; + M.at(0,2) /= npoints; + M.at(1,2) /= npoints; if (rmse) { *rmse = 0; for (int i = 0; i < npoints; ++i) - *rmse += sqr(points1[i].x - points0[i].x - M(0,2)) + - sqr(points1[i].y - points0[i].y - M(1,2)); + *rmse += sqr(points1[i].x - points0[i].x - M.at(0,2)) + + sqr(points1[i].y - points0[i].y - M.at(1,2)); *rmse = std::sqrt(*rmse / npoints); } @@ -194,16 +194,16 @@ static Mat estimateGlobMotionLeastSquaresRotation( // A*sin(alpha) + B*cos(alpha) = 0 float C = std::sqrt(A*A + B*B); - Mat_ M = Mat::eye(3, 3, CV_32F); + Mat M = Mat::eye(3, 3, CV_32F); if ( C != 0 ) { float sinAlpha = - B / C; float cosAlpha = A / C; - M(0,0) = cosAlpha; - M(1,1) = M(0,0); - M(0,1) = sinAlpha; - M(1,0) = - M(0,1); + M.at(0,0) = cosAlpha; + M.at(1,1) = cosAlpha; + M.at(0,1) = sinAlpha; + M.at(1,0) = - sinAlpha; } if (rmse) @@ -213,8 +213,8 @@ static Mat estimateGlobMotionLeastSquaresRotation( { p0 = points0[i]; p1 = points1[i]; - *rmse += sqr(p1.x - M(0,0)*p0.x - M(0,1)*p0.y) + - sqr(p1.y - M(1,0)*p0.x - M(1,1)*p0.y); + *rmse += sqr(p1.x - M.at(0,0)*p0.x - M.at(0,1)*p0.y) + + sqr(p1.y - M.at(1,0)*p0.x - M.at(1,1)*p0.y); } *rmse = std::sqrt(*rmse / npoints); } @@ -222,7 +222,7 @@ static Mat estimateGlobMotionLeastSquaresRotation( return M; } -static Mat estimateGlobMotionLeastSquaresRigid( +static Mat estimateGlobMotionLeastSquaresRigid( int npoints, Point2f *points0, Point2f *points1, float *rmse) { Point2f mean0(0.f, 0.f); @@ -250,15 +250,15 @@ static Mat estimateGlobMotionLeastSquaresRigid( A(1,1) += pt1.y * pt0.y; } - Mat_ M = Mat::eye(3, 3, CV_32F); + Mat M = Mat::eye(3, 3, CV_32FC1); SVD svd(A); Mat_ R = svd.u * svd.vt; Mat tmp(M(Rect(0,0,2,2))); R.copyTo(tmp); - M(0,2) = mean1.x - R(0,0)*mean0.x - R(0,1)*mean0.y; - M(1,2) = mean1.y - R(1,0)*mean0.x - R(1,1)*mean0.y; + M.at(0,2) = mean1.x - R(0,0)*mean0.x - R(0,1)*mean0.y; + M.at(1,2) = mean1.y - R(1,0)*mean0.x - R(1,1)*mean0.y; if (rmse) { @@ -267,8 +267,8 @@ static Mat estimateGlobMotionLeastSquaresRigid( { pt0 = points0[i]; pt1 = points1[i]; - *rmse += sqr(pt1.x - M(0,0)*pt0.x - M(0,1)*pt0.y - M(0,2)) + - sqr(pt1.y - M(1,0)*pt0.x - M(1,1)*pt0.y - M(1,2)); + *rmse += sqr(pt1.x - M.at(0,0)*pt0.x - M.at(0,1)*pt0.y - M.at(0,2)) + + sqr(pt1.y - M.at(1,0)*pt0.x - M.at(1,1)*pt0.y - M.at(1,2)); } *rmse = std::sqrt(*rmse / npoints); } @@ -404,7 +404,7 @@ Mat estimateGlobalMotionRansac( // best hypothesis std::vector bestIndices(params.size); - Mat_ bestM; + Mat bestM; int ninliersMax = -1; RNG rng(0); @@ -469,8 +469,8 @@ Mat estimateGlobalMotionRansac( { p0 = points0_[i]; p1 = points1_[i]; - x = bestM(0,0)*p0.x + bestM(0,1)*p0.y + bestM(0,2); - y = bestM(1,0)*p0.x + bestM(1,1)*p0.y + bestM(1,2); + x = bestM.at(0,0)*p0.x + bestM.at(0,1)*p0.y + bestM.at(0,2); + y = bestM.at(1,0)*p0.x + bestM.at(1,1)*p0.y + bestM.at(1,2); if (sqr(x - p1.x) + sqr(y - p1.y) < params.thresh * params.thresh) { subset0[j] = p0; @@ -505,7 +505,7 @@ Mat MotionEstimatorRansacL2::estimate(InputArray points0, InputArray points1, bo // find motion int ninliers = 0; - Mat_ M; + Mat M; if (motionModel() != MM_HOMOGRAPHY) M = estimateGlobalMotionRansac( @@ -675,11 +675,11 @@ FromFileMotionReader::FromFileMotionReader(const String &path) Mat FromFileMotionReader::estimate(const Mat &/*frame0*/, const Mat &/*frame1*/, bool *ok) { - Mat_ M(3, 3); + Mat M(3, 3, CV_32FC1); bool ok_; - file_ >> M(0,0) >> M(0,1) >> M(0,2) - >> M(1,0) >> M(1,1) >> M(1,2) - >> M(2,0) >> M(2,1) >> M(2,2) >> ok_; + file_ >> M.at(0,0) >> M.at(0,1) >> M.at(0,2) + >> M.at(1,0) >> M.at(1,1) >> M.at(1,2) + >> M.at(2,0) >> M.at(2,1) >> M.at(2,2) >> ok_; if (ok) *ok = ok_; return M; } @@ -696,10 +696,11 @@ ToFileMotionWriter::ToFileMotionWriter(const String &path, Ptr M = motionEstimator_->estimate(frame0, frame1, &ok_); - file_ << M(0,0) << " " << M(0,1) << " " << M(0,2) << " " - << M(1,0) << " " << M(1,1) << " " << M(1,2) << " " - << M(2,0) << " " << M(2,1) << " " << M(2,2) << " " << ok_ << std::endl; + Mat M = motionEstimator_->estimate(frame0, frame1, &ok_); + file_ << M.at(0,0) << " " << M.at(0,1) << " " << M.at(0,2) << " " + << M.at(1,0) << " " << M.at(1,1) << " " << M.at(1,2) << " " + << M.at(2,0) << " " << M.at(2,1) << " " << M.at(2,2) << " " + << ok_ << std::endl; if (ok) *ok = ok_; return M; } From a7cf92e8e37fef3d7dc2e841951db23543fe5405 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 14 May 2024 11:47:38 +0300 Subject: [PATCH 5/5] MCC test tuning. --- modules/mcc/test/test_mcc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mcc/test/test_mcc.cpp b/modules/mcc/test/test_mcc.cpp index dd0dd28439d..37bd1f11fc7 100644 --- a/modules/mcc/test/test_mcc.cpp +++ b/modules/mcc/test/test_mcc.cpp @@ -114,7 +114,7 @@ TEST(CV_mcc_ccm_test, detect_Macbeth) // check chartsRGB Mat chartsRGB = checker->getChartsRGB(); - EXPECT_MAT_NEAR(goldChartsRGB.col(1), chartsRGB.col(1), 0.25); // diff 0.240634 in ARM only + EXPECT_MAT_NEAR(goldChartsRGB.col(1), chartsRGB.col(1), 0.3); // diff 0.292077 on Ubuntu 20.04 ARM64 } TEST(CV_mcc_ccm_test, compute_ccm)