Ask Your Question

How to bind GpuMat to texture

asked 2013-03-18 05:52:00 -0500

Gianluigi gravatar image

I have a GpuMat Image(H, W, CV_8UC3)
May I bind it using these function?

texture<uchar3, 2, cudaReadModeNormalizedFloat> rgbTex;
cudaChannelFormatDesc desc = cudaCreateChannelDesc<uchar3>();
cudaBindTexture2D(0, rgbTex,, desc, W, H, Image.step));
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-18 06:06:30 -0500

Vladislav Vinogradov gravatar image

The main problem is that you can't use GpuMat in .cu files (nvcc can't compile gpumat.hpp header). You can pass only GpuMat's members to functions from .cu file:

// .cu file

texture<uchar3, 2, cudaReadModeNormalizedFloat> rgbTex;

void cu_func(void* data, size_t step, int width, int height)
    cudaChannelFormatDesc desc = cudaCreateChannelDesc<uchar3>();
    cudaBindTexture2D(0, rgbTex, data, desc, width, height, step));

// .cpp file

void cu_func(void* data, size_t step, int width, int height);

void cpp_func(GpuMat Image)
    cu_func(, Image.step, Image.cols, Image.rows);
edit flag offensive delete link more


If I include gpu/device/common.hpp, I can use PtrStep and PtrStepSz in cu files, so I can do things just like I post. Is it right?

Gianluigi gravatar imageGianluigi ( 2013-03-18 20:58:36 -0500 )edit

Yes. You can also use bindTexture function from common.hpp: cv::gpu::device::bindTexture(&tex, img);

Vladislav Vinogradov gravatar imageVladislav Vinogradov ( 2013-03-19 01:03:49 -0500 )edit

Thanks, it's helpful.

Gianluigi gravatar imageGianluigi ( 2013-03-19 01:46:06 -0500 )edit

Question Tools


Asked: 2013-03-18 05:52:00 -0500

Seen: 2,283 times

Last updated: Mar 18 '13