MNN  1.0
ImageProcess.hpp
浏览该文件的文档.
1 //
2 // ImageProcess.hpp
3 // MNN
4 //
5 // Created by MNN on 2018/09/19.
6 // Copyright © 2018, Alibaba Group Holding Limited
7 //
8 
9 #ifndef ImageProcess_hpp
10 #define ImageProcess_hpp
11 
12 #include "ErrorCode.hpp"
13 #include "Matrix.h"
14 #include "Tensor.hpp"
15 
16 namespace MNN {
17 namespace CV {
19  RGBA = 0,
20  RGB,
21  BGR,
24  YUV_NV21 = 11,
25 };
26 
27 enum Filter { NEAREST = 0, BILINEAR = 1, BICUBIC = 2 };
28 
29 enum Wrap { CLAMP_TO_EDGE = 0, ZERO = 1, REPEAT = 2 };
30 
39 public:
40  struct Inside;
41  struct Config {
43  Filter filterType = NEAREST;
45  ImageFormat sourceFormat = RGBA;
47  ImageFormat destFormat = RGBA;
48 
49  // Only valid if the dest type is float
50  float mean[4] = {0.0f, 0.0f, 0.0f, 0.0f};
51  float normal[4] = {1.0f, 1.0f, 1.0f, 1.0f};
52 
55  };
56 
57 public:
64  static ImageProcess* create(const Config& config, const Tensor* dstTensor = nullptr);
65 
77  static ImageProcess* create(const ImageFormat sourceFormat = RGBA, const ImageFormat destFormat = RGBA,
78  const float* means = nullptr, const int meanCount = 0, const float* normals = nullptr,
79  const int normalCount = 0, const Tensor* dstTensor = nullptr);
80 
81  ~ImageProcess();
82 
87  inline const Matrix& matrix() const {
88  return mTransform;
89  }
90  void setMatrix(const Matrix& matrix);
91 
101  ErrorCode convert(const uint8_t* source, int iw, int ih, int stride, Tensor* dest);
102 
111  template <typename T>
112  static Tensor* createImageTensor(int w, int h, int bpp, void* p = nullptr) {
113  return createImageTensor(halide_type_of<T>(), w, h, bpp, p);
114  }
115  static Tensor* createImageTensor(halide_type_t type, int w, int h, int bpp, void* p = nullptr);
116 
117 private:
118  ImageProcess(const Config& config);
119  Matrix mTransform;
120  Matrix mTransformInvert;
121  Inside* mInside;
122 };
123 } // namespace CV
124 } // namespace MNN
125 
126 #endif /* ImageProcess_hpp */
Filter
Definition: ImageProcess.hpp:27
Definition: ImageProcess.hpp:38
Definition: ImageProcess.hpp:21
Definition: ImageProcess.hpp:22
Definition: ImageProcess.hpp:24
Definition: ImageProcess.hpp:29
Wrap
Definition: ImageProcess.hpp:29
Definition: ImageProcess.hpp:29
static Tensor * createImageTensor(int w, int h, int bpp, void *p=nullptr)
create tensor with given data.
Definition: ImageProcess.hpp:112
Definition: ImageProcess.hpp:27
Definition: Tensor.hpp:25
Definition: ImageProcess.hpp:27
#define MNN_PUBLIC
Definition: MNNDefine.h:53
Definition: Matrix.h:48
Definition: HalideRuntime.h:82
Definition: AutoTime.hpp:16
Definition: ImageProcess.hpp:20
Definition: ImageProcess.hpp:41
Definition: ImageProcess.hpp:29
Definition: ImageProcess.hpp:19
Definition: ImageProcess.hpp:23
ErrorCode
Definition: ErrorCode.hpp:13
ImageFormat
Definition: ImageProcess.hpp:18
Definition: ImageProcess.hpp:27
const Matrix & matrix() const
get affine transform matrix.
Definition: ImageProcess.hpp:87