Home | History | Annotate | Download | only in src
      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 // Third party copyrights are property of their respective owners.
     16 //
     17 // Redistribution and use in source and binary forms, with or without modification,
     18 // are permitted provided that the following conditions are met:
     19 //
     20 //   * Redistribution's of source code must retain the above copyright notice,
     21 //     this list of conditions and the following disclaimer.
     22 //
     23 //   * Redistribution's in binary form must reproduce the above copyright notice,
     24 //     this list of conditions and the following disclaimer in the documentation
     25 //     and/or other materials provided with the distribution.
     26 //
     27 //   * The name of the copyright holders may not be used to endorse or promote products
     28 //     derived from this software without specific prior written permission.
     29 //
     30 // This software is provided by the copyright holders and contributors "as is" and
     31 // any express or implied warranties, including, but not limited to, the implied
     32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     33 // In no event shall the Intel Corporation or contributors be liable for any direct,
     34 // indirect, incidental, special, exemplary, or consequential damages
     35 // (including, but not limited to, procurement of substitute goods or services;
     36 // loss of use, data, or profits; or business interruption) however caused
     37 // and on any theory of liability, whether in contract, strict liability,
     38 // or tort (including negligence or otherwise) arising in any way out of
     39 // the use of this software, even if advised of the possibility of such damage.
     40 //
     41 //M*/
     42 
     43 #include "precomp.hpp"
     44 
     45 using namespace cv;
     46 using namespace cv::cuda;
     47 
     48 #if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
     49 
     50 void cv::cuda::meanShiftFiltering(InputArray, OutputArray, int, int, TermCriteria, Stream&) { throw_no_cuda(); }
     51 void cv::cuda::meanShiftProc(InputArray, OutputArray, OutputArray, int, int, TermCriteria, Stream&) { throw_no_cuda(); }
     52 
     53 #else /* !defined (HAVE_CUDA) */
     54 
     55 ////////////////////////////////////////////////////////////////////////
     56 // meanShiftFiltering
     57 
     58 namespace cv { namespace cuda { namespace device
     59 {
     60     namespace imgproc
     61     {
     62         void meanShiftFiltering_gpu(const PtrStepSzb& src, PtrStepSzb dst, int sp, int sr, int maxIter, float eps, cudaStream_t stream);
     63     }
     64 }}}
     65 
     66 void cv::cuda::meanShiftFiltering(InputArray _src, OutputArray _dst, int sp, int sr, TermCriteria criteria, Stream& stream)
     67 {
     68     using namespace ::cv::cuda::device::imgproc;
     69 
     70     GpuMat src = _src.getGpuMat();
     71 
     72     CV_Assert( src.type() == CV_8UC4 );
     73 
     74     _dst.create(src.size(), CV_8UC4);
     75     GpuMat dst = _dst.getGpuMat();
     76 
     77     if (!(criteria.type & TermCriteria::MAX_ITER))
     78         criteria.maxCount = 5;
     79 
     80     int maxIter = std::min(std::max(criteria.maxCount, 1), 100);
     81 
     82     if (!(criteria.type & TermCriteria::EPS))
     83         criteria.epsilon = 1.f;
     84 
     85     float eps = (float) std::max(criteria.epsilon, 0.0);
     86 
     87     meanShiftFiltering_gpu(src, dst, sp, sr, maxIter, eps, StreamAccessor::getStream(stream));
     88 }
     89 
     90 ////////////////////////////////////////////////////////////////////////
     91 // meanShiftProc_CUDA
     92 
     93 namespace cv { namespace cuda { namespace device
     94 {
     95     namespace imgproc
     96     {
     97         void meanShiftProc_gpu(const PtrStepSzb& src, PtrStepSzb dstr, PtrStepSzb dstsp, int sp, int sr, int maxIter, float eps, cudaStream_t stream);
     98     }
     99 }}}
    100 
    101 void cv::cuda::meanShiftProc(InputArray _src, OutputArray _dstr, OutputArray _dstsp, int sp, int sr, TermCriteria criteria, Stream& stream)
    102 {
    103     using namespace ::cv::cuda::device::imgproc;
    104 
    105     GpuMat src = _src.getGpuMat();
    106 
    107     CV_Assert( src.type() == CV_8UC4 );
    108 
    109     _dstr.create(src.size(), CV_8UC4);
    110     _dstsp.create(src.size(), CV_16SC2);
    111 
    112     GpuMat dstr = _dstr.getGpuMat();
    113     GpuMat dstsp = _dstsp.getGpuMat();
    114 
    115     if (!(criteria.type & TermCriteria::MAX_ITER))
    116         criteria.maxCount = 5;
    117 
    118     int maxIter = std::min(std::max(criteria.maxCount, 1), 100);
    119 
    120     if (!(criteria.type & TermCriteria::EPS))
    121         criteria.epsilon = 1.f;
    122 
    123     float eps = (float) std::max(criteria.epsilon, 0.0);
    124 
    125     meanShiftProc_gpu(src, dstr, dstsp, sp, sr, maxIter, eps, StreamAccessor::getStream(stream));
    126 }
    127 
    128 #endif /* !defined (HAVE_CUDA) */
    129