OpenPose 1.0.0rc2 OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | List of all members
op::Array< T > Class Template Reference

`#include <array.hpp>`

## Public Member Functions
| Array (const int size)
| Array (const std::vector< int > &sizes={})
| Array (const int size, const T value)
| Array (const std::vector< int > &sizes, const T value)
| Array (const int size, T *const dataPtr)
| Array (const std::vector< int > &sizes, T *const dataPtr)
| Array (const Array< T > &array, const int index, const bool noCopy=false)
| Array (const Array< T > &array)
Array< T > & | operator= (const Array< T > &array)
| Array (Array< T > &&array)
Array< T > & | operator= (Array< T > &&array)
Array< T > | clone () const
void | reset (const int size)
void | reset (const std::vector< int > &sizes={})
void | reset (const int size, const T value)
void | reset (const std::vector< int > &sizes, const T value)
void | setFrom (const cv::Mat &cvMat)
void | setTo (const T value)
bool | empty () const
std::vector< int > | getSize () const
int | getSize (const int index) const
std::string | printSize () const
size_t | getNumberDimensions () const
size_t | getVolume () const
size_t | getVolume (const int indexA, const int indexB=-1) const
std::vector< int > | getStride () const
int | getStride (const int index) const
T * | getPtr ()
const T * | getConstPtr () const
T * | getPseudoConstPtr () const
const cv::Mat & | getConstCvMat () const
cv::Mat & | getCvMat ()
T & | operator[] (const int index)
const T & | operator[] (const int index) const
T & | operator[] (const std::vector< int > &indexes)
const T & | operator[] (const std::vector< int > &indexes) const
T & | at (const int index)
const T & | at (const int index) const
T & | at (const std::vector< int > &indexes)
const T & | at (const std::vector< int > &indexes) const
const std::string | toString () const

## Detailed Description

### template<typename T>
class op::Array< T >

Array<T>: The OpenPose Basic Raw Data Container This template class implements a multidimensional data array. It is our basic data container, analogous to cv::Mat in OpenCV, Tensor in Torch/TensorFlow or Blob in Caffe. It wraps a cv::Mat and a std::shared_ptr, both of them pointing to the same raw data. I.e. they both share the same memory, so we can read and modify this data in both formats with no performance impact. Hence, it keeps high performance while adding high-level functions.

## Constructor & Destructor Documentation

template<typename T>

op::Array< T >::Array | ( | const int | size | ) |
| explicit

Array constructor. Equivalent to default constructor + reset(const int size).

Parameters

  size | Integer with the number of T element to be allocated. E.g., size = 5 is internally similar to `new T[5]`.

template<typename T>

op::Array< T >::Array | ( | const std::vector< int > & | sizes = `{}` | ) |
| explicit

Array constructor. Equivalent to default constructor + reset(const std::vector<int>& size = {}).

Parameters

  sizes | Vector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to `new T[3*5*2]`.

template<typename T>

op::Array< T >::Array | ( | const int | size,
|  | const T | value
| ) |  |

Array constructor. Equivalent to default constructor + reset(const int size, const T value).

Parameters

  size | Integer with the number of T element to be allocated. E.g., size = 5 is internally similar to `new T[5]`.
  value | Initial value for each component of the Array.

template<typename T>

op::Array< T >::Array | ( | const std::vector< int > & | sizes,
|  | const T | value
| ) |  |

Array constructor. Equivalent to default constructor + reset(const std::vector<int>& size, const T value).

Parameters

  sizes | Vector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to: `new T[3*5*2]`.
  value | Initial value for each component of the Array.

template<typename T>

op::Array< T >::Array | ( | const int | size,
|  | T *const | dataPtr
| ) |  |

Array constructor. Equivalent to default constructor, but it does not allocate memory, but rather use dataPtr.

Parameters

  size | Integer with the number of T element to be allocated. E.g., size = 5 is internally similar to `new T[5]`.
  dataPtr | Pointer to the memory to be used by the Array.

template<typename T>

