1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
18 // Peng Xiao, pengxiao@multicorewareinc.com
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
23 // * Redistribution's of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
26 // * Redistribution's in binary form must reproduce the above copyright notice,
27 // this list of conditions and the following disclaimer in the documentation
28 // and/or other oclMaterials provided with the distribution.
30 // * The name of the copyright holders may not be used to endorse or promote products
31 // derived from this software without specific prior written permission.
33 // This software is provided by the copyright holders and contributors as is and
34 // any express or implied warranties, including, but not limited to, the implied
35 // warranties of merchantability and fitness for a particular purpose are disclaimed.
36 // In no event shall the Intel Corporation or contributors be liable for any direct,
37 // indirect, incidental, special, exemplary, or consequential damages
38 // (including, but not limited to, procurement of substitute goods or services;
39 // loss of use, data, or profits; or business interruption) however caused
40 // and on any theory of liability, whether in contract, strict liability,
41 // or tort (including negligence or otherwise) arising in any way out of
42 // the use of this software, even if advised of the possibility of such damage.
47 #include "precomp.hpp"
48 #include "opencl_kernels.hpp"
51 using namespace cv::ocl;
57 void matchTemplate_SQDIFF(
58 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf);
60 void matchTemplate_SQDIFF_NORMED(
61 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf);
64 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf);
66 void matchTemplate_CCORR(
67 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf);
69 void matchTemplate_CCORR_NORMED(
70 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf);
72 void matchTemplate_CCOFF(
73 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf);
75 void matchTemplate_CCOFF_NORMED(
76 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf);
79 void matchTemplateNaive_SQDIFF(
80 const oclMat &image, const oclMat &templ, oclMat &result, int cn);
82 void matchTemplateNaive_CCORR(
83 const oclMat &image, const oclMat &templ, oclMat &result, int cn);
85 void extractFirstChannel_32F(
86 const oclMat &image, oclMat &result);
88 // Evaluates optimal template's area threshold. If
89 // template's area is less than the threshold, we use naive match
90 // template version, otherwise FFT-based (if available)
91 static bool useNaive(int , int , Size )
94 // always use naive until convolve is imported
98 //////////////////////////////////////////////////////////////////////
100 void matchTemplate_SQDIFF(
101 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf & buf)
103 result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F);
104 if (useNaive(CV_TM_SQDIFF, image.depth(), templ.size()))
106 matchTemplateNaive_SQDIFF(image, templ, result, image.oclchannels());
111 buf.image_sqsums.resize(1);
113 // TODO, add double support for ocl::integral
114 // use CPU integral temporarily
116 cv::integral(Mat(image.reshape(1)), sums, sqsums);
117 buf.image_sqsums[0] = sqsums;
119 unsigned long long templ_sqsum = (unsigned long long)sqrSum(templ.reshape(1))[0];
120 matchTemplate_CCORR(image, templ, result, buf);
122 //port CUDA's matchTemplatePrepared_SQDIFF_8U
123 Context *clCxt = image.clCxt;
124 string kernelName = "matchTemplate_Prepared_SQDIFF";
125 vector< pair<size_t, const void *> > args;
127 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sqsums[0].data));
128 args.push_back( make_pair( sizeof(cl_mem), (void *)&result.data));
129 args.push_back( make_pair( sizeof(cl_ulong), (void *)&templ_sqsum));
130 args.push_back( make_pair( sizeof(cl_int), (void *)&result.rows));
131 args.push_back( make_pair( sizeof(cl_int), (void *)&result.cols));
132 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.rows));
133 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.cols));
134 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sqsums[0].offset));
135 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sqsums[0].step));
136 args.push_back( make_pair( sizeof(cl_int), (void *)&result.offset));
137 args.push_back( make_pair( sizeof(cl_int), (void *)&result.step));
139 size_t globalThreads[3] = {result.cols, result.rows, 1};
140 size_t localThreads[3] = {16, 16, 1};
142 const char * build_opt = image.oclchannels() == 4 ? "-D CN4" : "";
143 openCLExecuteKernel(clCxt, &match_template, kernelName, globalThreads, localThreads, args, 1, CV_8U, build_opt);
147 void matchTemplate_SQDIFF_NORMED(
148 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf)
150 matchTemplate_CCORR(image, templ, result, buf);
151 buf.image_sums.resize(1);
153 integral(image.reshape(1), buf.image_sums[0]);
155 unsigned long long templ_sqsum = (unsigned long long)sqrSum(templ.reshape(1))[0];
157 Context *clCxt = image.clCxt;
158 string kernelName = "matchTemplate_Prepared_SQDIFF_NORMED";
159 vector< pair<size_t, const void *> > args;
161 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[0].data));
162 args.push_back( make_pair( sizeof(cl_mem), (void *)&result.data));
163 args.push_back( make_pair( sizeof(cl_ulong), (void *)&templ_sqsum));
164 args.push_back( make_pair( sizeof(cl_int), (void *)&result.rows));
165 args.push_back( make_pair( sizeof(cl_int), (void *)&result.cols));
166 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.rows));
167 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.cols));
168 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].offset));
169 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].step));
170 args.push_back( make_pair( sizeof(cl_int), (void *)&result.offset));
171 args.push_back( make_pair( sizeof(cl_int), (void *)&result.step));
173 size_t globalThreads[3] = {result.cols, result.rows, 1};
174 size_t localThreads[3] = {16, 16, 1};
175 openCLExecuteKernel(clCxt, &match_template, kernelName, globalThreads, localThreads, args, 1, CV_8U);
178 void matchTemplateNaive_SQDIFF(
179 const oclMat &image, const oclMat &templ, oclMat &result, int)
181 CV_Assert((image.depth() == CV_8U && templ.depth() == CV_8U )
182 || ((image.depth() == CV_32F && templ.depth() == CV_32F) && result.depth() == CV_32F)
184 CV_Assert(image.oclchannels() == templ.oclchannels() && (image.oclchannels() == 1 || image.oclchannels() == 4) && result.oclchannels() == 1);
185 CV_Assert(result.rows == image.rows - templ.rows + 1 && result.cols == image.cols - templ.cols + 1);
187 Context *clCxt = image.clCxt;
188 string kernelName = "matchTemplate_Naive_SQDIFF";
190 vector< pair<size_t, const void *> > args;
192 args.push_back( make_pair( sizeof(cl_mem), (void *)&image.data));
193 args.push_back( make_pair( sizeof(cl_mem), (void *)&templ.data));
194 args.push_back( make_pair( sizeof(cl_mem), (void *)&result.data));
195 args.push_back( make_pair( sizeof(cl_int), (void *)&image.rows));
196 args.push_back( make_pair( sizeof(cl_int), (void *)&image.cols));
197 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.rows));
198 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.cols));
199 args.push_back( make_pair( sizeof(cl_int), (void *)&result.rows));
200 args.push_back( make_pair( sizeof(cl_int), (void *)&result.cols));
201 args.push_back( make_pair( sizeof(cl_int), (void *)&image.offset));
202 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.offset));
203 args.push_back( make_pair( sizeof(cl_int), (void *)&result.offset));
204 args.push_back( make_pair( sizeof(cl_int), (void *)&image.step));
205 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.step));
206 args.push_back( make_pair( sizeof(cl_int), (void *)&result.step));
208 size_t globalThreads[3] = {result.cols, result.rows, 1};
209 size_t localThreads[3] = {16, 16, 1};
210 openCLExecuteKernel(clCxt, &match_template, kernelName, globalThreads, localThreads, args, image.oclchannels(), image.depth());
213 //////////////////////////////////////////////////////////////////////
216 const oclMat &, const oclMat &, oclMat &, MatchTemplateBuf &)
218 CV_Error(-1, "convolve is not fully implemented yet");
221 void matchTemplate_CCORR(
222 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf)
224 result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F);
225 if (useNaive(CV_TM_CCORR, image.depth(), templ.size()))
227 matchTemplateNaive_CCORR(image, templ, result, image.oclchannels());
232 if(image.depth() == CV_8U && templ.depth() == CV_8U)
234 image.convertTo(buf.imagef, CV_32F);
235 templ.convertTo(buf.templf, CV_32F);
236 convolve_32F(buf.imagef, buf.templf, result, buf);
240 convolve_32F(image, templ, result, buf);
245 void matchTemplate_CCORR_NORMED(
246 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf)
248 matchTemplate_CCORR(image, templ, result, buf);
249 buf.image_sums.resize(1);
250 buf.image_sqsums.resize(1);
252 integral(image.reshape(1), buf.image_sums[0], buf.image_sqsums[0]);
254 unsigned long long templ_sqsum = (unsigned long long)sqrSum(templ.reshape(1))[0];
256 Context *clCxt = image.clCxt;
257 string kernelName = "normalizeKernel";
258 vector< pair<size_t, const void *> > args;
260 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sqsums[0].data));
261 args.push_back( make_pair( sizeof(cl_mem), (void *)&result.data));
262 args.push_back( make_pair( sizeof(cl_ulong), (void *)&templ_sqsum));
263 args.push_back( make_pair( sizeof(cl_int), (void *)&result.rows));
264 args.push_back( make_pair( sizeof(cl_int), (void *)&result.cols));
265 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.rows));
266 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.cols));
267 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sqsums[0].offset));
268 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sqsums[0].step));
269 args.push_back( make_pair( sizeof(cl_int), (void *)&result.offset));
270 args.push_back( make_pair( sizeof(cl_int), (void *)&result.step));
272 size_t globalThreads[3] = {result.cols, result.rows, 1};
273 size_t localThreads[3] = {16, 16, 1};
274 openCLExecuteKernel(clCxt, &match_template, kernelName, globalThreads, localThreads, args, 1, CV_8U);
277 void matchTemplateNaive_CCORR(
278 const oclMat &image, const oclMat &templ, oclMat &result, int)
280 CV_Assert((image.depth() == CV_8U && templ.depth() == CV_8U )
281 || ((image.depth() == CV_32F && templ.depth() == CV_32F) && result.depth() == CV_32F)
283 CV_Assert(image.oclchannels() == templ.oclchannels() && (image.oclchannels() == 1 || image.oclchannels() == 4) && result.oclchannels() == 1);
284 CV_Assert(result.rows == image.rows - templ.rows + 1 && result.cols == image.cols - templ.cols + 1);
286 Context *clCxt = image.clCxt;
287 string kernelName = "matchTemplate_Naive_CCORR";
289 vector< pair<size_t, const void *> > args;
291 args.push_back( make_pair( sizeof(cl_mem), (void *)&image.data));
292 args.push_back( make_pair( sizeof(cl_mem), (void *)&templ.data));
293 args.push_back( make_pair( sizeof(cl_mem), (void *)&result.data));
294 args.push_back( make_pair( sizeof(cl_int), (void *)&image.rows));
295 args.push_back( make_pair( sizeof(cl_int), (void *)&image.cols));
296 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.rows));
297 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.cols));
298 args.push_back( make_pair( sizeof(cl_int), (void *)&result.rows));
299 args.push_back( make_pair( sizeof(cl_int), (void *)&result.cols));
300 args.push_back( make_pair( sizeof(cl_int), (void *)&image.offset));
301 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.offset));
302 args.push_back( make_pair( sizeof(cl_int), (void *)&result.offset));
303 args.push_back( make_pair( sizeof(cl_int), (void *)&image.step));
304 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.step));
305 args.push_back( make_pair( sizeof(cl_int), (void *)&result.step));
307 size_t globalThreads[3] = {result.cols, result.rows, 1};
308 size_t localThreads[3] = {16, 16, 1};
309 openCLExecuteKernel(clCxt, &match_template, kernelName, globalThreads, localThreads, args, image.oclchannels(), image.depth());
311 //////////////////////////////////////////////////////////////////////
313 void matchTemplate_CCOFF(
314 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf)
316 CV_Assert(image.depth() == CV_8U && templ.depth() == CV_8U);
318 matchTemplate_CCORR(image, templ, result, buf);
320 Context *clCxt = image.clCxt;
323 kernelName = "matchTemplate_Prepared_CCOFF";
324 size_t globalThreads[3] = {result.cols, result.rows, 1};
325 size_t localThreads[3] = {16, 16, 1};
327 vector< pair<size_t, const void *> > args;
328 args.push_back( make_pair( sizeof(cl_mem), (void *)&result.data) );
329 args.push_back( make_pair( sizeof(cl_int), (void *)&image.rows) );
330 args.push_back( make_pair( sizeof(cl_int), (void *)&image.cols) );
331 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.rows) );
332 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.cols) );
333 args.push_back( make_pair( sizeof(cl_int), (void *)&result.rows) );
334 args.push_back( make_pair( sizeof(cl_int), (void *)&result.cols) );
335 args.push_back( make_pair( sizeof(cl_int), (void *)&result.offset));
336 args.push_back( make_pair( sizeof(cl_int), (void *)&result.step));
337 Vec4f templ_sum = Vec4f::all(0);
338 // to be continued in the following section
339 if(image.oclchannels() == 1)
341 buf.image_sums.resize(1);
342 integral(image, buf.image_sums[0]);
344 templ_sum[0] = (float)sum(templ)[0] / templ.size().area();
345 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[0].data) );
346 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].offset) );
347 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].step) );
348 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[0]) );
353 split(image, buf.images);
354 templ_sum = sum(templ) / templ.size().area();
355 buf.image_sums.resize(buf.images.size());
358 for(int i = 0; i < image.oclchannels(); i ++)
360 integral(buf.images[i], buf.image_sums[i]);
362 switch(image.oclchannels())
365 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[0].data) );
366 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[1].data) );
367 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[2].data) );
368 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[3].data) );
369 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].offset) );
370 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].step) );
371 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[0]) );
372 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[1]) );
373 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[2]) );
374 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[3]) );
377 CV_Error(CV_StsBadArg, "matchTemplate: unsupported number of channels");
381 openCLExecuteKernel(clCxt, &match_template, kernelName, globalThreads, localThreads, args, image.oclchannels(), image.depth());
384 void matchTemplate_CCOFF_NORMED(
385 const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf)
387 image.convertTo(buf.imagef, CV_32F);
388 templ.convertTo(buf.templf, CV_32F);
390 matchTemplate_CCORR(buf.imagef, buf.templf, result, buf);
391 float scale = 1.f / templ.size().area();
393 Context *clCxt = image.clCxt;
396 kernelName = "matchTemplate_Prepared_CCOFF_NORMED";
397 size_t globalThreads[3] = {result.cols, result.rows, 1};
398 size_t localThreads[3] = {16, 16, 1};
400 vector< pair<size_t, const void *> > args;
401 args.push_back( make_pair( sizeof(cl_mem), (void *)&result.data) );
402 args.push_back( make_pair( sizeof(cl_int), (void *)&image.rows) );
403 args.push_back( make_pair( sizeof(cl_int), (void *)&image.cols) );
404 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.rows) );
405 args.push_back( make_pair( sizeof(cl_int), (void *)&templ.cols) );
406 args.push_back( make_pair( sizeof(cl_int), (void *)&result.rows) );
407 args.push_back( make_pair( sizeof(cl_int), (void *)&result.cols) );
408 args.push_back( make_pair( sizeof(cl_int), (void *)&result.offset));
409 args.push_back( make_pair( sizeof(cl_int), (void *)&result.step));
410 args.push_back( make_pair( sizeof(cl_float), (void *)&scale) );
412 Vec4f templ_sum = Vec4f::all(0);
413 Vec4f templ_sqsum = Vec4f::all(0);
414 // to be continued in the following section
415 if(image.oclchannels() == 1)
417 buf.image_sums.resize(1);
418 buf.image_sqsums.resize(1);
419 integral(image, buf.image_sums[0], buf.image_sqsums[0]);
421 templ_sum[0] = (float)sum(templ)[0];
423 templ_sqsum[0] = sqrSum(templ)[0];
425 templ_sqsum[0] -= scale * templ_sum[0] * templ_sum[0];
426 templ_sum[0] *= scale;
428 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[0].data) );
429 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].offset) );
430 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].step) );
431 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sqsums[0].data) );
432 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sqsums[0].offset) );
433 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sqsums[0].step) );
434 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[0]) );
435 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sqsum[0]) );
440 split(image, buf.images);
441 templ_sum = sum(templ);
443 templ_sqsum = sqrSum(templ);
445 templ_sqsum -= scale * templ_sum * templ_sum;
447 float templ_sqsum_sum = 0;
448 for(int i = 0; i < image.oclchannels(); i ++)
450 templ_sqsum_sum += templ_sqsum[i] - scale * templ_sum[i] * templ_sum[i];
453 buf.image_sums.resize(buf.images.size());
454 buf.image_sqsums.resize(buf.images.size());
456 for(int i = 0; i < image.oclchannels(); i ++)
458 integral(buf.images[i], buf.image_sums[i], buf.image_sqsums[i]);
461 switch(image.oclchannels())
464 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[0].data) );
465 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[1].data) );
466 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[2].data) );
467 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sums[3].data) );
468 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].offset) );
469 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sums[0].step) );
470 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sqsums[0].data) );
471 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sqsums[1].data) );
472 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sqsums[2].data) );
473 args.push_back( make_pair( sizeof(cl_mem), (void *)&buf.image_sqsums[3].data) );
474 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sqsums[0].offset) );
475 args.push_back( make_pair( sizeof(cl_int), (void *)&buf.image_sqsums[0].step) );
476 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[0]) );
477 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[1]) );
478 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[2]) );
479 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sum[3]) );
480 args.push_back( make_pair( sizeof(cl_float), (void *)&templ_sqsum_sum) );
483 CV_Error(CV_StsBadArg, "matchTemplate: unsupported number of channels");
487 openCLExecuteKernel(clCxt, &match_template, kernelName, globalThreads, localThreads, args, image.oclchannels(), image.depth());
489 void extractFirstChannel_32F(const oclMat &image, oclMat &result)
491 Context *clCxt = image.clCxt;
494 kernelName = "extractFirstChannel";
495 size_t globalThreads[3] = {result.cols, result.rows, 1};
496 size_t localThreads[3] = {16, 16, 1};
498 vector< pair<size_t, const void *> > args;
499 args.push_back( make_pair( sizeof(cl_mem), (void *)&image.data) );
500 args.push_back( make_pair( sizeof(cl_mem), (void *)&result.data) );
501 args.push_back( make_pair( sizeof(cl_int), (void *)&result.rows) );
502 args.push_back( make_pair( sizeof(cl_int), (void *)&result.cols) );
503 args.push_back( make_pair( sizeof(cl_int), (void *)&image.offset));
504 args.push_back( make_pair( sizeof(cl_int), (void *)&result.offset));
505 args.push_back( make_pair( sizeof(cl_int), (void *)&image.step));
506 args.push_back( make_pair( sizeof(cl_int), (void *)&result.step));
508 openCLExecuteKernel(clCxt, &match_template, kernelName, globalThreads, localThreads, args, -1, -1);
513 void cv::ocl::matchTemplate(const oclMat &image, const oclMat &templ, oclMat &result, int method)
515 MatchTemplateBuf buf;
516 matchTemplate(image, templ, result, method, buf);
518 void cv::ocl::matchTemplate(const oclMat &image, const oclMat &templ, oclMat &result, int method, MatchTemplateBuf &buf)
520 CV_Assert(image.type() == templ.type());
521 CV_Assert(image.cols >= templ.cols && image.rows >= templ.rows);
523 typedef void (*Caller)(const oclMat &, const oclMat &, oclMat &, MatchTemplateBuf &);
525 const Caller callers[] =
527 ::matchTemplate_SQDIFF, ::matchTemplate_SQDIFF_NORMED,
528 ::matchTemplate_CCORR, ::matchTemplate_CCORR_NORMED,
529 ::matchTemplate_CCOFF, ::matchTemplate_CCOFF_NORMED
532 Caller caller = callers[method];
534 caller(image, templ, result, buf);