FastDeploy  latest
Fast & Easy to Deploy!
pad_to_size.h
1 // Copyright (c) 2022 PaddlePaddle Authors. 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 
15 #pragma once
16 
17 #include "fastdeploy/vision/common/processors/base.h"
18 #ifdef ENABLE_CVCUDA
19 #include <cvcuda/OpCopyMakeBorder.hpp>
20 
21 #include "fastdeploy/vision/common/processors/cvcuda_utils.h"
22 #endif
23 
24 namespace fastdeploy {
25 namespace vision {
26 
29 class FASTDEPLOY_DECL PadToSize : public Processor {
30  public:
31  // only support pad with right-bottom padding mode
32  PadToSize(int width, int height, const std::vector<float>& value) {
33  width_ = width;
34  height_ = height;
35  value_ = value;
36  }
37  bool ImplByOpenCV(Mat* mat);
38 #ifdef ENABLE_FLYCV
39  bool ImplByFlyCV(Mat* mat);
40 #endif
41 #ifdef ENABLE_CVCUDA
42  bool ImplByCvCuda(FDMat* mat);
43 #endif
44  std::string Name() { return "PadToSize"; }
45 
55  static bool Run(Mat* mat, int width, int height,
56  const std::vector<float>& value,
57  ProcLib lib = ProcLib::DEFAULT);
58 
64  void SetWidthHeight(int width, int height) {
65  width_ = width;
66  height_ = height;
67  }
68 
69  private:
70  bool CheckArgs(FDMat* mat);
71  int width_;
72  int height_;
73  std::vector<float> value_;
74 #ifdef ENABLE_CVCUDA
75  cvcuda::CopyMakeBorder cvcuda_pad_op_;
76 #endif
77 };
78 } // namespace vision
79 } // namespace fastdeploy
Processor for padding images to given size.
Definition: pad_to_size.h:29
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
void SetWidthHeight(int width, int height)
Process the input images.
Definition: pad_to_size.h:64
Processor base class for processors in fastdeploy/vision/common/processors.
Definition: base.h:42
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16