1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*M/////////////////////////////////////////////////////////////////////////////////////// 2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// By downloading, copying, installing or using the software you agree to this license. 6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// If you do not agree to this license, do not download, install, 7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// copy or use the software. 8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 10793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// License Agreement 11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// For Open Source Computer Vision Library 12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Third party copyrights are property of their respective owners. 16793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Redistribution and use in source and binary forms, with or without modification, 18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// are permitted provided that the following conditions are met: 19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Redistribution's of source code must retain the above copyright notice, 21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// this list of conditions and the following disclaimer. 22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Redistribution's in binary form must reproduce the above copyright notice, 24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// this list of conditions and the following disclaimer in the documentation 25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and/or other materials provided with the distribution. 26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * The name of the copyright holders may not be used to endorse or promote products 28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// derived from this software without specific prior written permission. 29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// This software is provided by the copyright holders and contributors "as is" and 31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// any express or implied warranties, including, but not limited to, the implied 32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// warranties of merchantability and fitness for a particular purpose are disclaimed. 33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// In no event shall the Intel Corporation or contributors be liable for any direct, 34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// indirect, incidental, special, exemplary, or consequential damages 35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// (including, but not limited to, procurement of substitute goods or services; 36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// loss of use, data, or profits; or business interruption) however caused 37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and on any theory of liability, whether in contract, strict liability, 38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// or tort (including negligence or otherwise) arising in any way out of 39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// the use of this software, even if advised of the possibility of such damage. 40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//M*/ 42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/opencv_modules.hpp" 44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef HAVE_OPENCV_CUDEV 46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#error "opencv_cudev is required" 48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#else 50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/cudaarithm.hpp" 52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/cudev.hpp" 53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/private.cuda.hpp" 54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing namespace cv; 56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing namespace cv::cuda; 57793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing namespace cv::cudev; 58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 59793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace 60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler template <typename T, typename S, typename D> 62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler void reduceToRowImpl(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream) 63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const GpuMat_<T>& src = (const GpuMat_<T>&) _src; 65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler GpuMat_<D>& dst = (GpuMat_<D>&) _dst; 66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (reduceOp) 68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case cv::REDUCE_SUM: 70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridReduceToRow< Sum<S> >(src, dst, stream); 71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 72793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 73793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case cv::REDUCE_AVG: 74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridReduceToRow< Avg<S> >(src, dst, stream); 75793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case cv::REDUCE_MIN: 78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridReduceToRow< Min<S> >(src, dst, stream); 79793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case cv::REDUCE_MAX: 82793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridReduceToRow< Max<S> >(src, dst, stream); 83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 86793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 87793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler template <typename T, typename S, typename D> 88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler void reduceToColumnImpl_(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream) 89793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 90793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const GpuMat_<T>& src = (const GpuMat_<T>&) _src; 91793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler GpuMat_<D>& dst = (GpuMat_<D>&) _dst; 92793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 93793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (reduceOp) 94793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case cv::REDUCE_SUM: 96793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridReduceToColumn< Sum<S> >(src, dst, stream); 97793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 99793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case cv::REDUCE_AVG: 100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridReduceToColumn< Avg<S> >(src, dst, stream); 101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case cv::REDUCE_MIN: 104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridReduceToColumn< Min<S> >(src, dst, stream); 105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case cv::REDUCE_MAX: 108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridReduceToColumn< Max<S> >(src, dst, stream); 109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 112793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler template <typename T, typename S, typename D> 114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler void reduceToColumnImpl(const GpuMat& src, GpuMat& dst, int reduceOp, Stream& stream) 115793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int reduceOp, Stream& stream); 117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler static const func_t funcs[4] = 118793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 119793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl_<T, S, D>, 120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl_<typename MakeVec<T, 2>::type, typename MakeVec<S, 2>::type, typename MakeVec<D, 2>::type>, 121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl_<typename MakeVec<T, 3>::type, typename MakeVec<S, 3>::type, typename MakeVec<D, 3>::type>, 122793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl_<typename MakeVec<T, 4>::type, typename MakeVec<S, 4>::type, typename MakeVec<D, 4>::type> 123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 124793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 125793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler funcs[src.channels() - 1](src, dst, reduceOp, stream); 126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 127793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 129793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervoid cv::cuda::reduce(InputArray _src, OutputArray _dst, int dim, int reduceOp, int dtype, Stream& stream) 130793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 131793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler GpuMat src = getInputMat(_src, stream); 132793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 133793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CV_Assert( src.channels() <= 4 ); 134793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CV_Assert( dim == 0 || dim == 1 ); 135793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CV_Assert( reduceOp == REDUCE_SUM || reduceOp == REDUCE_AVG || reduceOp == REDUCE_MAX || reduceOp == REDUCE_MIN ); 136793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (dtype < 0) 138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler dtype = src.depth(); 139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler GpuMat dst = getOutputMat(_dst, 1, dim == 0 ? src.cols : src.rows, CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src.channels()), stream); 141793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 142793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (dim == 0) 143793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream); 145793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler static const func_t funcs[7][7] = 146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 147793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 148793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<uchar, int, uchar>, 149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<uchar, int, schar>*/, 150793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<uchar, int, ushort>*/, 151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<uchar, int, short>*/, 152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<uchar, int, int>, 153793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<uchar, float, float>, 154793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<uchar, double, double> 155793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 156793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 157793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<schar, int, uchar>*/, 158793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<schar, int, schar>*/, 159793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<schar, int, ushort>*/, 160793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<schar, int, short>*/, 161793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<schar, int, int>*/, 162793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<schar, float, float>*/, 163793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<schar, double, double>*/ 164793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 165793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 166793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<ushort, int, uchar>*/, 167793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<ushort, int, schar>*/, 168793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<ushort, int, ushort>, 169793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<ushort, int, short>*/, 170793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<ushort, int, int>, 171793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<ushort, float, float>, 172793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<ushort, double, double> 173793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 174793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 175793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<short, int, uchar>*/, 176793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<short, int, schar>*/, 177793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<short, int, ushort>*/, 178793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<short, int, short>, 179793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<short, int, int>, 180793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<short, float, float>, 181793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<short, double, double> 182793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 183793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 184793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<int, int, uchar>*/, 185793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<int, int, schar>*/, 186793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<int, int, ushort>*/, 187793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<int, int, short>*/, 188793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<int, int, int>, 189793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<int, float, float>, 190793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<int, double, double> 191793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 192793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 193793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<float, float, uchar>*/, 194793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<float, float, schar>*/, 195793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<float, float, ushort>*/, 196793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<float, float, short>*/, 197793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<float, float, int>*/, 198793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<float, float, float>, 199793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<float, double, double> 200793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 201793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 202793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<double, double, uchar>*/, 203793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<double, double, schar>*/, 204793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<double, double, ushort>*/, 205793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<double, double, short>*/, 206793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<double, double, int>*/, 207793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToRowImpl<double, double, float>*/, 208793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToRowImpl<double, double, double> 209793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 210793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 211793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 212793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const func_t func = funcs[src.depth()][dst.depth()]; 213793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 214793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!func) 215793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of input and output array formats"); 216793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 217793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler GpuMat dst_cont = dst.reshape(1); 218793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler func(src.reshape(1), dst_cont, reduceOp, stream); 219793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 220793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler else 221793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 222793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream); 223793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler static const func_t funcs[7][7] = 224793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 225793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 226793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<uchar, int, uchar>, 227793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<uchar, int, schar>*/, 228793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<uchar, int, ushort>*/, 229793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<uchar, int, short>*/, 230793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<uchar, int, int>, 231793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<uchar, float, float>, 232793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<uchar, double, double> 233793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 234793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 235793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<schar, int, uchar>*/, 236793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<schar, int, schar>*/, 237793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<schar, int, ushort>*/, 238793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<schar, int, short>*/, 239793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<schar, int, int>*/, 240793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<schar, float, float>*/, 241793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<schar, double, double>*/ 242793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 243793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 244793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<ushort, int, uchar>*/, 245793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<ushort, int, schar>*/, 246793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<ushort, int, ushort>, 247793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<ushort, int, short>*/, 248793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<ushort, int, int>, 249793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<ushort, float, float>, 250793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<ushort, double, double> 251793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 252793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 253793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<short, int, uchar>*/, 254793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<short, int, schar>*/, 255793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<short, int, ushort>*/, 256793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<short, int, short>, 257793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<short, int, int>, 258793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<short, float, float>, 259793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<short, double, double> 260793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 261793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 262793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<int, int, uchar>*/, 263793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<int, int, schar>*/, 264793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<int, int, ushort>*/, 265793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<int, int, short>*/, 266793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<int, int, int>, 267793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<int, float, float>, 268793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<int, double, double> 269793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 270793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 271793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<float, float, uchar>*/, 272793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<float, float, schar>*/, 273793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<float, float, ushort>*/, 274793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<float, float, short>*/, 275793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<float, float, int>*/, 276793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<float, float, float>, 277793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<float, double, double> 278793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }, 279793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 280793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<double, double, uchar>*/, 281793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<double, double, schar>*/, 282793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<double, double, ushort>*/, 283793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<double, double, short>*/, 284793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<double, double, int>*/, 285793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 0 /*reduceToColumnImpl<double, double, float>*/, 286793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler reduceToColumnImpl<double, double, double> 287793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 288793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 289793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 290793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const func_t func = funcs[src.depth()][dst.depth()]; 291793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 292793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!func) 293793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of input and output array formats"); 294793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 295793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler func(src, dst, reduceOp, stream); 296793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 297793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 298793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler syncOutput(dst, _dst, stream); 299793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 300793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 301793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 302