opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
joeverbout 0:ea44dc9ed014 16 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 17 //
joeverbout 0:ea44dc9ed014 18 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 19 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 20 //
joeverbout 0:ea44dc9ed014 21 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 22 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 23 //
joeverbout 0:ea44dc9ed014 24 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 25 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 26 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 27 //
joeverbout 0:ea44dc9ed014 28 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 29 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 30 //
joeverbout 0:ea44dc9ed014 31 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 32 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 34 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 35 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 36 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 37 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 38 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 39 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 40 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 41 //
joeverbout 0:ea44dc9ed014 42 //M*/
joeverbout 0:ea44dc9ed014 43
joeverbout 0:ea44dc9ed014 44 #ifndef __OPENCV_CORE_PRIVATE_CUDA_HPP__
joeverbout 0:ea44dc9ed014 45 #define __OPENCV_CORE_PRIVATE_CUDA_HPP__
joeverbout 0:ea44dc9ed014 46
joeverbout 0:ea44dc9ed014 47 #ifndef __OPENCV_BUILD
joeverbout 0:ea44dc9ed014 48 # error this is a private header which should not be used from outside of the OpenCV library
joeverbout 0:ea44dc9ed014 49 #endif
joeverbout 0:ea44dc9ed014 50
joeverbout 0:ea44dc9ed014 51 #include "cvconfig.h"
joeverbout 0:ea44dc9ed014 52
joeverbout 0:ea44dc9ed014 53 #include "opencv2/core/cvdef.h"
joeverbout 0:ea44dc9ed014 54 #include "opencv2/core/base.hpp"
joeverbout 0:ea44dc9ed014 55
joeverbout 0:ea44dc9ed014 56 #include "opencv2/core/cuda.hpp"
joeverbout 0:ea44dc9ed014 57
joeverbout 0:ea44dc9ed014 58 #ifdef HAVE_CUDA
joeverbout 0:ea44dc9ed014 59 # include <cuda.h>
joeverbout 0:ea44dc9ed014 60 # include <cuda_runtime.h>
joeverbout 0:ea44dc9ed014 61 # include <npp.h>
joeverbout 0:ea44dc9ed014 62 # include "opencv2/core/cuda_stream_accessor.hpp"
joeverbout 0:ea44dc9ed014 63 # include "opencv2/core/cuda/common.hpp"
joeverbout 0:ea44dc9ed014 64
joeverbout 0:ea44dc9ed014 65 # define NPP_VERSION (NPP_VERSION_MAJOR * 1000 + NPP_VERSION_MINOR * 100 + NPP_VERSION_BUILD)
joeverbout 0:ea44dc9ed014 66
joeverbout 0:ea44dc9ed014 67 # define CUDART_MINIMUM_REQUIRED_VERSION 4020
joeverbout 0:ea44dc9ed014 68
joeverbout 0:ea44dc9ed014 69 # if (CUDART_VERSION < CUDART_MINIMUM_REQUIRED_VERSION)
joeverbout 0:ea44dc9ed014 70 # error "Insufficient Cuda Runtime library version, please update it."
joeverbout 0:ea44dc9ed014 71 # endif
joeverbout 0:ea44dc9ed014 72
joeverbout 0:ea44dc9ed014 73 # if defined(CUDA_ARCH_BIN_OR_PTX_10)
joeverbout 0:ea44dc9ed014 74 # error "OpenCV CUDA module doesn't support NVIDIA compute capability 1.0"
joeverbout 0:ea44dc9ed014 75 # endif
joeverbout 0:ea44dc9ed014 76 #endif
joeverbout 0:ea44dc9ed014 77
joeverbout 0:ea44dc9ed014 78 //! @cond IGNORED
joeverbout 0:ea44dc9ed014 79
joeverbout 0:ea44dc9ed014 80 namespace cv { namespace cuda {
joeverbout 0:ea44dc9ed014 81 CV_EXPORTS cv::String getNppErrorMessage(int code);
joeverbout 0:ea44dc9ed014 82 CV_EXPORTS cv::String getCudaDriverApiErrorMessage(int code);
joeverbout 0:ea44dc9ed014 83
joeverbout 0:ea44dc9ed014 84 CV_EXPORTS GpuMat getInputMat(InputArray _src, Stream& stream);
joeverbout 0:ea44dc9ed014 85
joeverbout 0:ea44dc9ed014 86 CV_EXPORTS GpuMat getOutputMat(OutputArray _dst, int rows, int cols, int type, Stream& stream);
joeverbout 0:ea44dc9ed014 87 static inline GpuMat getOutputMat(OutputArray _dst, Size size, int type, Stream& stream)
joeverbout 0:ea44dc9ed014 88 {
joeverbout 0:ea44dc9ed014 89 return getOutputMat(_dst, size.height, size.width, type, stream);
joeverbout 0:ea44dc9ed014 90 }
joeverbout 0:ea44dc9ed014 91
joeverbout 0:ea44dc9ed014 92 CV_EXPORTS void syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream);
joeverbout 0:ea44dc9ed014 93 }}
joeverbout 0:ea44dc9ed014 94
joeverbout 0:ea44dc9ed014 95 #ifndef HAVE_CUDA
joeverbout 0:ea44dc9ed014 96
joeverbout 0:ea44dc9ed014 97 static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without CUDA support"); }
joeverbout 0:ea44dc9ed014 98
joeverbout 0:ea44dc9ed014 99 #else // HAVE_CUDA
joeverbout 0:ea44dc9ed014 100
joeverbout 0:ea44dc9ed014 101 static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); }
joeverbout 0:ea44dc9ed014 102
joeverbout 0:ea44dc9ed014 103 namespace cv { namespace cuda
joeverbout 0:ea44dc9ed014 104 {
joeverbout 0:ea44dc9ed014 105 class CV_EXPORTS BufferPool
joeverbout 0:ea44dc9ed014 106 {
joeverbout 0:ea44dc9ed014 107 public:
joeverbout 0:ea44dc9ed014 108 explicit BufferPool(Stream& stream);
joeverbout 0:ea44dc9ed014 109
joeverbout 0:ea44dc9ed014 110 GpuMat getBuffer(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 111 GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); }
joeverbout 0:ea44dc9ed014 112
joeverbout 0:ea44dc9ed014 113 GpuMat::Allocator* getAllocator() const { return allocator_; }
joeverbout 0:ea44dc9ed014 114
joeverbout 0:ea44dc9ed014 115 private:
joeverbout 0:ea44dc9ed014 116 GpuMat::Allocator* allocator_;
joeverbout 0:ea44dc9ed014 117 };
joeverbout 0:ea44dc9ed014 118
joeverbout 0:ea44dc9ed014 119 static inline void checkNppError(int code, const char* file, const int line, const char* func)
joeverbout 0:ea44dc9ed014 120 {
joeverbout 0:ea44dc9ed014 121 if (code < 0)
joeverbout 0:ea44dc9ed014 122 cv::error(cv::Error::GpuApiCallError, getNppErrorMessage(code), func, file, line);
joeverbout 0:ea44dc9ed014 123 }
joeverbout 0:ea44dc9ed014 124
joeverbout 0:ea44dc9ed014 125 static inline void checkCudaDriverApiError(int code, const char* file, const int line, const char* func)
joeverbout 0:ea44dc9ed014 126 {
joeverbout 0:ea44dc9ed014 127 if (code != CUDA_SUCCESS)
joeverbout 0:ea44dc9ed014 128 cv::error(cv::Error::GpuApiCallError, getCudaDriverApiErrorMessage(code), func, file, line);
joeverbout 0:ea44dc9ed014 129 }
joeverbout 0:ea44dc9ed014 130
joeverbout 0:ea44dc9ed014 131 template<int n> struct NPPTypeTraits;
joeverbout 0:ea44dc9ed014 132 template<> struct NPPTypeTraits<CV_8U> { typedef Npp8u npp_type; };
joeverbout 0:ea44dc9ed014 133 template<> struct NPPTypeTraits<CV_8S> { typedef Npp8s npp_type; };
joeverbout 0:ea44dc9ed014 134 template<> struct NPPTypeTraits<CV_16U> { typedef Npp16u npp_type; };
joeverbout 0:ea44dc9ed014 135 template<> struct NPPTypeTraits<CV_16S> { typedef Npp16s npp_type; };
joeverbout 0:ea44dc9ed014 136 template<> struct NPPTypeTraits<CV_32S> { typedef Npp32s npp_type; };
joeverbout 0:ea44dc9ed014 137 template<> struct NPPTypeTraits<CV_32F> { typedef Npp32f npp_type; };
joeverbout 0:ea44dc9ed014 138 template<> struct NPPTypeTraits<CV_64F> { typedef Npp64f npp_type; };
joeverbout 0:ea44dc9ed014 139
joeverbout 0:ea44dc9ed014 140 class NppStreamHandler
joeverbout 0:ea44dc9ed014 141 {
joeverbout 0:ea44dc9ed014 142 public:
joeverbout 0:ea44dc9ed014 143 inline explicit NppStreamHandler(Stream& newStream)
joeverbout 0:ea44dc9ed014 144 {
joeverbout 0:ea44dc9ed014 145 oldStream = nppGetStream();
joeverbout 0:ea44dc9ed014 146 nppSetStream(StreamAccessor::getStream(newStream));
joeverbout 0:ea44dc9ed014 147 }
joeverbout 0:ea44dc9ed014 148
joeverbout 0:ea44dc9ed014 149 inline explicit NppStreamHandler(cudaStream_t newStream)
joeverbout 0:ea44dc9ed014 150 {
joeverbout 0:ea44dc9ed014 151 oldStream = nppGetStream();
joeverbout 0:ea44dc9ed014 152 nppSetStream(newStream);
joeverbout 0:ea44dc9ed014 153 }
joeverbout 0:ea44dc9ed014 154
joeverbout 0:ea44dc9ed014 155 inline ~NppStreamHandler()
joeverbout 0:ea44dc9ed014 156 {
joeverbout 0:ea44dc9ed014 157 nppSetStream(oldStream);
joeverbout 0:ea44dc9ed014 158 }
joeverbout 0:ea44dc9ed014 159
joeverbout 0:ea44dc9ed014 160 private:
joeverbout 0:ea44dc9ed014 161 cudaStream_t oldStream;
joeverbout 0:ea44dc9ed014 162 };
joeverbout 0:ea44dc9ed014 163 }}
joeverbout 0:ea44dc9ed014 164
joeverbout 0:ea44dc9ed014 165 #define nppSafeCall(expr) cv::cuda::checkNppError(expr, __FILE__, __LINE__, CV_Func)
joeverbout 0:ea44dc9ed014 166 #define cuSafeCall(expr) cv::cuda::checkCudaDriverApiError(expr, __FILE__, __LINE__, CV_Func)
joeverbout 0:ea44dc9ed014 167
joeverbout 0:ea44dc9ed014 168 #endif // HAVE_CUDA
joeverbout 0:ea44dc9ed014 169
joeverbout 0:ea44dc9ed014 170 //! @endcond
joeverbout 0:ea44dc9ed014 171
joeverbout 0:ea44dc9ed014 172 #endif // __OPENCV_CORE_CUDA_PRIVATE_HPP__
joeverbout 0:ea44dc9ed014 173