| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631 | /*M///////////////////////////////////////////////////////////////////////////////////////////  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.////  By downloading, copying, installing or using the software you agree to this license.//  If you do not agree to this license, do not download, install,//  copy or use the software.//////                          License Agreement//                For Open Source Computer Vision Library//// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.// Copyright (C) 2009, Willow Garage Inc., all rights reserved.// Copyright (C) 2013, OpenCV Foundation, all rights reserved.// Third party copyrights are property of their respective owners.//// Redistribution and use in source and binary forms, with or without modification,// are permitted provided that the following conditions are met:////   * Redistribution's of source code must retain the above copyright notice,//     this list of conditions and the following disclaimer.////   * Redistribution's in binary form must reproduce the above copyright notice,//     this list of conditions and the following disclaimer in the documentation//     and/or other materials provided with the distribution.////   * The name of the copyright holders may not be used to endorse or promote products//     derived from this software without specific prior written permission.//// This software is provided by the copyright holders and contributors "as is" and// any express or implied warranties, including, but not limited to, the implied// warranties of merchantability and fitness for a particular purpose are disclaimed.// In no event shall the Intel Corporation or contributors be liable for any direct,// indirect, incidental, special, exemplary, or consequential damages// (including, but not limited to, procurement of substitute goods or services;// loss of use, data, or profits; or business interruption) however caused// and on any theory of liability, whether in contract, strict liability,// or tort (including negligence or otherwise) arising in any way out of// the use of this software, even if advised of the possibility of such damage.////M*/#ifndef OPENCV_CORE_CUDAINL_HPP#define OPENCV_CORE_CUDAINL_HPP#include "opencv2/core/cuda.hpp"//! @cond IGNOREDnamespace cv { namespace cuda {//===================================================================================// GpuMat//===================================================================================inlineGpuMat::GpuMat(Allocator* allocator_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_){}inlineGpuMat::GpuMat(int rows_, int cols_, int type_, Allocator* allocator_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_){    if (rows_ > 0 && cols_ > 0)        create(rows_, cols_, type_);}inlineGpuMat::GpuMat(Size size_, int type_, Allocator* allocator_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_){    if (size_.height > 0 && size_.width > 0)        create(size_.height, size_.width, type_);}inlineGpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_, Allocator* allocator_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_){    if (rows_ > 0 && cols_ > 0)    {        create(rows_, cols_, type_);        setTo(s_);    }}inlineGpuMat::GpuMat(Size size_, int type_, Scalar s_, Allocator* allocator_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_){    if (size_.height > 0 && size_.width > 0)    {        create(size_.height, size_.width, type_);        setTo(s_);    }}inlineGpuMat::GpuMat(const GpuMat& m)    : 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){    if (refcount)        CV_XADD(refcount, 1);}inlineGpuMat::GpuMat(InputArray arr, Allocator* allocator_) :    flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_){    upload(arr);}inlineGpuMat::~GpuMat(){    release();}inlineGpuMat& GpuMat::operator =(const GpuMat& m){    if (this != &m)    {        GpuMat temp(m);        swap(temp);    }    return *this;}inlinevoid GpuMat::create(Size size_, int type_){    create(size_.height, size_.width, type_);}inlinevoid GpuMat::swap(GpuMat& b){    std::swap(flags, b.flags);    std::swap(rows, b.rows);    std::swap(cols, b.cols);    std::swap(step, b.step);    std::swap(data, b.data);    std::swap(datastart, b.datastart);    std::swap(dataend, b.dataend);    std::swap(refcount, b.refcount);    std::swap(allocator, b.allocator);}inlineGpuMat GpuMat::clone() const{    GpuMat m;    copyTo(m);    return m;}inlinevoid GpuMat::copyTo(OutputArray dst, InputArray mask) const{    copyTo(dst, mask, Stream::Null());}inlineGpuMat& GpuMat::setTo(Scalar s){    return setTo(s, Stream::Null());}inlineGpuMat& GpuMat::setTo(Scalar s, InputArray mask){    return setTo(s, mask, Stream::Null());}inlinevoid GpuMat::convertTo(OutputArray dst, int rtype) const{    convertTo(dst, rtype, Stream::Null());}inlinevoid GpuMat::convertTo(OutputArray dst, int rtype, double alpha, double beta) const{    convertTo(dst, rtype, alpha, beta, Stream::Null());}inlinevoid GpuMat::convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const{    convertTo(dst, rtype, alpha, 0.0, stream);}inlinevoid GpuMat::assignTo(GpuMat& m, int _type) const{    if (_type < 0)        m = *this;    else        convertTo(m, _type);}inlineuchar* GpuMat::ptr(int y){    CV_DbgAssert( (unsigned)y < (unsigned)rows );    return data + step * y;}inlineconst uchar* GpuMat::ptr(int y) const{    CV_DbgAssert( (unsigned)y < (unsigned)rows );    return data + step * y;}template<typename _Tp> inline_Tp* GpuMat::ptr(int y){    return (_Tp*)ptr(y);}template<typename _Tp> inlineconst _Tp* GpuMat::ptr(int y) const{    return (const _Tp*)ptr(y);}template <class T> inlineGpuMat::operator PtrStepSz<T>() const{    return PtrStepSz<T>(rows, cols, (T*)data, step);}template <class T> inlineGpuMat::operator PtrStep<T>() const{    return PtrStep<T>((T*)data, step);}inlineGpuMat GpuMat::row(int y) const{    return GpuMat(*this, Range(y, y+1), Range::all());}inlineGpuMat GpuMat::col(int x) const{    return GpuMat(*this, Range::all(), Range(x, x+1));}inlineGpuMat GpuMat::rowRange(int startrow, int endrow) const{    return GpuMat(*this, Range(startrow, endrow), Range::all());}inlineGpuMat GpuMat::rowRange(Range r) const{    return GpuMat(*this, r, Range::all());}inlineGpuMat GpuMat::colRange(int startcol, int endcol) const{    return GpuMat(*this, Range::all(), Range(startcol, endcol));}inlineGpuMat GpuMat::colRange(Range r) const{    return GpuMat(*this, Range::all(), r);}inlineGpuMat GpuMat::operator ()(Range rowRange_, Range colRange_) const{    return GpuMat(*this, rowRange_, colRange_);}inlineGpuMat GpuMat::operator ()(Rect roi) const{    return GpuMat(*this, roi);}inlinebool GpuMat::isContinuous() const{    return (flags & Mat::CONTINUOUS_FLAG) != 0;}inlinesize_t GpuMat::elemSize() const{    return CV_ELEM_SIZE(flags);}inlinesize_t GpuMat::elemSize1() const{    return CV_ELEM_SIZE1(flags);}inlineint GpuMat::type() const{    return CV_MAT_TYPE(flags);}inlineint GpuMat::depth() const{    return CV_MAT_DEPTH(flags);}inlineint GpuMat::channels() const{    return CV_MAT_CN(flags);}inlinesize_t GpuMat::step1() const{    return step / elemSize1();}inlineSize GpuMat::size() const{    return Size(cols, rows);}inlinebool GpuMat::empty() const{    return data == 0;}static inlineGpuMat createContinuous(int rows, int cols, int type){    GpuMat m;    createContinuous(rows, cols, type, m);    return m;}static inlinevoid createContinuous(Size size, int type, OutputArray arr){    createContinuous(size.height, size.width, type, arr);}static inlineGpuMat createContinuous(Size size, int type){    GpuMat m;    createContinuous(size, type, m);    return m;}static inlinevoid ensureSizeIsEnough(Size size, int type, OutputArray arr){    ensureSizeIsEnough(size.height, size.width, type, arr);}static inlinevoid swap(GpuMat& a, GpuMat& b){    a.swap(b);}//===================================================================================// HostMem//===================================================================================inlineHostMem::HostMem(AllocType alloc_type_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_){}inlineHostMem::HostMem(const HostMem& m)    : 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){    if( refcount )        CV_XADD(refcount, 1);}inlineHostMem::HostMem(int rows_, int cols_, int type_, AllocType alloc_type_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_){    if (rows_ > 0 && cols_ > 0)        create(rows_, cols_, type_);}inlineHostMem::HostMem(Size size_, int type_, AllocType alloc_type_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_){    if (size_.height > 0 && size_.width > 0)        create(size_.height, size_.width, type_);}inlineHostMem::HostMem(InputArray arr, AllocType alloc_type_)    : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_){    arr.getMat().copyTo(*this);}inlineHostMem::~HostMem(){    release();}inlineHostMem& HostMem::operator =(const HostMem& m){    if (this != &m)    {        HostMem temp(m);        swap(temp);    }    return *this;}inlinevoid HostMem::swap(HostMem& b){    std::swap(flags, b.flags);    std::swap(rows, b.rows);    std::swap(cols, b.cols);    std::swap(step, b.step);    std::swap(data, b.data);    std::swap(datastart, b.datastart);    std::swap(dataend, b.dataend);    std::swap(refcount, b.refcount);    std::swap(alloc_type, b.alloc_type);}inlineHostMem HostMem::clone() const{    HostMem m(size(), type(), alloc_type);    createMatHeader().copyTo(m);    return m;}inlinevoid HostMem::create(Size size_, int type_){    create(size_.height, size_.width, type_);}inlineMat HostMem::createMatHeader() const{    return Mat(size(), type(), data, step);}inlinebool HostMem::isContinuous() const{    return (flags & Mat::CONTINUOUS_FLAG) != 0;}inlinesize_t HostMem::elemSize() const{    return CV_ELEM_SIZE(flags);}inlinesize_t HostMem::elemSize1() const{    return CV_ELEM_SIZE1(flags);}inlineint HostMem::type() const{    return CV_MAT_TYPE(flags);}inlineint HostMem::depth() const{    return CV_MAT_DEPTH(flags);}inlineint HostMem::channels() const{    return CV_MAT_CN(flags);}inlinesize_t HostMem::step1() const{    return step / elemSize1();}inlineSize HostMem::size() const{    return Size(cols, rows);}inlinebool HostMem::empty() const{    return data == 0;}static inlinevoid swap(HostMem& a, HostMem& b){    a.swap(b);}//===================================================================================// Stream//===================================================================================inlineStream::Stream(const Ptr<Impl>& impl)    : impl_(impl){}//===================================================================================// Event//===================================================================================inlineEvent::Event(const Ptr<Impl>& impl)    : impl_(impl){}//===================================================================================// Initialization & Info//===================================================================================inlinebool TargetArchs::has(int major, int minor){    return hasPtx(major, minor) || hasBin(major, minor);}inlinebool TargetArchs::hasEqualOrGreater(int major, int minor){    return hasEqualOrGreaterPtx(major, minor) || hasEqualOrGreaterBin(major, minor);}inlineDeviceInfo::DeviceInfo(){    device_id_ = getDevice();}inlineDeviceInfo::DeviceInfo(int device_id){    CV_Assert( device_id >= 0 && device_id < getCudaEnabledDeviceCount() );    device_id_ = device_id;}inlineint DeviceInfo::deviceID() const{    return device_id_;}inlinesize_t DeviceInfo::freeMemory() const{    size_t _totalMemory = 0, _freeMemory = 0;    queryMemory(_totalMemory, _freeMemory);    return _freeMemory;}inlinesize_t DeviceInfo::totalMemory() const{    size_t _totalMemory = 0, _freeMemory = 0;    queryMemory(_totalMemory, _freeMemory);    return _totalMemory;}inlinebool DeviceInfo::supports(FeatureSet feature_set) const{    int version = majorVersion() * 10 + minorVersion();    return version >= feature_set;}}} // namespace cv { namespace cuda {//===================================================================================// Mat//===================================================================================namespace cv {inlineMat::Mat(const cuda::GpuMat& m)    : flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows){    m.download(*this);}}//! @endcond#endif // OPENCV_CORE_CUDAINL_HPP
 |