OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
matrix.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_CORE_MAT_HPP
2 #define OPENPOSE_CORE_MAT_HPP
3 
4 #include <memory> // std::shared_ptr
6 
7 namespace op
8 {
9  // Convert from Matrix into cv::Mat. Usage example:
10  // #include <opencv2/core/core.hpp>
11  // ...
12  // cv::Mat opMat = OP2CVMAT(cv::Mat());
13  #define OP_OP2CVMAT(opMat) \
14  (*((cv::Mat*)((opMat).getCvMat())))
15 
16  // Convert from Matrix into const cv::Mat. Usage example:
17  // #include <opencv2/core/core.hpp>
18  // ...
19  // cv::Mat opMat = OP2CVCONSTMAT(cv::Mat());
20  #define OP_OP2CVCONSTMAT(opMat) \
21  (*((cv::Mat*)((opMat).getConstCvMat())))
22 
23  // Convert from cv::Mat into Matrix. Usage example:
24  // #include <opencv2/core/core.hpp>
25  // ...
26  // Matrix opMat = CV2OPMAT(Matrix());
27  #define OP_CV2OPMAT(cvMat) \
28  (op::Matrix((void*)&(cvMat)))
29 
30  // Convert from cv::Mat into const Matrix. Usage example:
31  // #include <opencv2/core/core.hpp>
32  // ...
33  // Matrix opMat = CV2OPCONSTMAT(Matrix());
34  #define OP_CV2OPCONSTMAT(cvMat) \
35  (op::Matrix((const void*)&(cvMat)))
36 
37  // Convert from std::vector<Matrix> into std::vector<cv::Mat>. Usage example:
38  // #include <opencv2/core/core.hpp>
39  // ...
40  // std::vector<Matrix> opMats; // Assume filled
41  // OP_OP2CVVECTORMAT(cvMats, opMats);
42  #define OP_OP2CVVECTORMAT(cvMats, opMats) \
43  std::vector<cv::Mat> cvMats; \
44  for (auto& opMat : (opMats)) \
45  { \
46  const auto cvMat = OP_OP2CVCONSTMAT(opMat); \
47  cvMats.emplace_back(cvMat); \
48  }
49 
50  // Convert from std::vector<cv::Mat> into std::vector<Matrix>. Usage example:
51  // #include <opencv2/core/core.hpp>
52  // ...
53  // std::vector<cv::Mat> cvMats; // Assume filled
54  // OP_CV2OPVECTORMAT(opMats, cvMats);
55  #define OP_CV2OPVECTORMAT(opMats, cvMats) \
56  std::vector<op::Matrix> opMats; \
57  for (auto& cvMat : (cvMats)) \
58  { \
59  const auto opMat = OP_CV2OPMAT(cvMat); \
60  opMats.emplace_back(opMat); \
61  }
62 
63  // Convert from std::vector<cv::Mat> into std::vector<Matrix>. Usage example:
64  // #include <opencv2/core/core.hpp>
65  // ...
66  // // Equivalents:
67  // OP_CV_VOID_FUNCTION(opMat, size());
68  // // and
69  // OP_OP2CVMAT(cvMat, opMat);
70  // cvMat.size();
71  #define OP_MAT_VOID_FUNCTION(opMat, function) \
72  { \
73  cv::Mat cvMat = OP_OP2CVMAT(cvMat, opMat); \
74  cvMat.function; \
75  }
76  #define OP_CONST_MAT_VOID_FUNCTION(opMat, function) \
77  { \
78  const cv::Mat cvMat = OP_OP2CVCONSTMAT(opMat); \
79  cvMat.function; \
80  }
81  #define OP_MAT_RETURN_FUNCTION(outputVariable, opMat, function) \
82  { \
83  cv::Mat cvMat = OP_OP2CVMAT(cvMat, opMat); \
84  outputVariable = cvMat.function; \
85  }
86  #define OP_CONST_MAT_RETURN_FUNCTION(outputVariable, opMat, function) \
87  { \
88  const cv::Mat cvMat = OP_OP2CVCONSTMAT(opMat); \
89  outputVariable = cvMat.function; \
90  }
91 
95  class OP_API Matrix
96  {
97  public:
105  static void splitCvMatIntoVectorMatrix(std::vector<Matrix>& matrixesResized, const void* const cvMatPtr);
106 
108 
113  explicit Matrix(const void* cvMatPtr);
114 
118  explicit Matrix(const int rows, const int cols, const int type);
119 
127  explicit Matrix(const int rows, const int cols, const int type, void* cvMatPtr);
128 
129  Matrix clone() const;
130 
134  void* getCvMat();
135 
139  const void* getConstCvMat() const;
140 
145  unsigned char* data();
150  const unsigned char* dataConst() const;
156  unsigned char* dataPseudoConst() const;
157 
161  static Matrix eye(const int rows, const int cols, const int type);
165  int cols() const;
169  int rows() const;
173  int size(const int dimension) const;
177  int dims() const;
178 
182  bool isContinuous() const;
183  bool isSubmatrix() const;
184  size_t elemSize() const;
185  size_t elemSize1() const;
186  int type() const;
187  int depth() const;
188  int channels() const;
189  size_t step1(const int i = 0) const;
190  bool empty() const;
191  size_t total() const;
192  int checkVector(const int elemChannels, const int depth = -1, const bool requireContinuous = true) const;
193 
197  void setTo(const double value);
198  void copyTo(Matrix& outputMat) const;
199 
200  private:
201  // PIMPL idiom
202  // http://www.cppsamples.com/common-tasks/pimpl.html
203  struct ImplMatrix;
204  std::shared_ptr<ImplMatrix> spImpl;
205  };
206 }
207 
208 #endif // OPENPOSE_CORE_MAT_HPP
static void splitCvMatIntoVectorMatrix(std::vector< Matrix > &matrixesResized, const void *const cvMatPtr)
size_t total() const
const void * getConstCvMat() const
int rows() const
size_t elemSize() const
size_t step1(const int i=0) const
int channels() const
Matrix(const int rows, const int cols, const int type, void *cvMatPtr)
void copyTo(Matrix &outputMat) const
unsigned char * data()
Matrix(const int rows, const int cols, const int type)
int checkVector(const int elemChannels, const int depth=-1, const bool requireContinuous=true) const
static Matrix eye(const int rows, const int cols, const int type)
bool empty() const
int size(const int dimension) const
void * getCvMat()
const unsigned char * dataConst() const
bool isSubmatrix() const
int dims() const
int type() const
unsigned char * dataPseudoConst() const
Matrix clone() const
int cols() const
void setTo(const double value)
int depth() const
size_t elemSize1() const
bool isContinuous() const
Matrix(const void *cvMatPtr)
#define OP_API
Definition: macros.hpp:18