OpenCV  3.2.0
Open Source Computer Vision
Public Types | Public Member Functions | Static Public Member Functions | List of all members
cv::dnn::Blob Class Reference

This class provides methods for continuous n-dimensional CPU and GPU array processing. More...

#include "blob.hpp"

Public Types

enum  AllocFlag {
  ALLOC_MAT = HEAD_AT_MAT,
  ALLOC_UMAT = HEAD_AT_UMAT,
  ALLOC_BOTH = SYNCED
}
 
enum  DataState {
  UNINITIALIZED = 0,
  HEAD_AT_MAT = 1 << 0,
  HEAD_AT_UMAT = 1 << 1,
  SYNCED = HEAD_AT_MAT | HEAD_AT_UMAT
}
 

Public Member Functions

 Blob ()
 
 Blob (const BlobShape &shape, int type=CV_32F, int allocFlags=ALLOC_MAT)
 Constructs blob with specified shape and type. More...
 
 Blob (InputArray data)
 Constructs Blob from existing Mat or UMat. More...
 
void batchFromImages (InputArray image, int dstCn=-1)
 Works like Blob::fromImages() but in-place. More...
 
int canonicalAxis (int axis) const
 Converts axis index to canonical format (where 0 <= axis < dims()). More...
 
int channels () const
 Returns size of the second axis blob. More...
 
int cols () const
 Returns size of the fourth axis blob. More...
 
void create (const BlobShape &shape, int type=CV_32F, int allocFlags=ALLOC_MAT)
 Creates blob with specified shape and type. More...
 
int dims () const
 Returns number of blob dimensions. More...
 
int elemSize () const
 Returns size of single element in bytes. More...
 
bool equalShape (const Blob &other) const
 Checks equality of two blobs shapes. More...
 
void fill (InputArray in)
 Creates blob from Mat or UMat without copying the data. More...
 
void fill (const BlobShape &shape, int type, void *data, bool deepCopy=true)
 Creates blob from user data. More...
 
Mat getPlane (int n, int cn)
 Returns slice of first two dimensions. More...
 
Mat getPlanes (int n)
 Returns slice of first dimension. More...
 
template<typename XMat >
XMat & getRef (bool writeOnly=true)
 
template<typename XMat >
const XMat & getRefConst () const
 
int getState () const
 Returns current state of the blob,. More...
 
MatmatRef (bool writeOnly=true)
 Returns reference to cv::Mat, containing blob data. More...
 
const MatmatRefConst () const
 Returns reference to cv::Mat, containing blob data, for read-only purposes. More...
 
int num () const
 Returns size of the first axis blob. More...
 
template<int n>
size_t offset (const Vec< int, n > &pos) const
 Returns linear index of the element with specified coordinates in the blob. More...
 
size_t offset (int n=0, int cn=0, int row=0, int col=0) const
 
ucharptr (int n=0, int cn=0, int row=0, int col=0)
 Returns pointer to the blob element with the specified position, stored in CPU memory. More...
 
template<typename Type >
Type * ptr (int n=0, int cn=0, int row=0, int col=0)
 
float * ptrf (int n=0, int cn=0, int row=0, int col=0)
 
Blobreshape (const BlobShape &shape)
 Changes shape of the blob without copying the data. More...
 
Blob reshaped (const BlobShape &newShape) const
 Changes shape of the blob without copying the data. More...
 
int rows () const
 Returns size of the thrid axis blob. More...
 
void setTo (InputArray value, int allocFlags=-1)
 Sets value to the last used data (if allocFlags = -1). More...
 
BlobShape shape () const
 Returns shape of the blob. More...
 
Vec4i shape4 () const
 Returns shape of first four blob axes. More...
 
BlobshareFrom (const Blob &blob)
 Shares data from other blob. More...
 
int size (int axis) const
 Returns the size of the specified axis. More...
 
Size size2 () const
 Returns cv::Size(cols(), rows()) More...
 
void sync () const
 Updates Mat and UMat of Blob. More...
 
size_t total (int startAxis=0, int endAxis=INT_MAX) const
 Computes the product of sizes of axes among the specified axes range [startAxis; endAxis). More...
 
int type () const
 Returns type of the blob. More...
 
UMatumatRef (bool writeOnly=true)
 Returns reference to cv::UMat, containing blob data. More...
 
const UMatumatRefConst () const
 Returns reference to cv::UMat, containing blob data, for read-only purposes. More...
 
