Repository: opencv/opencv_contrib

Issue #2361: Bug in cv::cuda::warpPerspective
Created: 2019-11-25T07:11:50Z
System information (version)


OpenCV => 4.1.0
Operating System / Platform => debian10
Compiler => g++-8.3.0
Cuda => cuda-10.1

Detailed description
With some matricies (perspective transformation) I get exception about illegal memory access in GPU memory:
OpenCV(4.1.0) /tmp/opencv_dir/modules/core/src/cuda_stream.cpp:473: error: (-217:Gpu API call) an illegal memory access was encountered in function 'waitForCompletion'

This happens only if I use not default stream and linear interpolation.
Steps to reproduce
Tested with cuda-10.1 and opencv-4.1.0.
// main.cpp

#include <cstdlib>
#include <opencv2/cudawarping.hpp>
#include <vector>

int main() {
  cv::Size inputSize{1000, 1000}; // can be different

  cv::Size outSize{670, 893};
  std::vector<double> values{
      0.3154414342519155,    0.2158186507123098,    133.1013012869572,
      -0.01298153793321658,  0.5681477441984867,    297.7284881948252,
      1.839213382549264e-05, 0.0006366310508410327, 1};

  cv::Mat matrix{cv::Size{3, 3}, CV_64FC1, values.data()};

  cv::cuda::GpuMat image{inputSize, CV_8UC4};

  cv::cuda::Stream stream;
  cv::cuda::warpPerspective(image, image, matrix, outSize, cv::INTER_LINEAR,
                            cv::BORDER_CONSTANT, cv::Scalar{0, 0, 0, 0},
                            stream);
  stream.waitForCompletion();

  return EXIT_SUCCESS;
}
# cmake

cmake_minimum_required(VERSION 3.12)

project(min_ex)

find_package(OpenCV COMPONENTS core cudawarping REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS})
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS})

Duplicate issue #2712: cuda::remap - illegal memory access
Created: 2020-10-15T09:28:02Z
System information (version)


OpenCV => 4.4.0
Operating System / Platform => Windows 64 Bit / ubuntu 18.04 amd64
Compiler => Visual Studio 2019 / gcc 7.5.0

Detailed description
For some specific data, the cpu version remap works fine, but the cuda version remap can not work. The error message is as follows:
OpenCV(4.4.0) Error: Gpu API call (an illegal memory access was encountered) in cv::cuda::device::imgproc::RemapDispatcherNonStream<Filter, B, T>::call, file D:/programming/ opencv_contrib-4.4.0/modules/cudawarping/src/cuda/remap.cu, line 107
Steps to reproduce

map data to reproduce:map.zip
// C++ code example

#include <opencv2/opencv.hpp>
#include <opencv2/cudawarping.hpp>

using namespace cv;
using namespace cv::cuda;

int main(int argc, const char** argv)
{
	FileStorage fs("D:/map.yml", FileStorage::READ);
	Mat map1, map2;
	fs["map1"] >> map1;
	fs["map2"] >> map2;
	fs.release();

	Mat src, dst;
	src = Mat(640, 640, CV_8UC3, Scalar(255,255,255));
	cv::remap(src, dst, map1, map2, INTER_LINEAR);

	imshow("dst", dst);
	waitKey();

	GpuMat gsrc, gdst, gmap1, gmap2;
	gmap1.upload(map1);
	gmap2.upload(map2);
	gsrc.upload(src);
	cuda::remap(gsrc, gdst, gmap1, gmap2, INTER_LINEAR);
	gdst.download(dst);

	imshow("gdst", dst);
	waitKey();

	return 0;
}
Issue submission checklist

 I report the issue, it's not a question


 I checked the problem with documentation, FAQ, open issues,
answers.opencv.org, Stack Overflow, etc and have not found solution


 I updated to latest OpenCV version and the issue is still there


 There is reproducer code and related data files: videos, images, onnx, etc

Closing comment (2020-10-15T09:33:56Z): Looks like a duplicate of #2361