'Error occuring when applying MedianFilter or HoughTransform on a cuda::GpuMat in OpenCV "getGpuMat" not implemented

applying median filter or hough transform on a cuda::gpu Mat in opencv gives the the following error

OpenCV(4.5.5) /build/opencv/src/opencv-4.5.5/modules/core/src/matrix_wrap.cpp:342: error: (-213:The function/feature is not implemented) getGpuMat is available only for cuda::GpuMat and cuda::HostMem in function 'getGpuMat'

I searched through the web for hours and I am still clueless on why such error is occuring.

compiling the executable does not output any errors or warnings yet the error above is showing on runtime

here is the basic code I am using to test the functions with

#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/cudafeatures2d.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/cudafilters.hpp>
#include <chrono>
#include <iostream>

int main()
{
    try
    {
    cv::cuda::DeviceInfo device;
    cv::cuda::setDevice(device.deviceID());
    cv::cuda::GpuMat cudaMat;
    cv::Ptr<cv::cuda::Filter> medianFilter = cv::cuda::createMedianFilter(CV_8UC1,9);
    cv::Ptr<cv::cuda::HoughCirclesDetector> houghcircles = cv::cuda::createHoughCirclesDetector(1.5,25,165,30,7,15);
    cv::Mat img;
    img = cv::imread("./sample.jpg");
    cv::cvtColor(img, img, cv::COLOR_BGR2GRAY);
    cudaMat.upload(img);
    medianFilter->apply(cudaMat,cudaMat);
    std::vector<cv::Vec3f> circles;
    houghcircles->detect(cudaMat,circles);
    /*
    for (size_t i = 0; i < circles.size(); i++)
    {
        cv::Vec3i c = circles[i];
        cv::Point center = cv::Point(c[0], c[1]);
        cv::circle(img, center, 1, cv::Scalar(0, 100, 100), 3, cv::LINE_AA);
        int radius = c[2];
        cv::circle(img, center, radius, cv::Scalar(255, 0, 255), 3, cv::LINE_AA);
        
    }
    */
    cudaMat.download(img);
    cv::namedWindow("detected",cv::WINDOW_NORMAL);
    cv::imshow("detected",img);
    }
    catch(const cv::Exception& e)
    {
        std::cerr << e.what() << '\n';
    }
    
    
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source