void updateMat (bool syncData=true) const
 Actualizes data stored inside Mat of Blob; if syncData is false then only shape will be actualized. More...
 
void updateUMat (bool syncData=true) const
 Actualizes data stored inside Mat of Blob; if syncData is false then only shape will be actualized. More...
 
int xsize (int axis) const
 Returns the size of the specified axis. More...
 

Static Public Member Functions

static Blob fromImages (InputArray image, int dstCn=-1)
 Constructs 4-dimensional blob (so-called batch) from image or array of images. More...
 

Detailed Description

This class provides methods for continuous n-dimensional CPU and GPU array processing.

The class is realized as a wrapper over cv::Mat and cv::UMat. It will support methods for switching and logical synchronization between CPU and GPU.

Member Enumeration Documentation

§ AllocFlag

Enumerator
ALLOC_MAT 
ALLOC_UMAT 
ALLOC_BOTH 

§ DataState

Enumerator
UNINITIALIZED 
HEAD_AT_MAT 
HEAD_AT_UMAT 
SYNCED 

Constructor & Destructor Documentation

§ Blob() [1/3]

cv::dnn::Blob::Blob ( )

§ Blob() [2/3]

cv::dnn::Blob::Blob ( const BlobShape shape,
int  type = CV_32F,
int  allocFlags = ALLOC_MAT 
)
explicit

Constructs blob with specified shape and type.

§ Blob() [3/3]

cv::dnn::Blob::Blob ( InputArray  data)

Constructs Blob from existing Mat or UMat.

Member Function Documentation

§ batchFromImages()

void cv::dnn::Blob::batchFromImages ( InputArray  image,
int  dstCn = -1 
)

Works like Blob::fromImages() but in-place.

§ canonicalAxis()

int cv::dnn::Blob::canonicalAxis ( int  axis) const

Converts axis index to canonical format (where 0 <= axis < dims()).

§ channels()

int cv::dnn::Blob::channels ( ) const

Returns size of the second axis blob.

§ cols()

int cv::dnn::Blob::cols ( ) const

Returns size of the fourth axis blob.

§ create()

void cv::dnn::Blob::create ( const BlobShape shape,
int  type = CV_32F,
int  allocFlags = ALLOC_MAT 
)

Creates blob with specified shape and type.

§ dims()

int cv::dnn::Blob::dims ( ) const

Returns number of blob dimensions.

§ elemSize()

int cv::dnn::Blob::elemSize ( ) const

Returns size of single element in bytes.

§ equalShape()

bool cv::dnn::Blob::equalShape ( const Blob other) const

Checks equality of two blobs shapes.

§ fill() [1/2]

void cv::dnn::Blob::fill ( InputArray  in)

Creates blob from Mat or UMat without copying the data.

If in is Mat then Mat data is populated, otherwise - UMat.

§ fill() [2/2]

void cv::dnn::Blob::fill ( const BlobShape shape,
int  type,
void *  data,
bool  deepCopy = true 
)

Creates blob from user data.

If deepCopy is false then CPU data will not be allocated.

§ fromImages()

static Blob cv::dnn::Blob::fromImages ( InputArray  image,
int  dstCn = -1 
)
static

Constructs 4-dimensional blob (so-called batch) from image or array of images.

Parameters
image2-dimensional multi-channel or 3-dimensional single-channel image (or array of such images)
dstCnspecifies size of second axis of ouptut blob

§ getPlane()

Mat cv::dnn::Blob::getPlane ( int  n,
int  cn 
)

Returns slice of first two dimensions.

The behaviour is similar to the following numpy code: blob[n, cn, ...]

§ getPlanes()

Mat cv::dnn::Blob::getPlanes ( int  n)

Returns slice of first dimension.

The behaviour is similar to getPlane(), but returns all channels * rows * cols values, corresponding to the n-th value of the first dimension.

§ getRef()

template<typename XMat >
XMat& cv::dnn::Blob::getRef ( bool  writeOnly = true)

§ getRefConst()

template<typename XMat >
const XMat& cv::dnn::Blob::getRefConst ( ) const

§ getState()

int cv::dnn::Blob::getState ( ) const

Returns current state of the blob,.

See also
DataState.

§ matRef()

Mat& cv::dnn::Blob::matRef ( bool  writeOnly = true)

Returns reference to cv::Mat, containing blob data.

