From f66a2ffa1ebba245faa5d578969c537f1d18cdea Mon Sep 17 00:00:00 2001 From: cudawarped <12133430+cudawarped@users.noreply.github.com> Date: Wed, 2 Feb 2022 14:25:46 +0000 Subject: [PATCH] Fix GpuMat to correctly calculate dataend when using GpuMat::create(). Add output to createMat() to be used by locateROI test cases. --- modules/core/src/cuda/gpu_mat.cu | 5 +---- modules/ts/include/opencv2/ts/cuda_test.hpp | 1 + modules/ts/src/cuda_test.cpp | 15 +++++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/core/src/cuda/gpu_mat.cu b/modules/core/src/cuda/gpu_mat.cu index f31f78a..c286f28 100644 --- a/modules/core/src/cuda/gpu_mat.cu +++ b/modules/core/src/cuda/gpu_mat.cu @@ -184,11 +184,8 @@ void cv::cuda::GpuMat::create(int _rows, int _cols, int _type) if (esz * cols == step) flags |= Mat::CONTINUOUS_FLAG; - int64 _nettosize = static_cast(step) * rows; - size_t nettosize = static_cast(_nettosize); - datastart = data; - dataend = data + nettosize; + dataend = data + step * (rows - 1) + cols * esz; if (refcount) *refcount = 1; diff --git a/modules/ts/include/opencv2/ts/cuda_test.hpp b/modules/ts/include/opencv2/ts/cuda_test.hpp index 53bdbc8..f1851c5 100644 --- a/modules/ts/include/opencv2/ts/cuda_test.hpp +++ b/modules/ts/include/opencv2/ts/cuda_test.hpp @@ -63,6 +63,7 @@ namespace cvtest // GpuMat create cv::cuda::GpuMat createMat(cv::Size size, int type, bool useRoi = false); + cv::cuda::GpuMat createMat(cv::Size size, int type, cv::Size& size0, cv::Point& ofs, bool useRoi = false); cv::cuda::GpuMat loadMat(const cv::Mat& m, bool useRoi = false); ////////////////////////////////////////////////////////////////////// diff --git a/modules/ts/src/cuda_test.cpp b/modules/ts/src/cuda_test.cpp index 3870415f..a50f2cc 100644 --- a/modules/ts/src/cuda_test.cpp +++ b/modules/ts/src/cuda_test.cpp @@ -91,7 +91,13 @@ namespace cvtest GpuMat createMat(Size size, int type, bool useRoi) { - Size size0 = size; + Size size0; Point ofs; + return createMat(size, type, size0, ofs, useRoi); + } + + GpuMat createMat(Size size, int type, Size& size0, Point& ofs, bool useRoi) + { + size0 = size; if (useRoi) { @@ -100,9 +106,10 @@ namespace cvtest } GpuMat d_m(size0, type); - - if (size0 != size) - d_m = d_m(Rect((size0.width - size.width) / 2, (size0.height - size.height) / 2, size.width, size.height)); + if (size0 != size) { + ofs = Point((size0.width - size.width) / 2, (size0.height - size.height) / 2); + d_m = d_m(Rect(ofs, size)); + } return d_m; } -- 2.7.4