Ask Your Question
1

Interfacing OpenCV and Cuda

asked 2013-05-28 07:57:26 -0500

vent_d_ame gravatar image

I wish to interface OpenCV with Cuda. By this, I mean:

  • given a T* pointer on a GPU memory block allocated with cudaMalloc, how create an OpenCV GpuMat using this allocation (without copy, and later losing my block when the GpuMat object is destroyed).
  • given a GpuMat object, how to get the associated device pointer usable by cuda (seems from a previous answer that the ptr<> method can do this).

Thanks for your help.

Note: cuda5 is now able to compile the gpumat.hpp header.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-05-28 13:27:34 -0500

Vladislav Vinogradov gravatar image

You can create GpuMat object for existed pointer and GpuMat will not delete this memory in destructor:

void* data;
size_t step;
cudaMalloc2D(&data, &step, width * sizeof(float), height);
GpuMat mat(height, width, CV_32FC1, (uchar*) data, step);
gpu::bitwize_not(mat, mat);
cudaFree(data);

And you can get device pointer from GpuMat with ptr<> method:

float* data = mat.ptr<float>();
size_t step = mat.step;

The same is true for cv::Mat and CPU memory.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-05-28 07:57:26 -0500

Seen: 2,122 times

Last updated: May 28 '13