OpenCV GPU Dilate无法正常工作

时间:2014-08-19 17:35:13

标签: opencv gpu

我正在尝试使用OpenCV GPU执行Dilate和Erode功能,但由于某种原因它返回了黑色图像。我只是想不出来是什么问题;

我正在使用的代码:

int erosionDilation_size = 5;
Mat element = cv::getStructuringElement(MORPH_RECT, Size(2*erosionDilation_size + 1,    2*erosionDilation_size+1));
cv::gpu::dilate(_gpuProcessOutput[__n],  _gpuProcessOutput[__n],element);
_gpuProcessOutput[__n].download(_frame[__n]);
imshow("Test",_frame[0]);
cvWaitKey(1000/120);

有谁知道发生了什么?谢谢!

更新 这是我试图扩张的形象! Image1

1 个答案:

答案 0 :(得分:1)

这对我有用:

    #include "opencv2/opencv.hpp"
    #include "opencv2/cudafilters.hpp"
    #include "opencv2/cudaimgproc.hpp"
    using namespace std;
    using namespace cv;
    using namespace cv::cuda;

    //-----------------------------------------------------------------------------------------------------
    //
    //-----------------------------------------------------------------------------------------------------
    int main ( int argc, char** argv )
    {
        cv::cuda::setDevice(0);
        // -------------------------------
        // 
        // -------------------------------
    Mat img=imread("test.png",0);
    int erosionDilation_size = 5;
    Mat element = cv::getStructuringElement(MORPH_RECT, Size(2*erosionDilation_size + 1,    2*erosionDilation_size+1));

    cuda::GpuMat d_element(element);
    cuda::GpuMat d_img(img);

    Ptr<cuda::Filter> dilateFilter = cuda::createMorphologyFilter(MORPH_DILATE, d_img.type(), element);
    dilateFilter->apply(d_img, d_img);


    d_img.download(img);

    d_img.release();
    d_element.release();

    imshow("test",img);
    waitKey();
    }