First time here? Check out the FAQ!

Ask Your Question
1

Interfacing OpenCV and Cuda

asked May 28 '13

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.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered May 28 '13

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.

Preview: (hide)

Question Tools

Stats

Asked: May 28 '13

Seen: 2,718 times

Last updated: May 28 '13