1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Third party copyrights are property of their respective owners.
17 //
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
20 //
21 // * Redistribution's of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
23 //
24 // * Redistribution's in binary form must reproduce the above copyright notice,
25 // this list of conditions and the following disclaimer in the documentation
26 // and/or other materials provided with the distribution.
27 //
28 // * The name of the copyright holders may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
30 //
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
41 //
42 //M*/
43
44 #pragma once
45
46 #ifndef OPENCV_CUDEV_GRID_SPLIT_MERGE_HPP
47 #define OPENCV_CUDEV_GRID_SPLIT_MERGE_HPP
48
49 #include "../common.hpp"
50 #include "../util/tuple.hpp"
51 #include "../util/vec_traits.hpp"
52 #include "../ptr2d/traits.hpp"
53 #include "../ptr2d/gpumat.hpp"
54 #include "../ptr2d/glob.hpp"
55 #include "../ptr2d/mask.hpp"
56 #include "detail/split_merge.hpp"
57
58 namespace cv { namespace cudev {
59
60 //! @addtogroup cudev
61 //! @{
62
63 template <class Policy, class SrcPtrTuple, typename DstType, class MaskPtr>
gridMerge_(const SrcPtrTuple & src,GpuMat_<DstType> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())64 __host__ void gridMerge_(const SrcPtrTuple& src, GpuMat_<DstType>& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
65 {
66 CV_StaticAssert( VecTraits<DstType>::cn == tuple_size<SrcPtrTuple>::value, "" );
67
68 const int rows = getRows(src);
69 const int cols = getCols(src);
70
71 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
72
73 dst.create(rows, cols);
74
75 grid_split_merge_detail::MergeImpl<VecTraits<DstType>::cn, Policy>::merge(shrinkPtr(src),
76 shrinkPtr(dst),
77 shrinkPtr(mask),
78 rows, cols,
79 StreamAccessor::getStream(stream));
80 }
81
82 template <class Policy, class SrcPtrTuple, typename DstType, class MaskPtr>
gridMerge_(const SrcPtrTuple & src,const GlobPtrSz<DstType> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())83 __host__ void gridMerge_(const SrcPtrTuple& src, const GlobPtrSz<DstType>& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
84 {
85 CV_StaticAssert( VecTraits<DstType>::cn == tuple_size<SrcPtrTuple>::value, "" );
86
87 const int rows = getRows(src);
88 const int cols = getCols(src);
89
90 CV_Assert( getRows(dst) == rows && getCols(dst) == cols );
91 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
92
93 grid_split_merge_detail::MergeImpl<VecTraits<DstType>::cn, Policy>::merge(shrinkPtr(src),
94 shrinkPtr(dst),
95 shrinkPtr(mask),
96 rows, cols,
97 StreamAccessor::getStream(stream));
98 }
99
100 template <class Policy, class SrcPtrTuple, typename DstType>
gridMerge_(const SrcPtrTuple & src,GpuMat_<DstType> & dst,Stream & stream=Stream::Null ())101 __host__ void gridMerge_(const SrcPtrTuple& src, GpuMat_<DstType>& dst, Stream& stream = Stream::Null())
102 {
103 CV_StaticAssert( VecTraits<DstType>::cn == tuple_size<SrcPtrTuple>::value, "" );
104
105 const int rows = getRows(src);
106 const int cols = getCols(src);
107
108 dst.create(rows, cols);
109
110 grid_split_merge_detail::MergeImpl<VecTraits<DstType>::cn, Policy>::merge(shrinkPtr(src),
111 shrinkPtr(dst),
112 WithOutMask(),
113 rows, cols,
114 StreamAccessor::getStream(stream));
115 }
116
117 template <class Policy, class SrcPtrTuple, typename DstType>
gridMerge_(const SrcPtrTuple & src,const GlobPtrSz<DstType> & dst,Stream & stream=Stream::Null ())118 __host__ void gridMerge_(const SrcPtrTuple& src, const GlobPtrSz<DstType>& dst, Stream& stream = Stream::Null())
119 {
120 CV_StaticAssert( VecTraits<DstType>::cn == tuple_size<SrcPtrTuple>::value, "" );
121
122 const int rows = getRows(src);
123 const int cols = getCols(src);
124
125 CV_Assert( getRows(dst) == rows && getCols(dst) == cols );
126
127 grid_split_merge_detail::MergeImpl<VecTraits<DstType>::cn, Policy>::merge(shrinkPtr(src),
128 shrinkPtr(dst),
129 WithOutMask(),
130 rows, cols,
131 StreamAccessor::getStream(stream));
132 }
133
134 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())135 __host__ void gridSplit_(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
136 {
137 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 2, "" );
138
139 const int rows = getRows(src);
140 const int cols = getCols(src);
141
142 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
143
144 get<0>(dst).create(rows, cols);
145 get<1>(dst).create(rows, cols);
146
147 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
148 shrinkPtr(get<0>(dst)), shrinkPtr(get<1>(dst)),
149 shrinkPtr(mask),
150 rows, cols,
151 StreamAccessor::getStream(stream));
152 }
153
154 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,GpuMat_<DstType> (& dst)[2],const MaskPtr & mask,Stream & stream=Stream::Null ())155 __host__ void gridSplit_(const SrcPtr& src, GpuMat_<DstType> (&dst)[2], const MaskPtr& mask, Stream& stream = Stream::Null())
156 {
157 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 2, "" );
158
159 const int rows = getRows(src);
160 const int cols = getCols(src);
161
162 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
163
164 dst[0].create(rows, cols);
165 dst[1].create(rows, cols);
166
167 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
168 shrinkPtr(dst[0]), shrinkPtr(dst[1]),
169 shrinkPtr(mask),
170 rows, cols,
171 StreamAccessor::getStream(stream));
172 }
173
174 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,GlobPtrSz<DstType> (& dst)[2],const MaskPtr & mask,Stream & stream=Stream::Null ())175 __host__ void gridSplit_(const SrcPtr& src, GlobPtrSz<DstType> (&dst)[2], const MaskPtr& mask, Stream& stream = Stream::Null())
176 {
177 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 2, "" );
178
179 const int rows = getRows(src);
180 const int cols = getCols(src);
181
182 CV_Assert( getRows(dst[0]) == rows && getCols(dst[0]) == cols );
183 CV_Assert( getRows(dst[1]) == rows && getCols(dst[1]) == cols );
184 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
185
186 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
187 shrinkPtr(dst[0]), shrinkPtr(dst[1]),
188 shrinkPtr(mask),
189 rows, cols,
190 StreamAccessor::getStream(stream));
191 }
192
193 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,Stream & stream=Stream::Null ())194 __host__ void gridSplit_(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, Stream& stream = Stream::Null())
195 {
196 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 2, "" );
197
198 const int rows = getRows(src);
199 const int cols = getCols(src);
200
201 get<0>(dst).create(rows, cols);
202 get<1>(dst).create(rows, cols);
203
204 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
205 shrinkPtr(get<0>(dst)), shrinkPtr(get<1>(dst)),
206 WithOutMask(),
207 rows, cols,
208 StreamAccessor::getStream(stream));
209 }
210
211 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,GpuMat_<DstType> (& dst)[2],Stream & stream=Stream::Null ())212 __host__ void gridSplit_(const SrcPtr& src, GpuMat_<DstType> (&dst)[2], Stream& stream = Stream::Null())
213 {
214 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 2, "" );
215
216 const int rows = getRows(src);
217 const int cols = getCols(src);
218
219 dst[0].create(rows, cols);
220 dst[1].create(rows, cols);
221
222 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
223 shrinkPtr(dst[0]), shrinkPtr(dst[1]),
224 WithOutMask(),
225 rows, cols,
226 StreamAccessor::getStream(stream));
227 }
228
229 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,GlobPtrSz<DstType> (& dst)[2],Stream & stream=Stream::Null ())230 __host__ void gridSplit_(const SrcPtr& src, GlobPtrSz<DstType> (&dst)[2], Stream& stream = Stream::Null())
231 {
232 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 2, "" );
233
234 const int rows = getRows(src);
235 const int cols = getCols(src);
236
237 CV_Assert( getRows(dst[0]) == rows && getCols(dst[0]) == cols );
238 CV_Assert( getRows(dst[1]) == rows && getCols(dst[1]) == cols );
239
240 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
241 shrinkPtr(dst[0]), shrinkPtr(dst[1]),
242 WithOutMask(),
243 rows, cols,
244 StreamAccessor::getStream(stream));
245 }
246
247 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())248 __host__ void gridSplit_(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
249 {
250 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 3, "" );
251
252 const int rows = getRows(src);
253 const int cols = getCols(src);
254
255 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
256
257 get<0>(dst).create(rows, cols);
258 get<1>(dst).create(rows, cols);
259 get<2>(dst).create(rows, cols);
260
261 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
262 shrinkPtr(get<0>(dst)), shrinkPtr(get<1>(dst)), shrinkPtr(get<2>(dst)),
263 shrinkPtr(mask),
264 rows, cols,
265 StreamAccessor::getStream(stream));
266 }
267
268 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,GpuMat_<DstType> (& dst)[3],const MaskPtr & mask,Stream & stream=Stream::Null ())269 __host__ void gridSplit_(const SrcPtr& src, GpuMat_<DstType> (&dst)[3], const MaskPtr& mask, Stream& stream = Stream::Null())
270 {
271 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 3, "" );
272
273 const int rows = getRows(src);
274 const int cols = getCols(src);
275
276 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
277
278 dst[0].create(rows, cols);
279 dst[1].create(rows, cols);
280 dst[2].create(rows, cols);
281
282 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
283 shrinkPtr(dst[0]), shrinkPtr(dst[1]), shrinkPtr(dst[2]),
284 shrinkPtr(mask),
285 rows, cols,
286 StreamAccessor::getStream(stream));
287 }
288
289 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,GlobPtrSz<DstType> (& dst)[3],const MaskPtr & mask,Stream & stream=Stream::Null ())290 __host__ void gridSplit_(const SrcPtr& src, GlobPtrSz<DstType> (&dst)[3], const MaskPtr& mask, Stream& stream = Stream::Null())
291 {
292 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 3, "" );
293
294 const int rows = getRows(src);
295 const int cols = getCols(src);
296
297 CV_Assert( getRows(dst[0]) == rows && getCols(dst[0]) == cols );
298 CV_Assert( getRows(dst[1]) == rows && getCols(dst[1]) == cols );
299 CV_Assert( getRows(dst[2]) == rows && getCols(dst[2]) == cols );
300 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
301
302 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
303 shrinkPtr(dst[0]), shrinkPtr(dst[1]), shrinkPtr(dst[2]),
304 shrinkPtr(mask),
305 rows, cols,
306 StreamAccessor::getStream(stream));
307 }
308
309 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,Stream & stream=Stream::Null ())310 __host__ void gridSplit_(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, Stream& stream = Stream::Null())
311 {
312 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 3, "" );
313
314 const int rows = getRows(src);
315 const int cols = getCols(src);
316
317 get<0>(dst).create(rows, cols);
318 get<1>(dst).create(rows, cols);
319 get<2>(dst).create(rows, cols);
320
321 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
322 shrinkPtr(get<0>(dst)), shrinkPtr(get<1>(dst)), shrinkPtr(get<2>(dst)),
323 WithOutMask(),
324 rows, cols,
325 StreamAccessor::getStream(stream));
326 }
327
328 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,GpuMat_<DstType> (& dst)[3],Stream & stream=Stream::Null ())329 __host__ void gridSplit_(const SrcPtr& src, GpuMat_<DstType> (&dst)[3], Stream& stream = Stream::Null())
330 {
331 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 3, "" );
332
333 const int rows = getRows(src);
334 const int cols = getCols(src);
335
336 dst[0].create(rows, cols);
337 dst[1].create(rows, cols);
338 dst[2].create(rows, cols);
339
340 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
341 shrinkPtr(dst[0]), shrinkPtr(dst[1]), shrinkPtr(dst[2]),
342 WithOutMask(),
343 rows, cols,
344 StreamAccessor::getStream(stream));
345 }
346
347 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,GlobPtrSz<DstType> (& dst)[3],Stream & stream=Stream::Null ())348 __host__ void gridSplit_(const SrcPtr& src, GlobPtrSz<DstType> (&dst)[3], Stream& stream = Stream::Null())
349 {
350 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 3, "" );
351
352 const int rows = getRows(src);
353 const int cols = getCols(src);
354
355 CV_Assert( getRows(dst[0]) == rows && getCols(dst[0]) == cols );
356 CV_Assert( getRows(dst[1]) == rows && getCols(dst[1]) == cols );
357 CV_Assert( getRows(dst[2]) == rows && getCols(dst[2]) == cols );
358
359 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
360 shrinkPtr(dst[0]), shrinkPtr(dst[1]), shrinkPtr(dst[2]),
361 WithOutMask(),
362 rows, cols,
363 StreamAccessor::getStream(stream));
364 }
365
366 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())367 __host__ void gridSplit_(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
368 {
369 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 4, "" );
370
371 const int rows = getRows(src);
372 const int cols = getCols(src);
373
374 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
375
376 get<0>(dst).create(rows, cols);
377 get<1>(dst).create(rows, cols);
378 get<2>(dst).create(rows, cols);
379 get<3>(dst).create(rows, cols);
380
381 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
382 shrinkPtr(get<0>(dst)), shrinkPtr(get<1>(dst)), shrinkPtr(get<2>(dst)), shrinkPtr(get<3>(dst)),
383 shrinkPtr(mask),
384 rows, cols,
385 StreamAccessor::getStream(stream));
386 }
387
388 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,GpuMat_<DstType> (& dst)[4],const MaskPtr & mask,Stream & stream=Stream::Null ())389 __host__ void gridSplit_(const SrcPtr& src, GpuMat_<DstType> (&dst)[4], const MaskPtr& mask, Stream& stream = Stream::Null())
390 {
391 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 4, "" );
392
393 const int rows = getRows(src);
394 const int cols = getCols(src);
395
396 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
397
398 dst[0].create(rows, cols);
399 dst[1].create(rows, cols);
400 dst[2].create(rows, cols);
401 dst[3].create(rows, cols);
402
403 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
404 shrinkPtr(dst[0]), shrinkPtr(dst[1]), shrinkPtr(dst[2]), shrinkPtr(dst[3]),
405 shrinkPtr(mask),
406 rows, cols,
407 StreamAccessor::getStream(stream));
408 }
409
410 template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
gridSplit_(const SrcPtr & src,GlobPtrSz<DstType> (& dst)[4],const MaskPtr & mask,Stream & stream=Stream::Null ())411 __host__ void gridSplit_(const SrcPtr& src, GlobPtrSz<DstType> (&dst)[4], const MaskPtr& mask, Stream& stream = Stream::Null())
412 {
413 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 4, "" );
414
415 const int rows = getRows(src);
416 const int cols = getCols(src);
417
418 CV_Assert( getRows(dst[0]) == rows && getCols(dst[0]) == cols );
419 CV_Assert( getRows(dst[1]) == rows && getCols(dst[1]) == cols );
420 CV_Assert( getRows(dst[2]) == rows && getCols(dst[2]) == cols );
421 CV_Assert( getRows(dst[3]) == rows && getCols(dst[3]) == cols );
422 CV_Assert( getRows(mask) == rows && getCols(mask) == cols );
423
424 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
425 shrinkPtr(dst[0]), shrinkPtr(dst[1]), shrinkPtr(dst[2]), shrinkPtr(dst[3]),
426 shrinkPtr(mask),
427 rows, cols,
428 StreamAccessor::getStream(stream));
429 }
430
431 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,Stream & stream=Stream::Null ())432 __host__ void gridSplit_(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, Stream& stream = Stream::Null())
433 {
434 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 4, "" );
435
436 const int rows = getRows(src);
437 const int cols = getCols(src);
438
439 get<0>(dst).create(rows, cols);
440 get<1>(dst).create(rows, cols);
441 get<2>(dst).create(rows, cols);
442 get<3>(dst).create(rows, cols);
443
444 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
445 shrinkPtr(get<0>(dst)), shrinkPtr(get<1>(dst)), shrinkPtr(get<2>(dst)), shrinkPtr(get<3>(dst)),
446 WithOutMask(),
447 rows, cols,
448 StreamAccessor::getStream(stream));
449 }
450
451 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,GpuMat_<DstType> (& dst)[4],Stream & stream=Stream::Null ())452 __host__ void gridSplit_(const SrcPtr& src, GpuMat_<DstType> (&dst)[4], Stream& stream = Stream::Null())
453 {
454 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 4, "" );
455
456 const int rows = getRows(src);
457 const int cols = getCols(src);
458
459 dst[0].create(rows, cols);
460 dst[1].create(rows, cols);
461 dst[2].create(rows, cols);
462 dst[3].create(rows, cols);
463
464 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
465 shrinkPtr(dst[0]), shrinkPtr(dst[1]), shrinkPtr(dst[2]), shrinkPtr(dst[3]),
466 WithOutMask(),
467 rows, cols,
468 StreamAccessor::getStream(stream));
469 }
470
471 template <class Policy, class SrcPtr, typename DstType>
gridSplit_(const SrcPtr & src,GlobPtrSz<DstType> (& dst)[4],Stream & stream=Stream::Null ())472 __host__ void gridSplit_(const SrcPtr& src, GlobPtrSz<DstType> (&dst)[4], Stream& stream = Stream::Null())
473 {
474 CV_StaticAssert( VecTraits<typename PtrTraits<SrcPtr>::value_type>::cn == 4, "" );
475
476 const int rows = getRows(src);
477 const int cols = getCols(src);
478
479 CV_Assert( getRows(dst[0]) == rows && getCols(dst[0]) == cols );
480 CV_Assert( getRows(dst[1]) == rows && getCols(dst[1]) == cols );
481 CV_Assert( getRows(dst[2]) == rows && getCols(dst[2]) == cols );
482 CV_Assert( getRows(dst[3]) == rows && getCols(dst[3]) == cols );
483
484 grid_split_merge_detail::split<Policy>(shrinkPtr(src),
485 shrinkPtr(dst[0]), shrinkPtr(dst[1]), shrinkPtr(dst[2]), shrinkPtr(dst[3]),
486 WithOutMask(),
487 rows, cols,
488 StreamAccessor::getStream(stream));
489 }
490
491 // Default Policy
492
493 struct DefaultSplitMergePolicy
494 {
495 enum {
496 block_size_x = 32,
497 block_size_y = 8
498 };
499 };
500
501 template <class SrcPtrTuple, typename DstType, class MaskPtr>
gridMerge(const SrcPtrTuple & src,GpuMat_<DstType> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())502 __host__ void gridMerge(const SrcPtrTuple& src, GpuMat_<DstType>& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
503 {
504 gridMerge_<DefaultSplitMergePolicy>(src, dst, mask, stream);
505 }
506
507 template <class SrcPtrTuple, typename DstType, class MaskPtr>
gridMerge(const SrcPtrTuple & src,const GlobPtrSz<DstType> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())508 __host__ void gridMerge(const SrcPtrTuple& src, const GlobPtrSz<DstType>& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
509 {
510 gridMerge_<DefaultSplitMergePolicy>(src, dst, mask, stream);
511 }
512
513 template <class SrcPtrTuple, typename DstType>
gridMerge(const SrcPtrTuple & src,GpuMat_<DstType> & dst,Stream & stream=Stream::Null ())514 __host__ void gridMerge(const SrcPtrTuple& src, GpuMat_<DstType>& dst, Stream& stream = Stream::Null())
515 {
516 gridMerge_<DefaultSplitMergePolicy>(src, dst, stream);
517 }
518
519 template <class SrcPtrTuple, typename DstType>
gridMerge(const SrcPtrTuple & src,const GlobPtrSz<DstType> & dst,Stream & stream=Stream::Null ())520 __host__ void gridMerge(const SrcPtrTuple& src, const GlobPtrSz<DstType>& dst, Stream& stream = Stream::Null())
521 {
522 gridMerge_<DefaultSplitMergePolicy>(src, dst, stream);
523 }
524
525 template <class SrcPtr, typename DstType, class MaskPtr>
gridSplit(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())526 __host__ void gridSplit(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
527 {
528 gridSplit_<DefaultSplitMergePolicy>(src, dst, mask, stream);
529 }
530
531 template <class SrcPtr, typename DstType>
gridSplit(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,Stream & stream=Stream::Null ())532 __host__ void gridSplit(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, Stream& stream = Stream::Null())
533 {
534 gridSplit_<DefaultSplitMergePolicy>(src, dst, stream);
535 }
536
537 template <class SrcPtr, typename DstType, class MaskPtr>
gridSplit(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())538 __host__ void gridSplit(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
539 {
540 gridSplit_<DefaultSplitMergePolicy>(src, dst, mask, stream);
541 }
542
543 template <class SrcPtr, typename DstType>
gridSplit(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,Stream & stream=Stream::Null ())544 __host__ void gridSplit(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, Stream& stream = Stream::Null())
545 {
546 gridSplit_<DefaultSplitMergePolicy>(src, dst, stream);
547 }
548
549 template <class SrcPtr, typename DstType, class MaskPtr>
gridSplit(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,const MaskPtr & mask,Stream & stream=Stream::Null ())550 __host__ void gridSplit(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null())
551 {
552 gridSplit_<DefaultSplitMergePolicy>(src, dst, mask, stream);
553 }
554
555 template <class SrcPtr, typename DstType>
gridSplit(const SrcPtr & src,const tuple<GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &,GpuMat_<DstType> &> & dst,Stream & stream=Stream::Null ())556 __host__ void gridSplit(const SrcPtr& src, const tuple< GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>&, GpuMat_<DstType>& >& dst, Stream& stream = Stream::Null())
557 {
558 gridSplit_<DefaultSplitMergePolicy>(src, dst, stream);
559 }
560
561 template <class SrcPtr, typename DstType, int COUNT, class MaskPtr>
gridSplit(const SrcPtr & src,GpuMat_<DstType> (& dst)[COUNT],const MaskPtr & mask,Stream & stream=Stream::Null ())562 __host__ void gridSplit(const SrcPtr& src, GpuMat_<DstType> (&dst)[COUNT], const MaskPtr& mask, Stream& stream = Stream::Null())
563 {
564 gridSplit_<DefaultSplitMergePolicy>(src, dst, mask, stream);
565 }
566
567 template <class SrcPtr, typename DstType, int COUNT, class MaskPtr>
gridSplit(const SrcPtr & src,GlobPtrSz<DstType> (& dst)[COUNT],const MaskPtr & mask,Stream & stream=Stream::Null ())568 __host__ void gridSplit(const SrcPtr& src, GlobPtrSz<DstType> (&dst)[COUNT], const MaskPtr& mask, Stream& stream = Stream::Null())
569 {
570 gridSplit_<DefaultSplitMergePolicy>(src, dst, mask, stream);
571 }
572
573 template <class SrcPtr, typename DstType, int COUNT>
gridSplit(const SrcPtr & src,GpuMat_<DstType> (& dst)[COUNT],Stream & stream=Stream::Null ())574 __host__ void gridSplit(const SrcPtr& src, GpuMat_<DstType> (&dst)[COUNT], Stream& stream = Stream::Null())
575 {
576 gridSplit_<DefaultSplitMergePolicy>(src, dst, stream);
577 }
578
579 template <class SrcPtr, typename DstType, int COUNT>
gridSplit(const SrcPtr & src,GlobPtrSz<DstType> (& dst)[COUNT],Stream & stream=Stream::Null ())580 __host__ void gridSplit(const SrcPtr& src, GlobPtrSz<DstType> (&dst)[COUNT], Stream& stream = Stream::Null())
581 {
582 gridSplit_<DefaultSplitMergePolicy>(src, dst, stream);
583 }
584
585 //! @}
586
587 }}
588
589 #endif
590