MYNT EYE D SDK  1.7.1
http://www.myntai.com/mynteye/depth
image.h
1 // Copyright 2018 Slightech Co., Ltd. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #ifndef MYNTEYE_DEVICE_IMAGE_H_
15 #define MYNTEYE_DEVICE_IMAGE_H_
16 #pragma once
17 
18 #include <cstdint>
19 #include <map>
20 #include <memory>
21 #include <vector>
22 #include <iostream>
23 
24 #ifdef WITH_OPENCV
25 #include <opencv2/core/core.hpp>
26 #endif
27 
28 #include "mynteyed/device/types.h"
29 #include "mynteyed/stubs/global.h"
30 
31 MYNTEYE_BEGIN_NAMESPACE
32 
33 class MYNTEYE_API Image {
34  public:
35  using pointer = std::shared_ptr<Image>;
36 
37  using data_t = std::vector<std::uint8_t>;
38  using data_ptr_t = std::shared_ptr<data_t>;
39 
40  protected:
41  Image(const ImageType& type, const ImageFormat& format,
42  int width, int height, bool is_buffer);
43 
44  public:
45  virtual ~Image();
46 
47  static pointer Create(const ImageType& type, const ImageFormat& format,
48  int width, int height, bool is_buffer);
49 
50  ImageType type() const {
51  return type_;
52  }
53 
54  ImageFormat format() const {
55  return format_;
56  }
57 
58  int width() const {
59  return width_;
60  }
61 
62  int height() const {
63  return height_;
64  }
65 
66  std::size_t size() const {
67  return width_ * height_;
68  }
69 
70  bool is_buffer() const {
71  return is_buffer_;
72  }
73 
74  int frame_id() const {
75  return frame_id_;
76  }
77 
78  void set_frame_id(int frame_id) {
79  frame_id_ = frame_id;
80  }
81 
82  bool is_dual() const {
83  return is_dual_;
84  }
85 
86  void set_is_dual(bool is_dual) {
87  is_dual_ = is_dual;
88  }
89 
90  std::uint8_t* data() {
91  return data_->data();
92  }
93 
94  const std::uint8_t* data() const {
95  return data_->data();
96  }
97 
98  std::size_t data_size() const {
99  return data_->size();
100  }
101 
102  std::size_t valid_size() const {
103  return valid_size_;
104  }
105 
106  // will resize data if larger then data size
107  void set_valid_size(std::size_t valid_size);
108 
109  virtual pointer To(const ImageFormat& format) = 0;
110 
111 #ifdef WITH_OPENCV
112  cv::Mat ToMat();
113 #endif
114 
115  pointer Clone() const;
116  pointer Shadow(const ImageType& type) const;
117 
118  bool ResetBuffer();
119 
120  protected:
121  ImageType type_;
122  ImageFormat format_;
123  int width_;
124  int height_;
125  bool is_buffer_;
126 
127  ImageFormat raw_format_;
128 
129  // Frame id
130  int frame_id_;
131  // Special state for dual data
132  bool is_dual_;
133 
134  data_ptr_t data_;
135  // The real valid size of some compress format or other cases.
136  std::size_t valid_size_;
137 
138  MYNTEYE_DISABLE_COPY(Image)
139  MYNTEYE_DISABLE_MOVE(Image)
140 };
141 
142 class MYNTEYE_API ImageColor : public Image,
143  public std::enable_shared_from_this<ImageColor> {
144  public:
145  using pointer = std::shared_ptr<ImageColor>;
146 
147  protected:
148  ImageColor(const ImageType& type, const ImageFormat& format,
149  int width, int height, bool is_buffer);
150 
151  public:
152  virtual ~ImageColor();
153 
154  static pointer Create(const ImageFormat& format, int width, int height,
155  bool is_buffer) {
156  return Create(ImageType::IMAGE_LEFT_COLOR, format, width, height,
157  is_buffer);
158  }
159 
160  static pointer Create(const ImageType& type, const ImageFormat& format,
161  int width, int height, bool is_buffer);
162 
163  Image::pointer To(const ImageFormat& format) override;
164 
165  private:
166  MYNTEYE_DISABLE_COPY(ImageColor)
167  MYNTEYE_DISABLE_MOVE(ImageColor)
168 };
169 
170 class MYNTEYE_API ImageDepth : public Image,
171  public std::enable_shared_from_this<ImageDepth> {
172  public:
173  using pointer = std::shared_ptr<ImageDepth>;
174 
175  protected:
176  ImageDepth(const ImageFormat& format, int width, int height, bool is_buffer);
177 
178  public:
179  virtual ~ImageDepth();
180 
181  static pointer Create(const ImageFormat& format, int width, int height,
182  bool is_buffer) {
183  return pointer(new ImageDepth(format, width, height, is_buffer));
184  }
185 
186  Image::pointer To(const ImageFormat& format) override;
187 
188  private:
189  MYNTEYE_DISABLE_COPY(ImageDepth)
190  MYNTEYE_DISABLE_MOVE(ImageDepth)
191 };
192 
193 MYNTEYE_END_NAMESPACE
194 
195 #endif // MYNTEYE_DEVICE_IMAGE_H_
Definition: image.h:170
Definition: image.h:142
Definition: image.h:33