0
我的源代码是从与OpenCL的异构计算第4章基本OpenCL示例>图像旋转。这本书留下了几个关键细节。如何将图像坐标变平成一维数组?
我的主要问题是我不知道如何初始化我提供给他们的内核的数组(他们不会告诉你如何)。我所拥有的是:
int W = inImage.width();
int H = inImage.height();
float *myImage = new float[W*H];
for(int row = 0; row < H; row++)
for(int col = 0; col < W; col++)
myImage[row*W+col] = col;
我提供这个内核:
__kernel void img_rotate(__global float* dest_data, __global float* src_data, int W, int H, float sinTheta, float cosTheta)
{
const int ix = get_global_id(0);
const int iy = get_global_id(1);
float x0 = W/2.0f;
float y0 = H/2.0f;
float xoff = ix-x0;
float yoff = iy-y0;
int xpos = (int)(xoff*cosTheta + yoff*sinTheta + x0);
int ypos = (int)(yoff*cosTheta - xoff*sinTheta + y0);
if(((int)xpos>=0) && ((int)xpos < W) && ((int)ypos>=0) && ((int)ypos<H))
{
dest_data[iy*W+ix] = src_data[ypos*W+xpos];
//dest_data[iy*W+ix] = src_data[iy*W+ix];
}
}
我无法找到对THETA正确的价值了。一个整数对于theta是一个合适的值,对吗?
float theta = 45; // 45 degrees, right?
float cos_theta = cos(theta);
float sin_theta = sin(theta);
库'cos'和'sin'总是接受弧度 - 您应该将45度转换为弧度 – japreiss