stromx  0.8.0
Image.h
1 /*
2 * Copyright 2011 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_IMAGE_H
18 #define STROMX_CVSUPPORT_IMAGE_H
19 
20 #include <string>
21 #include "stromx/cvsupport/Config.h"
22 #include <stromx/runtime/ImageWrapper.h>
23 
24 namespace cv
25 {
26  class Mat;
27 }
28 
29 namespace stromx
30 {
31  namespace cvsupport
32  {
34  class STROMX_CVSUPPORT_API Image : public runtime::ImageWrapper
35  {
36  friend STROMX_CVSUPPORT_API cv::Mat getOpenCvMat(const runtime::Image& image);
37 
38  public:
41  {
44 
49  GRAYSCALE = 0x2,
50 
55  COLOR = 0x4,
56 
62  DEPTH_16 = 0x8
63  };
64 
69  static void save(const std::string& filename, const runtime::Image & image);
70 
75  Image();
76 
78  explicit Image(const unsigned int width, const unsigned int height, const PixelType pixelType);
79 
81  explicit Image(const std::string & filename);
82 
87  explicit Image(const std::string & filename, const Conversion access);
88 
90  explicit Image(const stromx::runtime::Image& image);
91 
93  explicit Image(const stromx::cvsupport::Image& image);
94 
100  explicit Image(const cv::Mat & cvImage);
101 
111  explicit Image(const cv::Mat & cvImage, const PixelType pixelType);
112 
117  explicit Image(const unsigned int size);
118 
119  virtual ~Image();
120 
121  virtual const runtime::Version & version() const { return VERSION; }
122  virtual const std::string & type() const { return TYPE; }
123  virtual const std::string & package() const { return PACKAGE; }
124 
125  virtual Data* clone() const;
126 
127  virtual void serialize(runtime::OutputProvider & output) const;
128  virtual void deserialize(runtime::InputProvider & input, const stromx::runtime::Version & version);
129 
130  virtual void initializeImage(const unsigned int width,
131  const unsigned int height,
132  const unsigned int stride,
133  uint8_t* data,
134  const PixelType pixelType);
135 
136  virtual void initializeMatrix(const unsigned int rows,
137  const unsigned int cols,
138  const unsigned int stride,
139  uint8_t* data,
140  const ValueType valueType);
141 
146  void open(const std::string& filename);
147 
152  void open(const std::string & filename, const Conversion access);
153 
158  void save(const std::string& filename) const;
159 
160  private:
161  static const std::string TYPE;
162  static const std::string PACKAGE;
163  static const runtime::Version VERSION;
164 
165  static PixelType pixelTypeFromParameters(const int depth, const int numChannels);
166  static int getCvAccessType(const Conversion access);
167  static int cvTypeFromPixelType(const runtime::Image::PixelType pixelType);
168  static int cvTypeFromValueType(const runtime::Matrix::ValueType valueType);
169  static runtime::Image::PixelType pixelTypeFromCvType(const int cvType);
170 
171  void getDataFromCvImage(const PixelType pixelType);
172  void copy(const stromx::runtime::Image & image);
173  void allocate(const unsigned int width, const unsigned int height, const Image::PixelType pixelType);
174 
175  cv::Mat* m_image;
176  };
177  }
178 }
179 
180 #endif // STROMX_CVSUPPORT_IMAGE_H
Conversion
Definition: Image.h:40
virtual const std::string & type() const
Definition: Image.h:122
A version of an operator or data type.
Definition: Version.h:46
Concrete image without memory management.
Definition: ImageWrapper.h:27
Abstract data object.
Definition: Data.h:53
virtual const runtime::Version & version() const
Definition: Image.h:121
Provides functions to serialize data to strings and files.
Definition: OutputProvider.h:27
Provides functions to deserialize data from strings and files.
Definition: InputProvider.h:27
Definition: Image.h:24
Image with support for reading and writing.
Definition: Image.h:34
Version version()
Returns the version of the stromx runtime library.
Definition: Runtime.cpp:54
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
virtual const std::string & package() const
Definition: Image.h:123
Abstract image.
Definition: Image.h:28
cv::Mat getOpenCvMat(const runtime::Image &image)
Definition: Utilities.cpp:34