没有插值内核的去隔行

时间:2016-01-19 00:17:30

标签: video graphics opencl gpgpu video-processing

我正在研究OpenCL内核以了解特定的实时反隔行扫描问题。我有帧(RGB,720 * 480 * 3),它们由 4个隔行扫描场组成。所以我想去隔行到维度的原始字段 G width / 4)*( height / 4),使用以下等式:

G_i = 1/4(f(x',y')+ f(x' + 1,y')+ f(x' + 2,y& #39;)+ f(x' + 3,y'))

其中 i = 0,1,2,3

(x',y')=(4x,4y + i)

结果字段 G_i 因此占据了帧的1/16,最终我计划分别使用逐行扫描字段。

这是我到目前为止所取得的成就,但我已经挣扎了很长一段时间,而且我并不在那里。有人可以帮忙吗?我想我需要一个4宽的步幅来穿过扁平的框架?

对OpenCL程序的调用(在PyOpenCL中):

# call limiting the global work space to 1/16th of the frame
# outputting to array of 1/16th the size
    self.program.deinterlace(self.queue, (self.dim[0]/self.n, self.dim[1]/self.n),
                             None,
                             self.frame_buf, self.dest_buf,
                             np.int32(self.dim[1]),
                             np.int32(self.dim[2]))
    result = np.empty((self.dim[0]/self.n, self.dim[1]/self.n, 3),
                      dtype=np.uint8)
    cl.enqueue_copy(self.queue, result, self.dest_buf).wait()

OpenCL内核:

__kernel void deinterlace(

        __global const uchar *a,
        __global uchar *c,
        const int width,
        const int channels
    )
    {
        int rowid = get_global_id(0);
        int colid = get_global_id(1);

        int ncols = width;
        int nchan = channels;

        int index = rowid * 4 * ncols * 4 * nchan + colid * 4 * nchan;
        int newindex = rowid * ncols * nchan + colid * nchan;
        c[newindex + 0] = a[index + 0];
        c[newindex + 1] = a[index + 1];
        c[newindex + 2] = a[index + 2];
    }

框架:

base frame

结果:

resulting field 0

1 个答案:

答案 0 :(得分:0)

是的,所以我忘了缩小迭代界限......

对OpenCL程序的调用应该是:

# call limiting the global work space to 1/16th of the frame
# outputting to array of 1/16th the size
    self.program.deinterlace(self.queue, (self.dim[0]/self.n, self.dim[1]/self.n),
                             None,
                             self.frame_buf, self.dest_buf,
                             np.int32(self.dim[1]/self.n),
                             np.int32(self.dim[2]))
    result = np.empty((self.dim[0]/self.n, self.dim[1]/self.n, 3),
                      dtype=np.uint8)
    cl.enqueue_copy(self.queue, result, self.dest_buf).wait()