op::Array< T >::Array | ( | const std::vector< int > & | sizes,
|  | T *const | dataPtr
| ) |  |

Array constructor. Equivalent to default constructor, but it does not allocate memory, but rather use dataPtr.

Parameters

  sizes | Vector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to: `new T[3*5*2]`.
  dataPtr | Pointer to the memory to be used by the Array.

template<typename T>

op::Array< T >::Array | ( | const Array< T > & | array,
|  | const int | index,
|  | const bool | noCopy = `false`
| ) |  |

Array constructor.

Parameters

  array | Array<T> with the original data array to slice.
  index | indicates the index of the array to extract.
  noCopy | indicates whether to perform a copy. Copy will never go to undefined behavior, however, if noCopy == true, then: It is faster, as no data copy is involved, but... If the Array array goes out of scope, then the resulting Array will provoke an undefined behavior. If the returned Array is modified, the information in the Array array will also be.

Returns
  Array<T> with the same dimension than array expect the first dimension being 1. E.g., if array is {p,k,m}, the resulting Array<T> is {1,k,m}.

template<typename T>

op::Array< T >::Array | ( | const Array< T > & | array | ) |

Copy constructor. It performs `fast copy`: For performance purpose, copying a Array<T> or Datum or cv::Mat just copies the reference, it still shares the same internal data. Modifying the copied element will modify the original one. Use clone() for a slower but real copy, similarly to cv::Mat and Array<T>.

Parameters

  array | Array to be copied.

template<typename T>

op::Array< T >::Array | ( | Array< T > && | array | ) |

Move constructor. It destroys the original Array to be moved.

Parameters

  array | Array to be moved.

## Member Function Documentation

template<typename T>

T& op::Array< T >::at | ( | const int | index | ) |
| inline

at() function Same functionality as operator[](const int index), but it always check whether the indexes are within the data bounds. Otherwise, it will throw an error.

Parameters

  index | The desired memory location.

Returns
  A editable reference to the data on the desired index location.

template<typename T>

const T& op::Array< T >::at | ( | const int | index | ) | const
| inline

at() function Same functionality as operator[](const int index) const, but it always check whether the indexes are within the data bounds. Otherwise, it will throw an error.

Parameters

  index | The desired memory location.

Returns
  A non-editable reference to the data on the desired index location.

template<typename T>

T& op::Array< T >::at | ( | const std::vector< int > & | indexes | ) |
| inline

at() function Same functionality as operator[](const std::vector<int>& indexes), but it always check whether the indexes are within the data bounds. Otherwise, it will throw an error.

Parameters

  indexes | Vector with the desired memory location.

Returns
  A editable reference to the data on the desired index location.

template<typename T>

const T& op::Array< T >::at | ( | const std::vector< int > & | indexes | ) | const
| inline

at() function Same functionality as operator[](const std::vector<int>& indexes) const, but it always check whether the indexes are within the data bounds. Otherwise, it will throw an error.

Parameters

  indexes | Vector with the desired memory location.

Returns
  A non-editable reference to the data on the desired index location.

template<typename T>

Array<T> op::Array< T >::clone | ( |  | ) | const

Clone function. Similar to cv::Mat::clone and Datum::clone. It performs a real but slow copy of the data, i.e., even if the copied element is modified, the original one is not.

Returns
  The resulting Array.

template<typename T>

bool op::Array< T >::empty | ( |  | ) | const
| inline

Check whether memory has been allocated.

Returns
  True if no memory has been allocated, false otherwise.

template<typename T>

const cv::Mat& op::Array< T >::getConstCvMat | ( |  | ) | const

Return a cv::Mat wrapper to the data. It forbids the data to be modified. OpenCV only admits unsigned char, signed char, int, float & double. If the T class is not supported by OpenCV, it will throw an error. Note: Array<T> does not return an editable cv::Mat because some OpenCV functions reallocate memory and it would not longer point to the Array<T> instance. If you want to perform some OpenCV operation on the Array data, you can use: editedCvMat = array.getConstCvMat().clone(); // modify data array.setFrom(editedCvMat)

