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_CUDAINL_HPP__
joeverbout 0:ea44dc9ed014 45 #define __OPENCV_CORE_CUDAINL_HPP__
joeverbout 0:ea44dc9ed014 46
joeverbout 0:ea44dc9ed014 47 #include "opencv2/core/cuda.hpp"
joeverbout 0:ea44dc9ed014 48
joeverbout 0:ea44dc9ed014 49 //! @cond IGNORED
joeverbout 0:ea44dc9ed014 50
joeverbout 0:ea44dc9ed014 51 namespace cv { namespace cuda {
joeverbout 0:ea44dc9ed014 52
joeverbout 0:ea44dc9ed014 53 //===================================================================================
joeverbout 0:ea44dc9ed014 54 // GpuMat
joeverbout 0:ea44dc9ed014 55 //===================================================================================
joeverbout 0:ea44dc9ed014 56
joeverbout 0:ea44dc9ed014 57 inline
joeverbout 0:ea44dc9ed014 58 GpuMat::GpuMat(Allocator* allocator_)
joeverbout 0:ea44dc9ed014 59 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
joeverbout 0:ea44dc9ed014 60 {}
joeverbout 0:ea44dc9ed014 61
joeverbout 0:ea44dc9ed014 62 inline
joeverbout 0:ea44dc9ed014 63 GpuMat::GpuMat(int rows_, int cols_, int type_, Allocator* allocator_)
joeverbout 0:ea44dc9ed014 64 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
joeverbout 0:ea44dc9ed014 65 {
joeverbout 0:ea44dc9ed014 66 if (rows_ > 0 && cols_ > 0)
joeverbout 0:ea44dc9ed014 67 create(rows_, cols_, type_);
joeverbout 0:ea44dc9ed014 68 }
joeverbout 0:ea44dc9ed014 69
joeverbout 0:ea44dc9ed014 70 inline
joeverbout 0:ea44dc9ed014 71 GpuMat::GpuMat(Size size_, int type_, Allocator* allocator_)
joeverbout 0:ea44dc9ed014 72 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
joeverbout 0:ea44dc9ed014 73 {
joeverbout 0:ea44dc9ed014 74 if (size_.height > 0 && size_.width > 0)
joeverbout 0:ea44dc9ed014 75 create(size_.height, size_.width, type_);
joeverbout 0:ea44dc9ed014 76 }
joeverbout 0:ea44dc9ed014 77
joeverbout 0:ea44dc9ed014 78 inline
joeverbout 0:ea44dc9ed014 79 GpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_, Allocator* allocator_)
joeverbout 0:ea44dc9ed014 80 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
joeverbout 0:ea44dc9ed014 81 {
joeverbout 0:ea44dc9ed014 82 if (rows_ > 0 && cols_ > 0)
joeverbout 0:ea44dc9ed014 83 {
joeverbout 0:ea44dc9ed014 84 create(rows_, cols_, type_);
joeverbout 0:ea44dc9ed014 85 setTo(s_);
joeverbout 0:ea44dc9ed014 86 }
joeverbout 0:ea44dc9ed014 87 }
joeverbout 0:ea44dc9ed014 88
joeverbout 0:ea44dc9ed014 89 inline
joeverbout 0:ea44dc9ed014 90 GpuMat::GpuMat(Size size_, int type_, Scalar s_, Allocator* allocator_)
joeverbout 0:ea44dc9ed014 91 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
joeverbout 0:ea44dc9ed014 92 {
joeverbout 0:ea44dc9ed014 93 if (size_.height > 0 && size_.width > 0)
joeverbout 0:ea44dc9ed014 94 {
joeverbout 0:ea44dc9ed014 95 create(size_.height, size_.width, type_);
joeverbout 0:ea44dc9ed014 96 setTo(s_);
joeverbout 0:ea44dc9ed014 97 }
joeverbout 0:ea44dc9ed014 98 }
joeverbout 0:ea44dc9ed014 99
joeverbout 0:ea44dc9ed014 100 inline
joeverbout 0:ea44dc9ed014 101 GpuMat::GpuMat(const GpuMat& m)
joeverbout 0:ea44dc9ed014 102 : flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), allocator(m.allocator)
joeverbout 0:ea44dc9ed014 103 {
joeverbout 0:ea44dc9ed014 104 if (refcount)
joeverbout 0:ea44dc9ed014 105 CV_XADD(refcount, 1);
joeverbout 0:ea44dc9ed014 106 }
joeverbout 0:ea44dc9ed014 107
joeverbout 0:ea44dc9ed014 108 inline
joeverbout 0:ea44dc9ed014 109 GpuMat::GpuMat(InputArray arr, Allocator* allocator_) :
joeverbout 0:ea44dc9ed014 110 flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
joeverbout 0:ea44dc9ed014 111 {
joeverbout 0:ea44dc9ed014 112 upload(arr);
joeverbout 0:ea44dc9ed014 113 }
joeverbout 0:ea44dc9ed014 114
joeverbout 0:ea44dc9ed014 115 inline
joeverbout 0:ea44dc9ed014 116 GpuMat::~GpuMat()
joeverbout 0:ea44dc9ed014 117 {
joeverbout 0:ea44dc9ed014 118 release();
joeverbout 0:ea44dc9ed014 119 }
joeverbout 0:ea44dc9ed014 120
joeverbout 0:ea44dc9ed014 121 inline
joeverbout 0:ea44dc9ed014 122 GpuMat& GpuMat::operator =(const GpuMat& m)
joeverbout 0:ea44dc9ed014 123 {
joeverbout 0:ea44dc9ed014 124 if (this != &m)
joeverbout 0:ea44dc9ed014 125 {
joeverbout 0:ea44dc9ed014 126 GpuMat temp(m);
joeverbout 0:ea44dc9ed014 127 swap(temp);
joeverbout 0:ea44dc9ed014 128 }
joeverbout 0:ea44dc9ed014 129
joeverbout 0:ea44dc9ed014 130 return *this;
joeverbout 0:ea44dc9ed014 131 }
joeverbout 0:ea44dc9ed014 132
joeverbout 0:ea44dc9ed014 133 inline
joeverbout 0:ea44dc9ed014 134 void GpuMat::create(Size size_, int type_)
joeverbout 0:ea44dc9ed014 135 {
joeverbout 0:ea44dc9ed014 136 create(size_.height, size_.width, type_);
joeverbout 0:ea44dc9ed014 137 }
joeverbout 0:ea44dc9ed014 138
joeverbout 0:ea44dc9ed014 139 inline
joeverbout 0:ea44dc9ed014 140 void GpuMat::swap(GpuMat& b)
joeverbout 0:ea44dc9ed014 141 {
joeverbout 0:ea44dc9ed014 142 std::swap(flags, b.flags);
joeverbout 0:ea44dc9ed014 143 std::swap(rows, b.rows);
joeverbout 0:ea44dc9ed014 144 std::swap(cols, b.cols);
joeverbout 0:ea44dc9ed014 145 std::swap(step, b.step);
joeverbout 0:ea44dc9ed014 146 std::swap(data, b.data);
joeverbout 0:ea44dc9ed014 147 std::swap(datastart, b.datastart);
joeverbout 0:ea44dc9ed014 148 std::swap(dataend, b.dataend);
joeverbout 0:ea44dc9ed014 149 std::swap(refcount, b.refcount);
joeverbout 0:ea44dc9ed014 150 std::swap(allocator, b.allocator);
joeverbout 0:ea44dc9ed014 151 }
joeverbout 0:ea44dc9ed014 152
joeverbout 0:ea44dc9ed014 153 inline
joeverbout 0:ea44dc9ed014 154 GpuMat GpuMat::clone() const
joeverbout 0:ea44dc9ed014 155 {
joeverbout 0:ea44dc9ed014 156 GpuMat m;
joeverbout 0:ea44dc9ed014 157 copyTo(m);
joeverbout 0:ea44dc9ed014 158 return m;
joeverbout 0:ea44dc9ed014 159 }
joeverbout 0:ea44dc9ed014 160
joeverbout 0:ea44dc9ed014 161 inline
joeverbout 0:ea44dc9ed014 162 void GpuMat::copyTo(OutputArray dst, InputArray mask) const
joeverbout 0:ea44dc9ed014 163 {
joeverbout 0:ea44dc9ed014 164 copyTo(dst, mask, Stream::Null());
joeverbout 0:ea44dc9ed014 165 }
joeverbout 0:ea44dc9ed014 166
joeverbout 0:ea44dc9ed014 167 inline
joeverbout 0:ea44dc9ed014 168 GpuMat& GpuMat::setTo(Scalar s)
joeverbout 0:ea44dc9ed014 169 {
joeverbout 0:ea44dc9ed014 170 return setTo(s, Stream::Null());
joeverbout 0:ea44dc9ed014 171 }
joeverbout 0:ea44dc9ed014 172
joeverbout 0:ea44dc9ed014 173 inline
joeverbout 0:ea44dc9ed014 174 GpuMat& GpuMat::setTo(Scalar s, InputArray mask)
joeverbout 0:ea44dc9ed014 175 {
joeverbout 0:ea44dc9ed014 176 return setTo(s, mask, Stream::Null());
joeverbout 0:ea44dc9ed014 177 }
joeverbout 0:ea44dc9ed014 178
joeverbout 0:ea44dc9ed014 179 inline
joeverbout 0:ea44dc9ed014 180 void GpuMat::convertTo(OutputArray dst, int rtype) const
joeverbout 0:ea44dc9ed014 181 {
joeverbout 0:ea44dc9ed014 182 convertTo(dst, rtype, Stream::Null());
joeverbout 0:ea44dc9ed014 183 }
joeverbout 0:ea44dc9ed014 184
joeverbout 0:ea44dc9ed014 185 inline
joeverbout 0:ea44dc9ed014 186 void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, double beta) const
joeverbout 0:ea44dc9ed014 187 {
joeverbout 0:ea44dc9ed014 188 convertTo(dst, rtype, alpha, beta, Stream::Null());
joeverbout 0:ea44dc9ed014 189 }
joeverbout 0:ea44dc9ed014 190
joeverbout 0:ea44dc9ed014 191 inline
joeverbout 0:ea44dc9ed014 192 void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const
joeverbout 0:ea44dc9ed014 193 {
joeverbout 0:ea44dc9ed014 194 convertTo(dst, rtype, alpha, 0.0, stream);
joeverbout 0:ea44dc9ed014 195 }
joeverbout 0:ea44dc9ed014 196
joeverbout 0:ea44dc9ed014 197 inline
joeverbout 0:ea44dc9ed014 198 void GpuMat::assignTo(GpuMat& m, int _type) const
joeverbout 0:ea44dc9ed014 199 {
joeverbout 0:ea44dc9ed014 200 if (_type < 0)
joeverbout 0:ea44dc9ed014 201 m = *this;
joeverbout 0:ea44dc9ed014 202 else
joeverbout 0:ea44dc9ed014 203 convertTo(m, _type);
joeverbout 0:ea44dc9ed014 204 }
joeverbout 0:ea44dc9ed014 205
joeverbout 0:ea44dc9ed014 206 inline
joeverbout 0:ea44dc9ed014 207 uchar* GpuMat::ptr(int y)
joeverbout 0:ea44dc9ed014 208 {
joeverbout 0:ea44dc9ed014 209 CV_DbgAssert( (unsigned)y < (unsigned)rows );
joeverbout 0:ea44dc9ed014 210 return data + step * y;
joeverbout 0:ea44dc9ed014 211 }
joeverbout 0:ea44dc9ed014 212
joeverbout 0:ea44dc9ed014 213 inline
joeverbout 0:ea44dc9ed014 214 const uchar* GpuMat::ptr(int y) const
joeverbout 0:ea44dc9ed014 215 {
joeverbout 0:ea44dc9ed014 216 CV_DbgAssert( (unsigned)y < (unsigned)rows );
joeverbout 0:ea44dc9ed014 217 return data + step * y;
joeverbout 0:ea44dc9ed014 218 }
joeverbout 0:ea44dc9ed014 219
joeverbout 0:ea44dc9ed014 220 template<typename _Tp> inline
joeverbout 0:ea44dc9ed014 221 _Tp* GpuMat::ptr(int y)
joeverbout 0:ea44dc9ed014 222 {
joeverbout 0:ea44dc9ed014 223 return (_Tp*)ptr(y);
joeverbout 0:ea44dc9ed014 224 }
joeverbout 0:ea44dc9ed014 225
joeverbout 0:ea44dc9ed014 226 template<typename _Tp> inline
joeverbout 0:ea44dc9ed014 227 const _Tp* GpuMat::ptr(int y) const
joeverbout 0:ea44dc9ed014 228 {
joeverbout 0:ea44dc9ed014 229 return (const _Tp*)ptr(y);
joeverbout 0:ea44dc9ed014 230 }
joeverbout 0:ea44dc9ed014 231
joeverbout 0:ea44dc9ed014 232 template <class T> inline
joeverbout 0:ea44dc9ed014 233 GpuMat::operator PtrStepSz<T>() const
joeverbout 0:ea44dc9ed014 234 {
joeverbout 0:ea44dc9ed014 235 return PtrStepSz<T>(rows, cols, (T*)data, step);
joeverbout 0:ea44dc9ed014 236 }
joeverbout 0:ea44dc9ed014 237
joeverbout 0:ea44dc9ed014 238 template <class T> inline
joeverbout 0:ea44dc9ed014 239 GpuMat::operator PtrStep<T>() const
joeverbout 0:ea44dc9ed014 240 {
joeverbout 0:ea44dc9ed014 241 return PtrStep<T>((T*)data, step);
joeverbout 0:ea44dc9ed014 242 }
joeverbout 0:ea44dc9ed014 243
joeverbout 0:ea44dc9ed014 244 inline
joeverbout 0:ea44dc9ed014 245 GpuMat GpuMat::row(int y) const
joeverbout 0:ea44dc9ed014 246 {
joeverbout 0:ea44dc9ed014 247 return GpuMat(*this, Range(y, y+1), Range::all());
joeverbout 0:ea44dc9ed014 248 }
joeverbout 0:ea44dc9ed014 249
joeverbout 0:ea44dc9ed014 250 inline
joeverbout 0:ea44dc9ed014 251 GpuMat GpuMat::col(int x) const
joeverbout 0:ea44dc9ed014 252 {
joeverbout 0:ea44dc9ed014 253 return GpuMat(*this, Range::all(), Range(x, x+1));
joeverbout 0:ea44dc9ed014 254 }
joeverbout 0:ea44dc9ed014 255
joeverbout 0:ea44dc9ed014 256 inline
joeverbout 0:ea44dc9ed014 257 GpuMat GpuMat::rowRange(int startrow, int endrow) const
joeverbout 0:ea44dc9ed014 258 {
joeverbout 0:ea44dc9ed014 259 return GpuMat(*this, Range(startrow, endrow), Range::all());
joeverbout 0:ea44dc9ed014 260 }
joeverbout 0:ea44dc9ed014 261
joeverbout 0:ea44dc9ed014 262 inline
joeverbout 0:ea44dc9ed014 263 GpuMat GpuMat::rowRange(Range r) const
joeverbout 0:ea44dc9ed014 264 {
joeverbout 0:ea44dc9ed014 265 return GpuMat(*this, r, Range::all());
joeverbout 0:ea44dc9ed014 266 }
joeverbout 0:ea44dc9ed014 267
joeverbout 0:ea44dc9ed014 268 inline
joeverbout 0:ea44dc9ed014 269 GpuMat GpuMat::colRange(int startcol, int endcol) const
joeverbout 0:ea44dc9ed014 270 {
joeverbout 0:ea44dc9ed014 271 return GpuMat(*this, Range::all(), Range(startcol, endcol));
joeverbout 0:ea44dc9ed014 272 }
joeverbout 0:ea44dc9ed014 273
joeverbout 0:ea44dc9ed014 274 inline
joeverbout 0:ea44dc9ed014 275 GpuMat GpuMat::colRange(Range r) const
joeverbout 0:ea44dc9ed014 276 {
joeverbout 0:ea44dc9ed014 277 return GpuMat(*this, Range::all(), r);
joeverbout 0:ea44dc9ed014 278 }
joeverbout 0:ea44dc9ed014 279
joeverbout 0:ea44dc9ed014 280 inline
joeverbout 0:ea44dc9ed014 281 GpuMat GpuMat::operator ()(Range rowRange_, Range colRange_) const
joeverbout 0:ea44dc9ed014 282 {
joeverbout 0:ea44dc9ed014 283 return GpuMat(*this, rowRange_, colRange_);
joeverbout 0:ea44dc9ed014 284 }
joeverbout 0:ea44dc9ed014 285
joeverbout 0:ea44dc9ed014 286 inline
joeverbout 0:ea44dc9ed014 287 GpuMat GpuMat::operator ()(Rect roi) const
joeverbout 0:ea44dc9ed014 288 {
joeverbout 0:ea44dc9ed014 289 return GpuMat(*this, roi);
joeverbout 0:ea44dc9ed014 290 }
joeverbout 0:ea44dc9ed014 291
joeverbout 0:ea44dc9ed014 292 inline
joeverbout 0:ea44dc9ed014 293 bool GpuMat::isContinuous() const
joeverbout 0:ea44dc9ed014 294 {
joeverbout 0:ea44dc9ed014 295 return (flags & Mat::CONTINUOUS_FLAG) != 0;
joeverbout 0:ea44dc9ed014 296 }
joeverbout 0:ea44dc9ed014 297
joeverbout 0:ea44dc9ed014 298 inline
joeverbout 0:ea44dc9ed014 299 size_t GpuMat::elemSize() const
joeverbout 0:ea44dc9ed014 300 {
joeverbout 0:ea44dc9ed014 301 return CV_ELEM_SIZE(flags);
joeverbout 0:ea44dc9ed014 302 }
joeverbout 0:ea44dc9ed014 303
joeverbout 0:ea44dc9ed014 304 inline
joeverbout 0:ea44dc9ed014 305 size_t GpuMat::elemSize1() const
joeverbout 0:ea44dc9ed014 306 {
joeverbout 0:ea44dc9ed014 307 return CV_ELEM_SIZE1(flags);
joeverbout 0:ea44dc9ed014 308 }
joeverbout 0:ea44dc9ed014 309
joeverbout 0:ea44dc9ed014 310 inline
joeverbout 0:ea44dc9ed014 311 int GpuMat::type() const
joeverbout 0:ea44dc9ed014 312 {
joeverbout 0:ea44dc9ed014 313 return CV_MAT_TYPE(flags);
joeverbout 0:ea44dc9ed014 314 }
joeverbout 0:ea44dc9ed014 315
joeverbout 0:ea44dc9ed014 316 inline
joeverbout 0:ea44dc9ed014 317 int GpuMat::depth() const
joeverbout 0:ea44dc9ed014 318 {
joeverbout 0:ea44dc9ed014 319 return CV_MAT_DEPTH(flags);
joeverbout 0:ea44dc9ed014 320 }
joeverbout 0:ea44dc9ed014 321
joeverbout 0:ea44dc9ed014 322 inline
joeverbout 0:ea44dc9ed014 323 int GpuMat::channels() const
joeverbout 0:ea44dc9ed014 324 {
joeverbout 0:ea44dc9ed014 325 return CV_MAT_CN(flags);
joeverbout 0:ea44dc9ed014 326 }
joeverbout 0:ea44dc9ed014 327
joeverbout 0:ea44dc9ed014 328 inline
joeverbout 0:ea44dc9ed014 329 size_t GpuMat::step1() const
joeverbout 0:ea44dc9ed014 330 {
joeverbout 0:ea44dc9ed014 331 return step / elemSize1();
joeverbout 0:ea44dc9ed014 332 }
joeverbout 0:ea44dc9ed014 333
joeverbout 0:ea44dc9ed014 334 inline
joeverbout 0:ea44dc9ed014 335 Size GpuMat::size() const
joeverbout 0:ea44dc9ed014 336 {
joeverbout 0:ea44dc9ed014 337 return Size(cols, rows);
joeverbout 0:ea44dc9ed014 338 }
joeverbout 0:ea44dc9ed014 339
joeverbout 0:ea44dc9ed014 340 inline
joeverbout 0:ea44dc9ed014 341 bool GpuMat::empty() const
joeverbout 0:ea44dc9ed014 342 {
joeverbout 0:ea44dc9ed014 343 return data == 0;
joeverbout 0:ea44dc9ed014 344 }
joeverbout 0:ea44dc9ed014 345
joeverbout 0:ea44dc9ed014 346 static inline
joeverbout 0:ea44dc9ed014 347 GpuMat createContinuous(int rows, int cols, int type)
joeverbout 0:ea44dc9ed014 348 {
joeverbout 0:ea44dc9ed014 349 GpuMat m;
joeverbout 0:ea44dc9ed014 350 createContinuous(rows, cols, type, m);
joeverbout 0:ea44dc9ed014 351 return m;
joeverbout 0:ea44dc9ed014 352 }
joeverbout 0:ea44dc9ed014 353
joeverbout 0:ea44dc9ed014 354 static inline
joeverbout 0:ea44dc9ed014 355 void createContinuous(Size size, int type, OutputArray arr)
joeverbout 0:ea44dc9ed014 356 {
joeverbout 0:ea44dc9ed014 357 createContinuous(size.height, size.width, type, arr);
joeverbout 0:ea44dc9ed014 358 }
joeverbout 0:ea44dc9ed014 359
joeverbout 0:ea44dc9ed014 360 static inline
joeverbout 0:ea44dc9ed014 361 GpuMat createContinuous(Size size, int type)
joeverbout 0:ea44dc9ed014 362 {
joeverbout 0:ea44dc9ed014 363 GpuMat m;
joeverbout 0:ea44dc9ed014 364 createContinuous(size, type, m);
joeverbout 0:ea44dc9ed014 365 return m;
joeverbout 0:ea44dc9ed014 366 }
joeverbout 0:ea44dc9ed014 367
joeverbout 0:ea44dc9ed014 368 static inline
joeverbout 0:ea44dc9ed014 369 void ensureSizeIsEnough(Size size, int type, OutputArray arr)
joeverbout 0:ea44dc9ed014 370 {
joeverbout 0:ea44dc9ed014 371 ensureSizeIsEnough(size.height, size.width, type, arr);
joeverbout 0:ea44dc9ed014 372 }
joeverbout 0:ea44dc9ed014 373
joeverbout 0:ea44dc9ed014 374 static inline
joeverbout 0:ea44dc9ed014 375 void swap(GpuMat& a, GpuMat& b)
joeverbout 0:ea44dc9ed014 376 {
joeverbout 0:ea44dc9ed014 377 a.swap(b);
joeverbout 0:ea44dc9ed014 378 }
joeverbout 0:ea44dc9ed014 379
joeverbout 0:ea44dc9ed014 380 //===================================================================================
joeverbout 0:ea44dc9ed014 381 // HostMem
joeverbout 0:ea44dc9ed014 382 //===================================================================================
joeverbout 0:ea44dc9ed014 383
joeverbout 0:ea44dc9ed014 384 inline
joeverbout 0:ea44dc9ed014 385 HostMem::HostMem(AllocType alloc_type_)
joeverbout 0:ea44dc9ed014 386 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
joeverbout 0:ea44dc9ed014 387 {
joeverbout 0:ea44dc9ed014 388 }
joeverbout 0:ea44dc9ed014 389
joeverbout 0:ea44dc9ed014 390 inline
joeverbout 0:ea44dc9ed014 391 HostMem::HostMem(const HostMem& m)
joeverbout 0:ea44dc9ed014 392 : flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), alloc_type(m.alloc_type)
joeverbout 0:ea44dc9ed014 393 {
joeverbout 0:ea44dc9ed014 394 if( refcount )
joeverbout 0:ea44dc9ed014 395 CV_XADD(refcount, 1);
joeverbout 0:ea44dc9ed014 396 }
joeverbout 0:ea44dc9ed014 397
joeverbout 0:ea44dc9ed014 398 inline
joeverbout 0:ea44dc9ed014 399 HostMem::HostMem(int rows_, int cols_, int type_, AllocType alloc_type_)
joeverbout 0:ea44dc9ed014 400 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
joeverbout 0:ea44dc9ed014 401 {
joeverbout 0:ea44dc9ed014 402 if (rows_ > 0 && cols_ > 0)
joeverbout 0:ea44dc9ed014 403 create(rows_, cols_, type_);
joeverbout 0:ea44dc9ed014 404 }
joeverbout 0:ea44dc9ed014 405
joeverbout 0:ea44dc9ed014 406 inline
joeverbout 0:ea44dc9ed014 407 HostMem::HostMem(Size size_, int type_, AllocType alloc_type_)
joeverbout 0:ea44dc9ed014 408 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
joeverbout 0:ea44dc9ed014 409 {
joeverbout 0:ea44dc9ed014 410 if (size_.height > 0 && size_.width > 0)
joeverbout 0:ea44dc9ed014 411 create(size_.height, size_.width, type_);
joeverbout 0:ea44dc9ed014 412 }
joeverbout 0:ea44dc9ed014 413
joeverbout 0:ea44dc9ed014 414 inline
joeverbout 0:ea44dc9ed014 415 HostMem::HostMem(InputArray arr, AllocType alloc_type_)
joeverbout 0:ea44dc9ed014 416 : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
joeverbout 0:ea44dc9ed014 417 {
joeverbout 0:ea44dc9ed014 418 arr.getMat().copyTo(*this);
joeverbout 0:ea44dc9ed014 419 }
joeverbout 0:ea44dc9ed014 420
joeverbout 0:ea44dc9ed014 421 inline
joeverbout 0:ea44dc9ed014 422 HostMem::~HostMem()
joeverbout 0:ea44dc9ed014 423 {
joeverbout 0:ea44dc9ed014 424 release();
joeverbout 0:ea44dc9ed014 425 }
joeverbout 0:ea44dc9ed014 426
joeverbout 0:ea44dc9ed014 427 inline
joeverbout 0:ea44dc9ed014 428 HostMem& HostMem::operator =(const HostMem& m)
joeverbout 0:ea44dc9ed014 429 {
joeverbout 0:ea44dc9ed014 430 if (this != &m)
joeverbout 0:ea44dc9ed014 431 {
joeverbout 0:ea44dc9ed014 432 HostMem temp(m);
joeverbout 0:ea44dc9ed014 433 swap(temp);
joeverbout 0:ea44dc9ed014 434 }
joeverbout 0:ea44dc9ed014 435
joeverbout 0:ea44dc9ed014 436 return *this;
joeverbout 0:ea44dc9ed014 437 }
joeverbout 0:ea44dc9ed014 438
joeverbout 0:ea44dc9ed014 439 inline
joeverbout 0:ea44dc9ed014 440 void HostMem::swap(HostMem& b)
joeverbout 0:ea44dc9ed014 441 {
joeverbout 0:ea44dc9ed014 442 std::swap(flags, b.flags);
joeverbout 0:ea44dc9ed014 443 std::swap(rows, b.rows);
joeverbout 0:ea44dc9ed014 444 std::swap(cols, b.cols);
joeverbout 0:ea44dc9ed014 445 std::swap(step, b.step);
joeverbout 0:ea44dc9ed014 446 std::swap(data, b.data);
joeverbout 0:ea44dc9ed014 447 std::swap(datastart, b.datastart);
joeverbout 0:ea44dc9ed014 448 std::swap(dataend, b.dataend);
joeverbout 0:ea44dc9ed014 449 std::swap(refcount, b.refcount);
joeverbout 0:ea44dc9ed014 450 std::swap(alloc_type, b.alloc_type);
joeverbout 0:ea44dc9ed014 451 }
joeverbout 0:ea44dc9ed014 452
joeverbout 0:ea44dc9ed014 453 inline
joeverbout 0:ea44dc9ed014 454 HostMem HostMem::clone() const
joeverbout 0:ea44dc9ed014 455 {
joeverbout 0:ea44dc9ed014 456 HostMem m(size(), type(), alloc_type);
joeverbout 0:ea44dc9ed014 457 createMatHeader().copyTo(m);
joeverbout 0:ea44dc9ed014 458 return m;
joeverbout 0:ea44dc9ed014 459 }
joeverbout 0:ea44dc9ed014 460
joeverbout 0:ea44dc9ed014 461 inline
joeverbout 0:ea44dc9ed014 462 void HostMem::create(Size size_, int type_)
joeverbout 0:ea44dc9ed014 463 {
joeverbout 0:ea44dc9ed014 464 create(size_.height, size_.width, type_);
joeverbout 0:ea44dc9ed014 465 }
joeverbout 0:ea44dc9ed014 466
joeverbout 0:ea44dc9ed014 467 inline
joeverbout 0:ea44dc9ed014 468 Mat HostMem::createMatHeader() const
joeverbout 0:ea44dc9ed014 469 {
joeverbout 0:ea44dc9ed014 470 return Mat(size(), type(), data, step);
joeverbout 0:ea44dc9ed014 471 }
joeverbout 0:ea44dc9ed014 472
joeverbout 0:ea44dc9ed014 473 inline
joeverbout 0:ea44dc9ed014 474 bool HostMem::isContinuous() const
joeverbout 0:ea44dc9ed014 475 {
joeverbout 0:ea44dc9ed014 476 return (flags & Mat::CONTINUOUS_FLAG) != 0;
joeverbout 0:ea44dc9ed014 477 }
joeverbout 0:ea44dc9ed014 478
joeverbout 0:ea44dc9ed014 479 inline
joeverbout 0:ea44dc9ed014 480 size_t HostMem::elemSize() const
joeverbout 0:ea44dc9ed014 481 {
joeverbout 0:ea44dc9ed014 482 return CV_ELEM_SIZE(flags);
joeverbout 0:ea44dc9ed014 483 }
joeverbout 0:ea44dc9ed014 484
joeverbout 0:ea44dc9ed014 485 inline
joeverbout 0:ea44dc9ed014 486 size_t HostMem::elemSize1() const
joeverbout 0:ea44dc9ed014 487 {
joeverbout 0:ea44dc9ed014 488 return CV_ELEM_SIZE1(flags);
joeverbout 0:ea44dc9ed014 489 }
joeverbout 0:ea44dc9ed014 490
joeverbout 0:ea44dc9ed014 491 inline
joeverbout 0:ea44dc9ed014 492 int HostMem::type() const
joeverbout 0:ea44dc9ed014 493 {
joeverbout 0:ea44dc9ed014 494 return CV_MAT_TYPE(flags);
joeverbout 0:ea44dc9ed014 495 }
joeverbout 0:ea44dc9ed014 496
joeverbout 0:ea44dc9ed014 497 inline
joeverbout 0:ea44dc9ed014 498 int HostMem::depth() const
joeverbout 0:ea44dc9ed014 499 {
joeverbout 0:ea44dc9ed014 500 return CV_MAT_DEPTH(flags);
joeverbout 0:ea44dc9ed014 501 }
joeverbout 0:ea44dc9ed014 502
joeverbout 0:ea44dc9ed014 503 inline
joeverbout 0:ea44dc9ed014 504 int HostMem::channels() const
joeverbout 0:ea44dc9ed014 505 {
joeverbout 0:ea44dc9ed014 506 return CV_MAT_CN(flags);
joeverbout 0:ea44dc9ed014 507 }
joeverbout 0:ea44dc9ed014 508
joeverbout 0:ea44dc9ed014 509 inline
joeverbout 0:ea44dc9ed014 510 size_t HostMem::step1() const
joeverbout 0:ea44dc9ed014 511 {
joeverbout 0:ea44dc9ed014 512 return step / elemSize1();
joeverbout 0:ea44dc9ed014 513 }
joeverbout 0:ea44dc9ed014 514
joeverbout 0:ea44dc9ed014 515 inline
joeverbout 0:ea44dc9ed014 516 Size HostMem::size() const
joeverbout 0:ea44dc9ed014 517 {
joeverbout 0:ea44dc9ed014 518 return Size(cols, rows);
joeverbout 0:ea44dc9ed014 519 }
joeverbout 0:ea44dc9ed014 520
joeverbout 0:ea44dc9ed014 521 inline
joeverbout 0:ea44dc9ed014 522 bool HostMem::empty() const
joeverbout 0:ea44dc9ed014 523 {
joeverbout 0:ea44dc9ed014 524 return data == 0;
joeverbout 0:ea44dc9ed014 525 }
joeverbout 0:ea44dc9ed014 526
joeverbout 0:ea44dc9ed014 527 static inline
joeverbout 0:ea44dc9ed014 528 void swap(HostMem& a, HostMem& b)
joeverbout 0:ea44dc9ed014 529 {
joeverbout 0:ea44dc9ed014 530 a.swap(b);
joeverbout 0:ea44dc9ed014 531 }
joeverbout 0:ea44dc9ed014 532
joeverbout 0:ea44dc9ed014 533 //===================================================================================
joeverbout 0:ea44dc9ed014 534 // Stream
joeverbout 0:ea44dc9ed014 535 //===================================================================================
joeverbout 0:ea44dc9ed014 536
joeverbout 0:ea44dc9ed014 537 inline
joeverbout 0:ea44dc9ed014 538 Stream::Stream(const Ptr<Impl>& impl)
joeverbout 0:ea44dc9ed014 539 : impl_(impl)
joeverbout 0:ea44dc9ed014 540 {
joeverbout 0:ea44dc9ed014 541 }
joeverbout 0:ea44dc9ed014 542
joeverbout 0:ea44dc9ed014 543 //===================================================================================
joeverbout 0:ea44dc9ed014 544 // Event
joeverbout 0:ea44dc9ed014 545 //===================================================================================
joeverbout 0:ea44dc9ed014 546
joeverbout 0:ea44dc9ed014 547 inline
joeverbout 0:ea44dc9ed014 548 Event::Event(const Ptr<Impl>& impl)
joeverbout 0:ea44dc9ed014 549 : impl_(impl)
joeverbout 0:ea44dc9ed014 550 {
joeverbout 0:ea44dc9ed014 551 }
joeverbout 0:ea44dc9ed014 552
joeverbout 0:ea44dc9ed014 553 //===================================================================================
joeverbout 0:ea44dc9ed014 554 // Initialization & Info
joeverbout 0:ea44dc9ed014 555 //===================================================================================
joeverbout 0:ea44dc9ed014 556
joeverbout 0:ea44dc9ed014 557 inline
joeverbout 0:ea44dc9ed014 558 bool TargetArchs::has(int major, int minor)
joeverbout 0:ea44dc9ed014 559 {
joeverbout 0:ea44dc9ed014 560 return hasPtx(major, minor) || hasBin(major, minor);
joeverbout 0:ea44dc9ed014 561 }
joeverbout 0:ea44dc9ed014 562
joeverbout 0:ea44dc9ed014 563 inline
joeverbout 0:ea44dc9ed014 564 bool TargetArchs::hasEqualOrGreater(int major, int minor)
joeverbout 0:ea44dc9ed014 565 {
joeverbout 0:ea44dc9ed014 566 return hasEqualOrGreaterPtx(major, minor) || hasEqualOrGreaterBin(major, minor);
joeverbout 0:ea44dc9ed014 567 }
joeverbout 0:ea44dc9ed014 568
joeverbout 0:ea44dc9ed014 569 inline
joeverbout 0:ea44dc9ed014 570 DeviceInfo::DeviceInfo()
joeverbout 0:ea44dc9ed014 571 {
joeverbout 0:ea44dc9ed014 572 device_id_ = getDevice();
joeverbout 0:ea44dc9ed014 573 }
joeverbout 0:ea44dc9ed014 574
joeverbout 0:ea44dc9ed014 575 inline
joeverbout 0:ea44dc9ed014 576 DeviceInfo::DeviceInfo(int device_id)
joeverbout 0:ea44dc9ed014 577 {
joeverbout 0:ea44dc9ed014 578 CV_Assert( device_id >= 0 && device_id < getCudaEnabledDeviceCount() );
joeverbout 0:ea44dc9ed014 579 device_id_ = device_id;
joeverbout 0:ea44dc9ed014 580 }
joeverbout 0:ea44dc9ed014 581
joeverbout 0:ea44dc9ed014 582 inline
joeverbout 0:ea44dc9ed014 583 int DeviceInfo::deviceID() const
joeverbout 0:ea44dc9ed014 584 {
joeverbout 0:ea44dc9ed014 585 return device_id_;
joeverbout 0:ea44dc9ed014 586 }
joeverbout 0:ea44dc9ed014 587
joeverbout 0:ea44dc9ed014 588 inline
joeverbout 0:ea44dc9ed014 589 size_t DeviceInfo::freeMemory() const
joeverbout 0:ea44dc9ed014 590 {
joeverbout 0:ea44dc9ed014 591 size_t _totalMemory = 0, _freeMemory = 0;
joeverbout 0:ea44dc9ed014 592 queryMemory(_totalMemory, _freeMemory);
joeverbout 0:ea44dc9ed014 593 return _freeMemory;
joeverbout 0:ea44dc9ed014 594 }
joeverbout 0:ea44dc9ed014 595
joeverbout 0:ea44dc9ed014 596 inline
joeverbout 0:ea44dc9ed014 597 size_t DeviceInfo::totalMemory() const
joeverbout 0:ea44dc9ed014 598 {
joeverbout 0:ea44dc9ed014 599 size_t _totalMemory = 0, _freeMemory = 0;
joeverbout 0:ea44dc9ed014 600 queryMemory(_totalMemory, _freeMemory);
joeverbout 0:ea44dc9ed014 601 return _totalMemory;
joeverbout 0:ea44dc9ed014 602 }
joeverbout 0:ea44dc9ed014 603
joeverbout 0:ea44dc9ed014 604 inline
joeverbout 0:ea44dc9ed014 605 bool DeviceInfo::supports(FeatureSet feature_set) const
joeverbout 0:ea44dc9ed014 606 {
joeverbout 0:ea44dc9ed014 607 int version = majorVersion() * 10 + minorVersion();
joeverbout 0:ea44dc9ed014 608 return version >= feature_set;
joeverbout 0:ea44dc9ed014 609 }
joeverbout 0:ea44dc9ed014 610
joeverbout 0:ea44dc9ed014 611
joeverbout 0:ea44dc9ed014 612 }} // namespace cv { namespace cuda {
joeverbout 0:ea44dc9ed014 613
joeverbout 0:ea44dc9ed014 614 //===================================================================================
joeverbout 0:ea44dc9ed014 615 // Mat
joeverbout 0:ea44dc9ed014 616 //===================================================================================
joeverbout 0:ea44dc9ed014 617
joeverbout 0:ea44dc9ed014 618 namespace cv {
joeverbout 0:ea44dc9ed014 619
joeverbout 0:ea44dc9ed014 620 inline
joeverbout 0:ea44dc9ed014 621 Mat::Mat(const cuda::GpuMat& m)
joeverbout 0:ea44dc9ed014 622 : flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows)
joeverbout 0:ea44dc9ed014 623 {
joeverbout 0:ea44dc9ed014 624 m.download(*this);
joeverbout 0:ea44dc9ed014 625 }
joeverbout 0:ea44dc9ed014 626
joeverbout 0:ea44dc9ed014 627 }
joeverbout 0:ea44dc9ed014 628
joeverbout 0:ea44dc9ed014 629 //! @endcond
joeverbout 0:ea44dc9ed014 630
joeverbout 0:ea44dc9ed014 631 #endif // __OPENCV_CORE_CUDAINL_HPP__
joeverbout 0:ea44dc9ed014 632