Invalid argument in function 'copyTo'

I need to use opencv-cuda for some image distortion correction, I manually transplanted opencv4.6.0 version, and the following error occurred during use.

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.6.0) /home/hl/Workspace/opencv/workspace/opencv-4.6.0/modules/core/src/cuda/gpu_mat.cu:270: error: (-217:Gpu API call) invalid argument in function 'copyTo

image

Here’s my code:

static cv::cuda::GpuMat gpu_xmap, gpu_ymap;

static void cv_process_RGBA(void *pdata, int32_t width, int32_t height)
{
    cv::cuda::GpuMat d_Mat_RGBA(height, width, CV_8UC4, pdata,16640);
    cv::cuda::GpuMat d_Mat_RGBA_Src;
    d_Mat_RGBA.copyTo(d_Mat_RGBA_Src); // cannot avoid one copy
    cv::cuda::remap(d_Mat_RGBA_Src, d_Mat_RGBA, gpu_xmap, gpu_ymap, cv::INTER_CUBIC, cv::BORDER_CONSTANT, cv::Scalar(0.f, 0.f, 0.f, 0.f));

    // Check
    if(d_Mat_RGBA.data != pdata)
        std::cerr << "Error reallocated buffer for d_Mat_RGBA" << std::endl;
}

Hi,

Please try to initialize d_Mat_RGBA_Src and try it again.

Thanks.

I’m sorry for replying you so late. I think I already know the problem. The following commands sudo apt install nvidia_jetpack led to the installation of 4.5.4 without cuda, and then the system was still linked to some residual junk files of 4.5.4 when 4.6.0 was installed without manual uninstallation.