Ask Your Question
0

How to bind GpuMat to texture

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

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, Image.data, desc, W, H, Image.step));
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

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

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.data, Image.step, Image.cols, Image.rows);
}
edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit

Thanks, it's helpful.

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

Question Tools

Stats

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

Seen: 3,074 times

Last updated: Mar 18 '13