Ask Your Question

Revision history [back]

It seems that in order to get the cuda functionality working you need to explicitly include the CUDA header of that function. This setup did it just fine on my system

#include <opencv2/opencv.hpp>
#include <opencv2/cuda.hpp>
#include <opencv2/cudaimgproc.hpp>

using namespace cv;

int main() {
    Mat src = imread("car1080.jpg", 0);
    if (!src.data) exit(1);
    cuda::GpuMat d_src(src);
    cuda::GpuMat d_dst;
    cuda::bilateralFilter(d_src, d_dst, -1, 50, 7);
    cv::Canny(d_dst, d_dst, 35, 200, 3);
    Mat dst(d_dst);
    imwrite("out.png", dst);
    return 0;
}

It seems that in order to get the cuda functionality working you need to explicitly include the CUDA header of that function. This setup did it just fine on my system

UPDATE

  • It seems that the error is not due the reasons I expected but due to the misuse between Mat and GpuMat container.
  • There is no constructor for a Mat element that takes a GpuMat as input.
  • In order to transfer data you need to download from Gpu memory.

Adapted and working code --> Verified

#include <opencv2/opencv.hpp>
#include <opencv2/cuda.hpp>
#include <opencv2/cudaimgproc.hpp>

using namespace cv;

int main() {
    Mat src = imread("car1080.jpg", imread("/home/spu/Desktop/test.jpg", 0);
    if (!src.data) exit(1);
    cuda::GpuMat d_src(src);
    cuda::GpuMat d_dst;
    cuda::bilateralFilter(d_src, d_dst, -1, 50, 7);
    cv::Canny(d_dst, d_dst, Mat dst;
    d_dst.download(dst);
    cv::Canny(dst, dst, 35, 200, 3);
    Mat dst(d_dst);
    imwrite("out.png", dst);
resize(dst, dst, Size(dst.cols/3, dst.rows/3));
    imshow("test", dst); waitKey(0);
    return 0;
}

And the result as seen below

image description