在OpenCV C ++中使用gpu :: GpuMat [英] Using gpu::GpuMat in OpenCV C++

查看:1519
本文介绍了在OpenCV C ++中使用gpu :: GpuMat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何修改 gpu :: GpuMat 。事实上,我想知道是否可以使用 gpu :: GpuMat cv :: Mat

I would like to know how can I modify a gpu::GpuMat. In fact I would like to know if it is possible to use a gpu::GpuMat like a cv::Mat.

我想这样做:

    cv::namedWindow("Result");
    cv::Mat src_host = cv::imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    cv::gpu::GpuMat dst, src;
    src.upload(src_host);


    for (unsigned int y = 0; y < src.rows; y++){
        for (unsigned int x = 0; x < src.cols; x++){
            src.at<uchar>(y,x) = 0;
        }
    }

    cv::Mat result_host;
    dst.download(result_host);
    cv::imshow("Result", result_host);
    cv::waitKey();
}
catch(const cv::Exception& ex)
{
    std::cout << "Error: " << ex.what() << std::endl;
}
return 0;

似乎不可能。有人知道一个替代品吗?
每次我需要下载我的 gpu :: GpuMat cv :: Mat 做什么?
提前感谢

It seems to be not possible. Does someone know an alternative ? Do I have to download my gpu::GpuMat to a cv::Mat each time I want to make something ? Thanks in advance

编辑:我可以使用 gpu :: PtrStepSz ..)

I could probably use gpu::PtrStepSz (have to test...)

推荐答案

GpuMat 分配在GPU内存中。您不能从CPU代码修改它。您可以

GpuMat is allocated in GPU memory. You can't modify it from CPU code. You can


  1. 将所有矩阵像素设置为相同的值( setTo 方法)。

  2. 使用 cv :: Mat 在CPU上填充数据,然后将其上传到 GpuMat

  3. 实现您自己的CUDA内核,并在其中填写 GpuMat

  1. Set all matrix pixels to the same value (setTo method).
  2. Fill data on CPU using cv::Mat and then upload it to GpuMat.
  3. Implement your own CUDA kernel and fill GpuMat in it.

这篇关于在OpenCV C ++中使用gpu :: GpuMat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