FastDeploy  latest
Fast & Easy to Deploy!
resize_by_short.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/OpResize.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 ResizeByShort : public Processor {
30  public:
31  ResizeByShort(int target_size, int interp = 1, bool use_scale = true,
32  const std::vector<int>& max_hw = std::vector<int>()) {
33  target_size_ = target_size;
34  max_hw_ = max_hw;
35  interp_ = interp;
36  use_scale_ = use_scale;
37  }
38  bool ImplByOpenCV(FDMat* mat);
39 #ifdef ENABLE_FLYCV
40  bool ImplByFlyCV(FDMat* mat);
41 #endif
42 #ifdef ENABLE_CVCUDA
43  bool ImplByCvCuda(FDMat* mat);
44  bool ImplByCvCuda(FDMatBatch* mat_batch);
45 #endif
46  std::string Name() { return "ResizeByShort"; }
47 
58  static bool Run(FDMat* mat, int target_size, int interp = 1,
59  bool use_scale = true,
60  const std::vector<int>& max_hw = std::vector<int>(),
61  ProcLib lib = ProcLib::DEFAULT);
62 
63  private:
64  double GenerateScale(const int origin_w, const int origin_h);
65  int target_size_;
66  std::vector<int> max_hw_;
67  int interp_;
68  bool use_scale_;
69 #ifdef ENABLE_CVCUDA
70  cvcuda::Resize cvcuda_resize_op_;
71 #endif
72 };
73 } // namespace vision
74 } // namespace fastdeploy
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
Processor base class for processors in fastdeploy/vision/common/processors.
Definition: base.h:42
FDMatBatch contains batch data for preprocess.
Definition: mat_batch.h:28
Processor for resize images by short edge.
Definition: resize_by_short.h:29
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16