如何正确使用CIWarpKernel坐标系?

时间:2015-12-24 14:30:08

标签: ios core-image

我正在尝试在ios中构建自定义warp内核。

我有这个内核代码

var kernelCode =
        " kernel vec2 partialFlip(vec2 center, float width, float height) {   " + "\n" +
        " vec2 p = destCoord();    " + "\n" +
        " float x = width - p.x;   " + "\n" +
        " float y = height - p.y;   " + "\n" +
        " return vec2(x, y); }  ";

        kernel = CIWarpKernel(string: kernelCode);

当用户点击图像时,我想垂直和水平翻转一个区域。借助于用户的敲击和恒定宽度来计算该区域。就在我点击图像时,整个图像变成单一颜色,我假设每个像素只从一个像素中获取它的新颜色,为了使用我调用的内核

 var width = radius;
 var height = radius;   
 var roi  = CGRectMake(center.X - width / 2,center.Y - height / 2, width, height);
    return kernel.applyWithExtent(roi, roiCallback: {(n : Int32, rect: CGRect) -> CGRect in return rect; }, inputImage: image, arguments: [center, width, height])!;

我的中心和半径来自图像坐标系。    我在这里错过了什么吗?我应该将所有内容缩小到[0,1]吗?

1 个答案:

答案 0 :(得分:1)

核心图像坐标位于非标准化像素中。 坐标是笛卡尔坐标(即原点位于左下方)