Using gpu::GpuMat in OpenCV C++
13,524
GpuMat
is allocated in GPU memory. You can't modify it from CPU code. You can
- Set all matrix pixels to the same value (
setTo
method). - Fill data on CPU using
cv::Mat
and then upload it toGpuMat
. - Implement your own CUDA kernel and fill
GpuMat
in it.
Author by
Poko
I am actually working on Computer Vision technologies in C++ and NodeJS.
Updated on June 15, 2022Comments
-
Poko almost 2 years
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 agpu::GpuMat
like acv::Mat
.I would like to do something like that:
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;
It seems to be not possible. Does someone know an alternative ? Do I have to download my
gpu::GpuMat
to acv::Mat
each time I want to make something ? Thanks in advanceEdit: I could probably use
gpu::PtrStepSz
(have to test...) -
Poko almost 11 yearsThanks ! that's what I was thinking ... :/