cuda内核的opencv 3通道图像数据偏移量

时间:2013-03-11 10:45:58

标签: opencv cuda kernel offset

我有以下代码段:

// main.cu

#define thread 16

dim3 blocks( ( width + thread - 1 ) / thread, ( height + thread - 1 ) / thread );

dim3 threads( thread, thread );

kernel<<<blocks, threads>>>( dev_data, width, height );

// kernel function

__global__ void kernel( uchar *data, int width, int height ) {

// map from threadIdx/blockIdx to pixel position

int x = threadIdx.x + blockIdx.x * blockDim.x;

int y = threadIdx.y + blockIdx.y * blockDim.y;

int offset = x + y * blockDim.x * gridDim.x;

data[offset * 3 + 0] = 255;

data[offset * 3 + 1] = 0;

data[offset * 3 + 2] = 0;
}

当我执行它时,只有近一半像素变蓝。我究竟做错了什么?我认为它是关于索引的。

0 个答案:

没有答案