First time here? Check out the FAQ!

Ask Your Question
0

How to bind GpuMat to texture

asked Mar 18 '13

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));
Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Mar 18 '13

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);
}
Preview: (hide)

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 (Mar 19 '13)edit

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

Thanks, it's helpful.

Gianluigi gravatar imageGianluigi (Mar 19 '13)edit

Question Tools

Stats

Asked: Mar 18 '13

Seen: 3,183 times

Last updated: Mar 18 '13