Returns
  A const cv::Mat pointing to the data.

template<typename T>

const T* op::Array< T >::getConstPtr | ( |  | ) | const
| inline

Similar to getPtr(), but it forbids the data to be edited.

Returns
  A raw const pointer to the data.

template<typename T>

cv::Mat& op::Array< T >::getCvMat | ( |  | ) |

Analogous to getConstCvMat, but in this case it returns a editable cv::Mat. Very important: Only allowed functions which do not provoke data reallocation. E.g., resizing functions will not work and they would provoke an undefined behaviour and/or execution crashes.

Returns
  A cv::Mat pointing to the data.

template<typename T>

size_t op::Array< T >::getNumberDimensions | ( |  | ) | const
| inline

Return the total number of dimensions, equivalent to getSize().size().

Returns
  The number of dimensions. If no memory is allocated, it returns 0.

template<typename T>

T* op::Array< T >::getPseudoConstPtr | ( |  | ) | const
| inline

Similar to getConstPtr(), but it allows the data to be edited. This function is only implemented for Pybind11 usage.

Returns
  A raw pointer to the data.

template<typename T>

T* op::Array< T >::getPtr | ( |  | ) |
| inline

Return a raw pointer to the data. Similar to: std::shared_ptr::get(). Note: if you modify the pointer data, you will directly modify it in the Array<T> instance too. If you know you do not want to modify the data, then use getConstPtr() instead.

Returns
  A raw pointer to the data.

template<typename T>

std::vector<int> op::Array< T >::getSize | ( |  | ) | const
| inline

Return a vector with the size of each dimension allocated.

Returns
  A std::vector<int> with the size of each dimension. If no memory has been allocated, it will return an empty std::vector.

template<typename T>

int op::Array< T >::getSize | ( | const int | index | ) | const

Return a vector with the size of the desired dimension.

Parameters

  index | Dimension to check its size.

Returns
  Size of the desired dimension. It will return 0 if the requested dimension is higher than the number of dimensions.

template<typename T>

std::vector<int> op::Array< T >::getStride | ( |  | ) | const

Return the stride or step size of the array. E.g., given and Array<T> of size 5x3, getStride() would return the following vector: {5x3sizeof(T), 3sizeof(T), sizeof(T)}.

template<typename T>

int op::Array< T >::getStride | ( | const int | index | ) | const

Return the stride or step size of the array at the index-th dimension. E.g., given and Array<T> of size 5x3, getStride(2) would return sizeof(T).

template<typename T>

size_t op::Array< T >::getVolume | ( |  | ) | const
| inline

Return the total number of elements allocated, equivalent to multiply all the components from getSize(). E.g., for a Array<T> of size = {2,5,3}, the volume or total number of elements is: 2x5x3 = 30.

Returns
  The total volume of the allocated data. If no memory is allocated, it returns 0.

template<typename T>

size_t op::Array< T >::getVolume | ( | const int | indexA,
|  | const int | indexB = `-1`
| ) |  | const

Similar to getVolume(), but in this case it just returns the volume between the desired dimensions. E.g., for a Array<T> of size = {2,5,3}, the volume or total number of elements for getVolume(1,2) is 5x3 = 15.

Parameters

  indexA | Dimension where to start.
  indexB | Dimension where to stop. If indexB == -1, then it will take up to the last dimension.

Returns
  The total volume of the allocated data between the desired dimensions. If the index are out of bounds, it throws an error.

template<typename T>

Array<T>& op::Array< T >::operator= | ( | const Array< T > & | array | ) |

Copy assignment. Similar to Array<T>(const Array<T>& array).

Parameters

  array | Array to be copied.

Returns
  The resulting Array.

template<typename T>

Array<T>& op::Array< T >::operator= | ( | Array< T > && | array | ) |

Move assignment. Similar to Array<T>(Array<T>&& array).

Parameters

  array | Array to be moved.

Returns
  The resulting Array.