§ matRefConst()

const Mat& cv::dnn::Blob::matRefConst ( ) const

Returns reference to cv::Mat, containing blob data, for read-only purposes.

§ num()

int cv::dnn::Blob::num ( ) const

Returns size of the first axis blob.

§ offset() [1/2]

template<int n>
size_t cv::dnn::Blob::offset ( const Vec< int, n > &  pos) const

Returns linear index of the element with specified coordinates in the blob.

If n < dims() then unspecified coordinates will be filled by zeros. If n > dims() then extra coordinates will be ignored.

§ offset() [2/2]

size_t cv::dnn::Blob::offset ( int  n = 0,
int  cn = 0,
int  row = 0,
int  col = 0 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

§ ptr() [1/2]

uchar* cv::dnn::Blob::ptr ( int  n = 0,
int  cn = 0,
int  row = 0,
int  col = 0 
)

Returns pointer to the blob element with the specified position, stored in CPU memory.

n correspond to the first axis, cn - to the second, etc. If dims() > 4 then unspecified coordinates will be filled by zeros. If dims() < 4 then extra coordinates will be ignored.

§ ptr() [2/2]

template<typename Type >
Type* cv::dnn::Blob::ptr ( int  n = 0,
int  cn = 0,
int  row = 0,
int  col = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

§ ptrf()

float* cv::dnn::Blob::ptrf ( int  n = 0,
int  cn = 0,
int  row = 0,
int  col = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

§ reshape()

Blob& cv::dnn::Blob::reshape ( const BlobShape shape)

Changes shape of the blob without copying the data.

Returns
*this

§ reshaped()

Blob cv::dnn::Blob::reshaped ( const BlobShape newShape) const

Changes shape of the blob without copying the data.

Returns
shallow copy of original blob with new shape.

§ rows()

int cv::dnn::Blob::rows ( ) const

Returns size of the thrid axis blob.

§ setTo()

void cv::dnn::Blob::setTo ( InputArray  value,
int  allocFlags = -1 
)

Sets value to the last used data (if allocFlags = -1).

If allocFlags != -1 then destination data (Mat or UMat) is determined by flags from AllocFlag enum like in create().

§ shape()

BlobShape cv::dnn::Blob::shape ( ) const

Returns shape of the blob.

§ shape4()

Vec4i cv::dnn::Blob::shape4 ( ) const

Returns shape of first four blob axes.

§ shareFrom()

Blob& cv::dnn::Blob::shareFrom ( const Blob blob)

Shares data from other blob.

Returns
*this

§ size()

int cv::dnn::Blob::size ( int  axis) const

Returns the size of the specified axis.

Negative axis is supported, in this case a counting starts from the last axis, i. e. -1 corresponds to last axis. If non-existing axis was passed then an error will be generated.

§ size2()

Size cv::dnn::Blob::size2 ( ) const

Returns cv::Size(cols(), rows())

§ sync()

void cv::dnn::Blob::sync ( ) const

Updates Mat and UMat of Blob.

§ total()

size_t cv::dnn::Blob::total ( int  startAxis = 0,
int  endAxis = INT_MAX 
) const

Computes the product of sizes of axes among the specified axes range [startAxis; endAxis).

Parameters
startAxisthe first axis to include in the range.
endAxisthe first axis to exclude from the range.

Negative axis indexing can be used.

§ type()

int cv::dnn::Blob::type ( ) const

Returns type of the blob.

§ umatRef()

UMat& cv::dnn::Blob::umatRef ( bool  writeOnly = true)

Returns reference to cv::UMat, containing blob data.

§ umatRefConst()

const UMat& cv::dnn::Blob::umatRefConst ( ) const

Returns reference to cv::UMat, containing blob data, for read-only purposes.

§ updateMat()

void cv::dnn::Blob::updateMat ( bool  syncData = true) const

Actualizes data stored inside Mat of Blob; if syncData is false then only shape will be actualized.

§ updateUMat()

void cv::dnn::Blob::updateUMat ( bool  syncData = true) const

Actualizes data stored inside Mat of Blob; if syncData is false then only shape will be actualized.

§ xsize()

int cv::dnn::Blob::xsize ( int  axis) const

Returns the size of the specified axis.

Does the same thing as size(int) const, but if non-existing axis will be passed then 1 will be returned, therefore this function always finishes successfully.


The documentation for this class was generated from the following file: