Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用OpenCV UMat作为输入时参数的OpenCL参数化_C++_Opencv_Opencl - Fatal编程技术网

C++ 使用OpenCV UMat作为输入时参数的OpenCL参数化

C++ 使用OpenCV UMat作为输入时参数的OpenCL参数化,c++,opencv,opencl,C++,Opencv,Opencl,我一直在研究的源代码,以便更好地理解如何编写opencv代码 参数列表似乎包含9个参数: "__kernel void magnutude_filter_8u(\n" " __global const uchar* src, int src_step, int src_offset,\n" " __global uchar* dst, int dst_step, int dst_offset, int dst_rows, int dst_cols,\n" "

我一直在研究的源代码,以便更好地理解如何编写opencv代码

参数列表似乎包含9个参数:

"__kernel void magnutude_filter_8u(\n"
"       __global const uchar* src, int src_step, int src_offset,\n"
"       __global uchar* dst, int dst_step, int dst_offset, int dst_rows, int dst_cols,\n"
"       float scale)\n"
bool executionResult = k
     .args(
            cv::ocl::KernelArg::ReadOnlyNoSize(src), // size is not used (similar to 'dst' size)
            cv::ocl::KernelArg::WriteOnly(result),
            (float)2.0
        ) 
但它只有3个参数:

"__kernel void magnutude_filter_8u(\n"
"       __global const uchar* src, int src_step, int src_offset,\n"
"       __global uchar* dst, int dst_step, int dst_offset, int dst_rows, int dst_cols,\n"
"       float scale)\n"
bool executionResult = k
     .args(
            cv::ocl::KernelArg::ReadOnlyNoSize(src), // size is not used (similar to 'dst' size)
            cv::ocl::KernelArg::WriteOnly(result),
            (float)2.0
        ) 
这在其他代码中也会发生,例如canny和实现


我想知道UMat结构的特殊之处是什么,它允许这种情况发生。

如果您多浏览一下opencv代码,您会发现 函数返回一个kernelArg,它似乎是一个结构中的4个值,这3个值被内核“使用”,对于每个kernelArg,默认情况下分配2个值,在这种情况下,这些值与src_step、src_offset、dst_step和dst_offset匹配,另一方面,dst_行和dst_cols参数是从dst UMat size推导出来的(请再次参阅set()调用),这是OpenCL函数调用所需的所有参数

现在,args(…)为每个参数调用set(int-index,T-type),对于KernelArg,它应该是

set(int i, const KernelArg &arg);
这意味着它解压(使用)KernelArg结构的成员。 如果您想知道它们被分配到内核的位置,那么在多个

clSetKernelArg(..)

函数内部的调用

这仍然没有意义,因为ReadOnlyNoSize调用只匹配3个参数(u global const uchar*src,int src_step,int src_offset),WriteOnly调用匹配5个参数(u global uchar*dst,int dst_step,int dst_offset,int dst_rows,int dst cols)@zcaudate我已经扩展了我的答案。@zcaudate我想说你将在opencv api中进入低级,你不需要知道这一点,除非你想对opencv或其他东西有所贡献,你只需要知道什么时候在你的自定义内核中使用相应的步长值,在这种情况下,由于KernelArg的原因,它们默认为1。如果你需要您可以编写不同的步幅(Mat、stride、stride)等。KernelArg最多可重载16个值!(请参阅ocl.hpp)