template<typename T>

T& op::Array< T >::operator[] | ( | const int | index | ) |
| inline

[] operator Similar to the [] operator for raw pointer data. If debug mode is enabled, then it will check that the desired index is in the data range, and it will throw an exception otherwise (similar to the at operator).

Parameters

  index | The desired memory location.

Returns
  A editable reference to the data on the desired index location.

template<typename T>

const T& op::Array< T >::operator[] | ( | const int | index | ) | const
| inline

[] operator Same functionality as operator[](const int index), but it forbids modifying the value. Otherwise, const functions would not be able to call the [] operator.

Parameters

  index | The desired memory location.

Returns
  A non-editable reference to the data on the desired index location.

template<typename T>

T& op::Array< T >::operator[] | ( | const std::vector< int > & | indexes | ) |
| inline

[] operator Same functionality as operator[](const int index), but it lets the user introduce the multi-dimensional index. E.g., given a (10 x 10 x 10) array, array[11] is equivalent to array[{1,1,0}]

Parameters

  indexes | Vector with the desired memory location.

Returns
  A editable reference to the data on the desired index location.

template<typename T>

const T& op::Array< T >::operator[] | ( | const std::vector< int > & | indexes | ) | const
| inline

[] operator Same functionality as operator[](const std::vector<int>& indexes), but it forbids modifying the value. Otherwise, const functions would not be able to call the [] operator.

Parameters

  indexes | Vector with the desired memory location.

Returns
  A non-editable reference to the data on the desired index location.

template<typename T>

std::string op::Array< T >::printSize | ( |  | ) | const

Return a string with the size of each dimension allocated.

Returns
  A std::stringwith the size of each dimension. If no memory has been allocated, it will return an empty string.

template<typename T>

void op::Array< T >::reset | ( | const int | size | ) |

Data allocation function. It allocates the required space for the memory (it does not initialize that memory).

Parameters

  size | Integer with the number of T element to be allocated. E.g., size = 5 is internally similar to `new T[5]`.

template<typename T>

void op::Array< T >::reset | ( | const std::vector< int > & | sizes = `{}` | ) |

Data allocation function. Similar to reset(const int size), but it allocates a multi-dimensional array of dimensions each of the values of the argument.

Parameters

  sizes | Vector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to `new T[3*5*2]`.

template<typename T>

void op::Array< T >::reset | ( | const int | size,
|  | const T | value
| ) |  |

Data allocation function. Similar to reset(const int size), but initializing the data to the value specified by the second argument.

Parameters

  size | Integer with the number of T element to be allocated. E.g., size = 5 is internally similar to `new T[5]`.
  value | Initial value for each component of the Array.

template<typename T>

void op::Array< T >::reset | ( | const std::vector< int > & | sizes,
|  | const T | value
| ) |  |

Data allocation function. Similar to reset(const std::vector<int>& size), but initializing the data to the value specified by the second argument.

Parameters

  sizes | Vector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to `new T[3*5*2]`.
  value | Initial value for each component of the Array.

template<typename T>

void op::Array< T >::setFrom | ( | const cv::Mat & | cvMat | ) |

Data allocation function. It internally allocates memory and copies the data of the argument to the Array allocated memory.

Parameters

  cvMat | cv::Mat to be copied.

template<typename T>

void op::Array< T >::setTo | ( | const T | value | ) |

Data allocation function. It internally assigns all the allocated memory to the value indicated by the argument.

Parameters

  value | Value for each component of the Array.

template<typename T>

const std::string op::Array< T >::toString | ( |  | ) | const

It returns a string with the whole array data. Useful for debugging. The format is: values separated by a space, and a enter for each dimension. E.g., For the Array{2, 2, 3}, it will print: Array<T>::toString(): x1 x2 x3 x4 x5 x6

x7 x8 x9 x10 x11 x12

Returns
  A string with the array values in the above format.

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

- /home/travis/build/CMU-Perceptual-Computing-Lab/openpose/include/openpose/core/array.hpp