stromx  0.8.0
Matrix.h
1 /*
2 * Copyright 2012 Matthias Fuchs
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #ifndef STROMX_CVSUPPORT_MATRIX_H
18 #define STROMX_CVSUPPORT_MATRIX_H
19 
20 #include <string>
21 #include <vector>
22 #include "stromx/cvsupport/Config.h"
23 #include <stromx/runtime/MatrixWrapper.h>
24 
25 namespace cv
26 {
27  class Mat;
28  class MatExpr;
29 
30  template <class T>
31  class Rect_;
32  typedef Rect_<int> Rect;
33 
34  class RotatedRect;
35 }
36 
37 namespace stromx
38 {
39  namespace cvsupport
40  {
42  class STROMX_CVSUPPORT_API Matrix : public runtime::MatrixWrapper
43  {
44  friend STROMX_CVSUPPORT_API cv::Mat getOpenCvMat(const runtime::Matrix& matrix,
45  const unsigned int numChannels);
46 
47  public:
48 
53  Matrix();
54 
56  Matrix(const stromx::cvsupport::Matrix& matrix);
57 
59  explicit Matrix(const unsigned int rows, const unsigned int cols, const ValueType valueType);
60 
65  explicit Matrix(cv::Mat& cvMatrix);
66 
71  explicit Matrix(const cv::MatExpr& cvMatExpr);
72 
74  explicit Matrix(const stromx::runtime::Matrix& matrix);
75 
80  explicit Matrix(const cv::Rect& cvRect);
81 
87  explicit Matrix(const cv::RotatedRect& cvRotatedRect);
88 
94  explicit Matrix(const unsigned int size);
95 
97  explicit Matrix(const std::string & filename);
98 
99  virtual ~Matrix();
100 
101  virtual const runtime::Version & version() const { return VERSION; }
102  virtual const std::string & type() const { return TYPE; }
103  virtual const std::string & package() const { return PACKAGE; }
104 
105  virtual Data* clone() const;
106 
108  const Matrix & operator=(const runtime::Matrix & matrix);
109 
110 
116  static cvsupport::Matrix eye(const unsigned int rows,
117  const unsigned int cols,
118  const ValueType valueType);
119 
120 
125  static cvsupport::Matrix zeros(const unsigned int rows,
126  const unsigned int cols,
127  const ValueType valueType);
128 
129  private:
130  static const std::string TYPE;
131  static const std::string PACKAGE;
132  static const runtime::Version VERSION;
133 
134  static int cvTypeFromValueType(const runtime::Matrix::ValueType valueType,
135  const unsigned int numChannels = 1);
136  static runtime::Matrix::ValueType valueTypeFromCvType(const int cvType);
137 
138  void copy(const stromx::runtime::Matrix & matrix);
139  void allocate(const unsigned int rows, const unsigned int cols, const runtime::Matrix::ValueType valueType);
140  void getDataFromCvMatrix(const ValueType valueType);
141 
142  cv::Mat* m_matrix;
143  };
144  }
145 }
146 
147 #endif // STROMX_CVSUPPORT_MATRIX_H
A version of an operator or data type.
Definition: Version.h:46
Abstract data object.
Definition: Data.h:53
Matrix implementation based on OpenCV matrices.
Definition: Matrix.h:42
virtual const runtime::Version & version() const
Definition: Matrix.h:101
Definition: Image.h:24
virtual const std::string & type() const
Definition: Matrix.h:102
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
Abstract image.
Definition: Matrix.h:28
virtual const std::string & package() const
Definition: Matrix.h:103
Concrete matrix without memory management.
Definition: MatrixWrapper.h:27
cv::Mat getOpenCvMat(const runtime::Image &image)
Definition: Utilities.cpp:34
Definition: Matrix.h:31