本文整理汇总了C++中oclMat::elemSize方法的典型用法代码示例。如果您正苦于以下问题:C++ oclMat::elemSize方法的具体用法?C++ oclMat::elemSize怎么用?C++ oclMat::elemSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oclMat
的用法示例。
在下文中一共展示了oclMat::elemSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_to_withmask_run
static void set_to_withmask_run(const oclMat &dst, const Scalar &scalar, const oclMat &mask, String kernelName)
{
CV_DbgAssert( dst.rows == mask.rows && dst.cols == mask.cols);
std::vector<std::pair<size_t , const void *> > args;
size_t localThreads[3] = { 16, 16, 1 };
size_t globalThreads[3] = { dst.cols, dst.rows, 1 };
int step_in_pixel = dst.step / dst.elemSize(), offset_in_pixel = dst.offset / dst.elemSize();
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
const char channelMap[] = { ' ', ' ', '2', '4', '4' };
std::string buildOptions = format("-D GENTYPE=%s%c", typeMap[dst.depth()], channelMap[dst.channels()]);
oclMat m(Mat(1, 1, dst.type(), scalar));
args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&m.data ));
args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&dst.data ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&dst.cols ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&dst.rows ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&step_in_pixel ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&offset_in_pixel ));
args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&mask.data ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&mask.step ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&mask.offset ));
openCLExecuteKernel(dst.clCxt , &operator_setToM, kernelName, globalThreads,
localThreads, args, -1, -1, buildOptions.c_str());
}
示例2: set_to_withmask_run
void set_to_withmask_run(const oclMat &dst, const Scalar &scalar, const oclMat &mask, string kernelName)
{
CV_DbgAssert( dst.rows == mask.rows && dst.cols == mask.cols);
vector<pair<size_t , const void *> > args;
cl_float4 val;
val.s[0] = scalar.val[0];
val.s[1] = scalar.val[1];
val.s[2] = scalar.val[2];
val.s[3] = scalar.val[3];
size_t localThreads[3] = {16, 16, 1};
size_t globalThreads[3];
globalThreads[0] = (dst.cols + localThreads[0] - 1) / localThreads[0] * localThreads[0];
globalThreads[1] = (dst.rows + localThreads[1] - 1) / localThreads[1] * localThreads[1];
globalThreads[2] = 1;
if(dst.type() == CV_8UC1)
{
globalThreads[0] = ((dst.cols + 4) / 4 + localThreads[0] - 1) / localThreads[0] * localThreads[0];
}
int step_in_pixel = dst.step / dst.elemSize(), offset_in_pixel = dst.offset / dst.elemSize();
args.push_back( make_pair( sizeof(cl_float4) , (void *)&val ));
args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst.data ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&dst.cols ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&dst.rows ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&step_in_pixel ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&offset_in_pixel ));
args.push_back( make_pair( sizeof(cl_mem) , (void *)&mask.data ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&mask.step ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&mask.offset ));
openCLExecuteKernel(dst.clCxt , &operator_setToM, kernelName, globalThreads,
localThreads, args, dst.channels(), dst.depth());
}
示例3: convert_run_cus
///////////////////////////////////////////////////////////////////////////
//////////////////////////////// ConvertTo ////////////////////////////////
///////////////////////////////////////////////////////////////////////////
static void convert_run_cus(const oclMat &src, oclMat &dst, double alpha, double beta)
{
std::string kernelName = "convert_to_S";
std::stringstream idxStr;
idxStr << src.depth();
kernelName += idxStr.str();
float alpha_f = (float)alpha, beta_f = (float)beta;
CV_DbgAssert(src.rows == dst.rows && src.cols == dst.cols);
std::vector<std::pair<size_t , const void *> > args;
size_t localThreads[3] = {16, 16, 1};
size_t globalThreads[3];
globalThreads[0] = (dst.cols + localThreads[0] - 1) / localThreads[0] * localThreads[0];
globalThreads[1] = (dst.rows + localThreads[1] - 1) / localThreads[1] * localThreads[1];
globalThreads[2] = 1;
int dststep_in_pixel = dst.step / dst.elemSize(), dstoffset_in_pixel = dst.offset / dst.elemSize();
int srcstep_in_pixel = src.step / src.elemSize(), srcoffset_in_pixel = src.offset / src.elemSize();
if(dst.type() == CV_8UC1)
{
globalThreads[0] = ((dst.cols + 4) / 4 + localThreads[0]) / localThreads[0] * localThreads[0];
}
args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&src.data ));
args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&dst.data ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&src.cols ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&src.rows ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&srcstep_in_pixel ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&srcoffset_in_pixel ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&dststep_in_pixel ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&dstoffset_in_pixel ));
args.push_back( std::make_pair( sizeof(cl_float) , (void *)&alpha_f ));
args.push_back( std::make_pair( sizeof(cl_float) , (void *)&beta_f ));
openCLExecuteKernel2(dst.clCxt , &operator_convertTo, kernelName, globalThreads,
localThreads, args, dst.oclchannels(), dst.depth(), CLFLUSH);
}
示例4: sizeof
void ocl_tvl1flow::estimateU(oclMat &I1wx, oclMat &I1wy, oclMat &grad,
oclMat &rho_c, oclMat &p11, oclMat &p12,
oclMat &p21, oclMat &p22, oclMat &u1,
oclMat &u2, oclMat &error, float l_t, float theta, char calc_error)
{
Context* clCxt = I1wx.clCxt;
size_t localThread[] = {32, 8, 1};
size_t globalThread[] =
{
I1wx.cols,
I1wx.rows,
1
};
int I1wx_element_size = I1wx.elemSize();
int I1wx_step = I1wx.step/I1wx_element_size;
int u1_element_size = u1.elemSize();
int u1_step = u1.step/u1_element_size;
int u2_element_size = u2.elemSize();
int u2_step = u2.step/u2_element_size;
int u1_offset_y = u1.offset/u1.step;
int u1_offset_x = u1.offset%u1.step;
u1_offset_x = u1_offset_x/u1.elemSize();
int u2_offset_y = u2.offset/u2.step;
int u2_offset_x = u2.offset%u2.step;
u2_offset_x = u2_offset_x/u2.elemSize();
String kernelName = "estimateUKernel";
vector< pair<size_t, const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void*)&I1wx.data));
args.push_back( make_pair( sizeof(cl_int), (void*)&I1wx.cols));
args.push_back( make_pair( sizeof(cl_int), (void*)&I1wx.rows));
args.push_back( make_pair( sizeof(cl_int), (void*)&I1wx_step));
args.push_back( make_pair( sizeof(cl_mem), (void*)&I1wy.data));
args.push_back( make_pair( sizeof(cl_mem), (void*)&grad.data));
args.push_back( make_pair( sizeof(cl_mem), (void*)&rho_c.data));
args.push_back( make_pair( sizeof(cl_mem), (void*)&p11.data));
args.push_back( make_pair( sizeof(cl_mem), (void*)&p12.data));
args.push_back( make_pair( sizeof(cl_mem), (void*)&p21.data));
args.push_back( make_pair( sizeof(cl_mem), (void*)&p22.data));
args.push_back( make_pair( sizeof(cl_mem), (void*)&u1.data));
args.push_back( make_pair( sizeof(cl_int), (void*)&u1_step));
args.push_back( make_pair( sizeof(cl_mem), (void*)&u2.data));
args.push_back( make_pair( sizeof(cl_mem), (void*)&error.data));
args.push_back( make_pair( sizeof(cl_float), (void*)&l_t));
args.push_back( make_pair( sizeof(cl_float), (void*)&theta));
args.push_back( make_pair( sizeof(cl_int), (void*)&u2_step));
args.push_back( make_pair( sizeof(cl_int), (void*)&u1_offset_x));
args.push_back( make_pair( sizeof(cl_int), (void*)&u1_offset_y));
args.push_back( make_pair( sizeof(cl_int), (void*)&u2_offset_x));
args.push_back( make_pair( sizeof(cl_int), (void*)&u2_offset_y));
args.push_back( make_pair( sizeof(cl_char), (void*)&calc_error));
openCLExecuteKernel(clCxt, &tvl1flow, kernelName, globalThread, localThread, args, -1, -1);
}
示例5: bindTexture
static cl_mem bindTexture(const oclMat &mat, int depth, int channels)
{
cl_mem texture;
cl_image_format format;
int err;
if(depth == 0)
{
format.image_channel_data_type = CL_UNSIGNED_INT8;
}
else if(depth == 5)
{
format.image_channel_data_type = CL_FLOAT;
}
if(channels == 1)
{
format.image_channel_order = CL_R;
}
else if(channels == 3)
{
format.image_channel_order = CL_RGB;
}
else if(channels == 4)
{
format.image_channel_order = CL_RGBA;
}
#ifdef CL_VERSION_1_2
cl_image_desc desc;
desc.image_type = CL_MEM_OBJECT_IMAGE2D;
desc.image_width = mat.step / mat.elemSize();
desc.image_height = mat.rows;
desc.image_depth = NULL;
desc.image_array_size = 1;
desc.image_row_pitch = 0;
desc.image_slice_pitch = 0;
desc.buffer = NULL;
desc.num_mip_levels = 0;
desc.num_samples = 0;
texture = clCreateImage(mat.clCxt->impl->clContext, CL_MEM_READ_WRITE, &format, &desc, NULL, &err);
#else
texture = clCreateImage2D(
mat.clCxt->impl->clContext,
CL_MEM_READ_WRITE,
&format,
mat.step / mat.elemSize(),
mat.rows,
0,
NULL,
&err);
#endif
size_t origin[] = { 0, 0, 0 };
size_t region[] = { mat.step / mat.elemSize(), mat.rows, 1 };
clEnqueueCopyBufferToImage(mat.clCxt->impl->clCmdQueue, (cl_mem)mat.data, texture, 0, origin, region, 0, NULL, 0);
openCLSafeCall(err);
return texture;
}
示例6: set_to_withoutmask_run
static void set_to_withoutmask_run(const oclMat &dst, const Scalar &scalar, String kernelName)
{
std::vector<std::pair<size_t , const void *> > args;
size_t localThreads[3] = {16, 16, 1};
size_t globalThreads[3] = { dst.cols, dst.rows, 1 };
int step_in_pixel = dst.step / dst.elemSize(), offset_in_pixel = dst.offset / dst.elemSize();
if (dst.type() == CV_8UC1)
globalThreads[0] = ((dst.cols + 4) / 4 + localThreads[0] - 1) / localThreads[0] * localThreads[0];
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
const char channelMap[] = { ' ', ' ', '2', '4', '4' };
std::string buildOptions = format("-D GENTYPE=%s%c", typeMap[dst.depth()], channelMap[dst.channels()]);
Mat mat(1, 1, dst.type(), scalar);
#ifdef CL_VERSION_1_2
// this enables backwards portability to
// run on OpenCL 1.1 platform if library binaries are compiled with OpenCL 1.2 support
if (Context::getContext()->supportsFeature(Context::CL_VER_1_2) &&
dst.offset == 0 && dst.cols == dst.wholecols)
{
const int sizeofMap[][7] =
{
{ sizeof(cl_uchar) , sizeof(cl_char) , sizeof(cl_ushort) , sizeof(cl_short) , sizeof(cl_int) , sizeof(cl_float) , sizeof(cl_double) },
{ sizeof(cl_uchar2), sizeof(cl_char2), sizeof(cl_ushort2), sizeof(cl_short2), sizeof(cl_int2), sizeof(cl_float2), sizeof(cl_double2) },
{ 0 , 0 , 0 , 0 , 0 , 0 , 0 },
{ sizeof(cl_uchar4), sizeof(cl_char4), sizeof(cl_ushort4), sizeof(cl_short4), sizeof(cl_int4), sizeof(cl_float4), sizeof(cl_double4) },
};
int sizeofGeneric = sizeofMap[dst.oclchannels() - 1][dst.depth()];
clEnqueueFillBuffer((cl_command_queue)dst.clCxt->oclCommandQueue(),
(cl_mem)dst.data, (void*)mat.data, sizeofGeneric,
0, dst.step * dst.rows, 0, NULL, NULL);
}
else
#endif
{
oclMat m(mat);
args.push_back( std::make_pair( sizeof(cl_mem) , (void*)&m.data ));
args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&dst.data ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&dst.cols ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&dst.rows ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&step_in_pixel ));
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&offset_in_pixel ));
openCLExecuteKernel(dst.clCxt , &operator_setTo, kernelName, globalThreads,
localThreads, args, -1, -1, buildOptions.c_str());
}
}
示例7: matmul_poly
static void matmul_poly(oclMat & src, oclMat & src2, oclMat & dst, int src_rows, int src2_cols, int var_count, double alpha1, double beta1, double degree1, bool flag)
{
Context *clCxt = Context::getContext();
String kernelName = "svm_poly";
int src_step = (int)src.step / src.elemSize();
int src2_step = (int)src2.step / src2.elemSize();
int dst_step = (int)dst.step / dst.elemSize();
int x = MIN(16, src_rows);
int y = MIN(16, src2_cols);
size_t localThreads[] = {x, y, 1};
size_t globalThreads[] = {src2_cols, src_rows, 1};
int width = var_count;
char build_options[50];
if(flag)
{
sprintf(build_options, "-D ADDPOW");
}
std::vector< std::pair<size_t, const void *> > args;
args.push_back(std::make_pair(sizeof(cl_mem), (void* )&src.data));
args.push_back(std::make_pair(sizeof(cl_int), (void* )&src_step));
args.push_back(std::make_pair(sizeof(cl_mem), (void* )&src2.data));
args.push_back(std::make_pair(sizeof(cl_int), (void* )&src2_step));
args.push_back(std::make_pair(sizeof(cl_mem), (void* )&dst.data));
args.push_back(std::make_pair(sizeof(cl_int), (void* )&dst_step));
args.push_back(std::make_pair(sizeof(cl_int), (void* )&src_rows));
args.push_back(std::make_pair(sizeof(cl_int), (void* )&src2_cols));
args.push_back(std::make_pair(sizeof(cl_int), (void* )&width));
float alpha = 0.0f, beta = 0.0f, degree = 0.0f;
if(!Context::getContext()->supportsFeature(FEATURE_CL_DOUBLE))
{
alpha = (float)alpha1;
beta = (float)beta1;
degree = (float)degree1;
args.push_back(std::make_pair(sizeof(cl_float), (void* )&alpha));
args.push_back(std::make_pair(sizeof(cl_float), (void* )&beta));
args.push_back(std::make_pair(sizeof(cl_float), (void* )°ree));
}
else
{
args.push_back(std::make_pair(sizeof(cl_double), (void* )&alpha1));
args.push_back(std::make_pair(sizeof(cl_double), (void* )&beta1));
args.push_back(std::make_pair(sizeof(cl_double), (void* )°ree1));
}
openCLExecuteKernel(clCxt, &svm, kernelName, globalThreads, localThreads, args, -1, -1, build_options);
}
示例8: openCLExecuteKernel
void cv::ocl::distanceToCenters(oclMat &dists, oclMat &labels, const oclMat &src, const oclMat ¢ers)
{
//if(src.clCxt -> impl -> double_support == 0 && src.type() == CV_64F)
//{
// CV_Error(Error::OpenCLDoubleNotSupported, "Selected device doesn't support double");
// return;
//}
Context *clCxt = src.clCxt;
int labels_step = (int)(labels.step/labels.elemSize());
String kernelname = "distanceToCenters";
int threadNum = src.rows > 256 ? 256 : src.rows;
size_t localThreads[3] = {1, threadNum, 1};
size_t globalThreads[3] = {1, src.rows, 1};
std::vector<std::pair<size_t, const void *> > args;
args.push_back(std::make_pair(sizeof(cl_int), (void *)&labels_step));
args.push_back(std::make_pair(sizeof(cl_int), (void *)¢ers.rows));
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&labels.data));
args.push_back(std::make_pair(sizeof(cl_int), (void *)¢ers.cols));
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.rows));
args.push_back(std::make_pair(sizeof(cl_mem), (void *)¢ers.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&dists.data));
openCLExecuteKernel(clCxt, &kmeans_kernel, kernelname, globalThreads, localThreads, args, -1, -1, NULL);
}
示例9: copyTo
static void copyTo(const oclMat &src, oclMat &m )
{
CV_DbgAssert(!src.empty());
m.create(src.size(), src.type());
openCLCopyBuffer2D(src.clCxt, m.data, m.step, m.offset,
src.data, src.step, src.cols * src.elemSize(), src.rows, src.offset);
}
示例10: snprintf
void cv::ocl::device::mog::getBackgroundImage2_ocl(int cn, const oclMat& modesUsed, const oclMat& weight, const oclMat& mean, oclMat& dst, int nmixtures)
{
Context* clCxt = Context::getContext();
size_t local_thread[] = {32, 8, 1};
size_t global_thread[] = {modesUsed.cols, modesUsed.rows, 1};
int weight_step = (int)(weight.step/weight.elemSize());
int modesUsed_step = (int)(modesUsed.step/modesUsed.elemSize());
int mean_step = (int)(mean.step/mean.elemSize());
int dst_step = (int)(dst.step/dst.elemSize());
int dst_y = (int)(dst.offset/dst.step);
int dst_x = (int)(dst.offset%dst.step);
dst_x = dst_x/(int)dst.elemSize();
String kernel_name = "getBackgroundImage2_kernel";
std::vector<std::pair<size_t, const void*> > args;
char build_option[50];
if(cn == 1)
{
snprintf(build_option, 50, "-D CN1 -D NMIXTURES=%d", nmixtures);
}else
{
snprintf(build_option, 50, "-D NMIXTURES=%d", nmixtures);
}
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&modesUsed.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&weight.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&mean.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&dst.data));
args.push_back(std::make_pair(sizeof(cl_float), (void*)&c_TB));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&modesUsed.rows));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&modesUsed.cols));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&modesUsed_step));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&weight_step));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&mean_step));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&dst_step));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&dst_x));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&dst_y));
openCLExecuteKernel(clCxt, &bgfg_mog, kernel_name, global_thread, local_thread, args, -1, -1, build_option);
}
示例11: lkSparse_run
static void lkSparse_run(oclMat &I, oclMat &J,
const oclMat &prevPts, oclMat &nextPts, oclMat &status, oclMat& err, bool /*GET_MIN_EIGENVALS*/, int ptcount,
int level, /*dim3 block, */dim3 patch, Size winSize, int iters)
{
Context *clCxt = I.clCxt;
int elemCntPerRow = I.step / I.elemSize();
std::string kernelName = "lkSparse";
size_t localThreads[3] = { 8, 8, 1 };
size_t globalThreads[3] = { 8 * ptcount, 8, 1};
int cn = I.oclchannels();
char calcErr;
if (level == 0)
{
calcErr = 1;
}
else
{
calcErr = 0;
}
std::vector<std::pair<size_t , const void *> > args;
cl_mem ITex = bindTexture(I);
cl_mem JTex = bindTexture(J);
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&ITex ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&JTex ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&prevPts.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&prevPts.step ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&nextPts.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&nextPts.step ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&status.data ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&err.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&level ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&I.rows ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&I.cols ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&patch.x ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&patch.y ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&cn ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&winSize.width ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&winSize.height ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&iters ));
args.push_back( std::make_pair( sizeof(cl_char), (void *)&calcErr ));
try
{
openCLExecuteKernel2(clCxt, &pyrlk, kernelName, globalThreads, localThreads, args, I.oclchannels(), I.depth(), CLFLUSH);
}
catch(Exception&)
{
printf("Warning: The image2d_t is not supported by the device. Using alternative method!\n");
releaseTexture(ITex);
releaseTexture(JTex);
ITex = (cl_mem)I.data;
JTex = (cl_mem)J.data;
localThreads[1] = globalThreads[1] = 32;
args.insert( args.begin()+11, std::make_pair( sizeof(cl_int), (void *)&elemCntPerRow ) );
openCLExecuteKernel2(clCxt, &pyrlk_no_image, kernelName, globalThreads, localThreads, args, I.oclchannels(), I.depth(), CLFLUSH);
}
}
示例12: lkSparse_run
static void lkSparse_run(oclMat &I, oclMat &J,
const oclMat &prevPts, oclMat &nextPts, oclMat &status, oclMat& err, bool /*GET_MIN_EIGENVALS*/, int ptcount,
int level, /*dim3 block, */dim3 patch, Size winSize, int iters)
{
Context *clCxt = I.clCxt;
int elemCntPerRow = I.step / I.elemSize();
String kernelName = "lkSparse";
bool isImageSupported = support_image2d();
size_t localThreads[3] = { 8, isImageSupported ? 8 : 32, 1 };
size_t globalThreads[3] = { 8 * ptcount, isImageSupported ? 8 : 32, 1};
int cn = I.oclchannels();
char calcErr;
if (level == 0)
{
calcErr = 1;
}
else
{
calcErr = 0;
}
std::vector<std::pair<size_t , const void *> > args;
cl_mem ITex = isImageSupported ? bindTexture(I) : (cl_mem)I.data;
cl_mem JTex = isImageSupported ? bindTexture(J) : (cl_mem)J.data;
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&ITex ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&JTex ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&prevPts.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&prevPts.step ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&nextPts.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&nextPts.step ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&status.data ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&err.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&level ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&I.rows ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&I.cols ));
if (!isImageSupported)
args.push_back( std::make_pair( sizeof(cl_int), (void *)&elemCntPerRow ) );
args.push_back( std::make_pair( sizeof(cl_int), (void *)&patch.x ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&patch.y ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&cn ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&winSize.width ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&winSize.height ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&iters ));
args.push_back( std::make_pair( sizeof(cl_char), (void *)&calcErr ));
if(isImageSupported)
{
openCLExecuteKernel2(clCxt, &pyrlk, kernelName, globalThreads, localThreads, args, I.oclchannels(), I.depth(), CLFLUSH);
releaseTexture(ITex);
releaseTexture(JTex);
}
else
{
openCLExecuteKernel2(clCxt, &pyrlk_no_image, kernelName, globalThreads, localThreads, args, I.oclchannels(), I.depth(), CLFLUSH);
}
}
示例13: mog_withoutLearning
static void mog_withoutLearning(const oclMat& frame, int cn, oclMat& fgmask, oclMat& weight, oclMat& mean, oclMat& var,
int nmixtures, float varThreshold, float backgroundRatio)
{
Context* clCxt = Context::getContext();
size_t local_thread[] = {32, 8, 1};
size_t global_thread[] = {frame.cols, frame.rows, 1};
int frame_step = (int)(frame.step/frame.elemSize());
int fgmask_step = (int)(fgmask.step/fgmask.elemSize());
int weight_step = (int)(weight.step/weight.elemSize());
int mean_step = (int)(mean.step/mean.elemSize());
int var_step = (int)(var.step/var.elemSize());
int fgmask_offset_y = (int)(fgmask.offset/fgmask.step);
int fgmask_offset_x = (int)(fgmask.offset%fgmask.step);
fgmask_offset_x = fgmask_offset_x/(int)fgmask.elemSize();
int frame_offset_y = (int)(frame.offset/frame.step);
int frame_offset_x = (int)(frame.offset%frame.step);
frame_offset_x = frame_offset_x/(int)frame.elemSize();
char build_option[50];
if(cn == 1)
{
snprintf(build_option, 50, "-D CN1 -D NMIXTURES=%d", nmixtures);
}else
{
snprintf(build_option, 50, "-D NMIXTURES=%d", nmixtures);
}
String kernel_name = "mog_withoutLearning_kernel";
std::vector<std::pair<size_t, const void*> > args;
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&frame.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&fgmask.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&weight.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&mean.data));
args.push_back(std::make_pair(sizeof(cl_mem), (void*)&var.data));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&frame.rows));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&frame.cols));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&frame_step));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&fgmask_step));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&weight_step));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&mean_step));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&var_step));
args.push_back(std::make_pair(sizeof(cl_float), (void*)&varThreshold));
args.push_back(std::make_pair(sizeof(cl_float), (void*)&backgroundRatio));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&fgmask_offset_x));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&fgmask_offset_y));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&frame_offset_x));
args.push_back(std::make_pair(sizeof(cl_int), (void*)&frame_offset_y));
openCLExecuteKernel(clCxt, &bgfg_mog, kernel_name, global_thread, local_thread, args, -1, -1, build_option);
}
示例14: lkSparse_run
static void lkSparse_run(oclMat &I, oclMat &J,
const oclMat &prevPts, oclMat &nextPts, oclMat &status, oclMat& err, bool /*GET_MIN_EIGENVALS*/, int ptcount,
int level, /*dim3 block, */dim3 patch, Size winSize, int iters)
{
Context *clCxt = I.clCxt;
int elemCntPerRow = I.step / I.elemSize();
String kernelName = "lkSparse";
bool isImageSupported = support_image2d();
size_t localThreads[3] = { 8, isImageSupported ? 8 : 32, 1 };
size_t globalThreads[3] = { 8 * ptcount, isImageSupported ? 8 : 32, 1};
int cn = I.oclchannels();
char calcErr = level==0?1:0;
std::vector<std::pair<size_t , const void *> > args;
cl_mem ITex = isImageSupported ? bindTexture(I) : (cl_mem)I.data;
cl_mem JTex = isImageSupported ? bindTexture(J) : (cl_mem)J.data;
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&ITex ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&JTex ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&prevPts.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&prevPts.step ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&nextPts.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&nextPts.step ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&status.data ));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&err.data ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&level ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&I.rows ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&I.cols ));
if (!isImageSupported)
args.push_back( std::make_pair( sizeof(cl_int), (void *)&elemCntPerRow ) );
args.push_back( std::make_pair( sizeof(cl_int), (void *)&patch.x ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&patch.y ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&cn ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&winSize.width ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&winSize.height ));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&iters ));
args.push_back( std::make_pair( sizeof(cl_char), (void *)&calcErr ));
if(isImageSupported)
{
std::stringstream idxStr;
idxStr << kernelName.c_str() << "_C" << I.oclchannels() << "_D" << I.depth();
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &pyrlk, idxStr.str().c_str());
int wave_size = (int)queryWaveFrontSize(kernel);
openCLSafeCall(clReleaseKernel(kernel));
static char opt[32] = {0};
sprintf(opt, " -D WAVE_SIZE=%d", wave_size);
openCLExecuteKernel2(clCxt, &pyrlk, kernelName, globalThreads, localThreads, args, I.oclchannels(), I.depth(), opt, CLFLUSH);
releaseTexture(ITex);
releaseTexture(JTex);
}
else
openCLExecuteKernel2(clCxt, &pyrlk_no_image, kernelName, globalThreads, localThreads, args, I.oclchannels(), I.depth(), CLFLUSH);
}
示例15: KRT_mat
void cv::ocl::buildWarpPlaneMaps(Size /*src_size*/, Rect dst_roi, const Mat &K, const Mat &R, const Mat &T,
float scale, oclMat &xmap, oclMat &ymap)
{
CV_Assert(K.size() == Size(3, 3) && K.type() == CV_32F);
CV_Assert(R.size() == Size(3, 3) && R.type() == CV_32F);
CV_Assert((T.size() == Size(3, 1) || T.size() == Size(1, 3)) && T.type() == CV_32F && T.isContinuous());
Mat K_Rinv = K * R.t();
CV_Assert(K_Rinv.isContinuous());
Mat KRT_mat(1, 12, CV_32FC1); // 9 + 3
KRT_mat(Range::all(), Range(0, 8)) = K_Rinv.reshape(1, 1);
KRT_mat(Range::all(), Range(9, 11)) = T;
oclMat KRT_oclMat(KRT_mat);
// transfer K_Rinv and T into a single cl_mem
xmap.create(dst_roi.size(), CV_32F);
ymap.create(dst_roi.size(), CV_32F);
int tl_u = dst_roi.tl().x;
int tl_v = dst_roi.tl().y;
int xmap_step = xmap.step / xmap.elemSize(), xmap_offset = xmap.offset / xmap.elemSize();
int ymap_step = ymap.step / ymap.elemSize(), ymap_offset = ymap.offset / ymap.elemSize();
std::vector< std::pair<size_t, const void *> > args;
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&xmap.data));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&ymap.data));
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&KRT_mat.data));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&tl_u));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&tl_v));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&xmap.cols));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&xmap.rows));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&xmap_step));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&ymap_step));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&xmap_offset));
args.push_back( std::make_pair( sizeof(cl_int), (void *)&ymap_offset));
args.push_back( std::make_pair( sizeof(cl_float), (void *)&scale));
size_t globalThreads[3] = { xmap.cols, xmap.rows, 1 };
size_t localThreads[3] = { 32, 8, 1 };
openCLExecuteKernel(Context::getContext(), &build_warps, "buildWarpPlaneMaps", globalThreads, localThreads, args, -1, -1);
}