Ask Your Question

GpuMat to device data type conversion

asked 2012-10-25 06:49:46 -0600

Quan Tran Minh gravatar image

Hi all,

I wonder to know that is there a way to convert GpuMat to CUDA data type and vice versa? Say, I have GpuMat(512, 512, CV_32FC2) and I want to convert it to float2* which has 512*512 elements. The reason is I want to write my own kernel outside cv::gpu modules. It seems that the smart pointer could work in this case.

Best regards,

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-10-25 07:08:48 -0600

Vladislav Vinogradov gravatar image
GpuMat d_mat(512, 512, CV_32FC2);
float2* data = d_mat.ptr<float>();
size_t step = d_mat.step;
// kernel
__global__ void func(float2* data, size_t step)
    int x = ...;
    int y = ...;
    float2* row_y = (float2*)((char*)data + y * step);
    float2 val = row_y[x];
edit flag offensive delete link more


thanks a lot ^^ I gotta try :)

Quan Tran Minh gravatar imageQuan Tran Minh ( 2012-10-25 09:14:31 -0600 )edit

Dear Sir,

you are my saviour.

tfreitas gravatar imagetfreitas ( 2017-10-20 12:05:34 -0600 )edit

Question Tools


Asked: 2012-10-25 06:49:46 -0600

Seen: 2,597 times

Last updated: Oct 25 '12