utils.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #pragma once
  15. #include "opencv2/core/core.hpp"
  16. #include "ultra_infer/core/fd_tensor.h"
  17. #include "ultra_infer/utils/utils.h"
  18. #include "ultra_infer/vision/common/processors/mat.h"
  19. #ifdef ENABLE_FLYCV
  20. #include "flycv.h" // NOLINT
  21. #endif
  22. namespace ultra_infer {
  23. namespace vision {
  24. // Convert data type of opencv to FDDataType
  25. FDDataType OpenCVDataTypeToFD(int type);
  26. // Create data type of opencv by FDDataType
  27. int CreateOpenCVDataType(FDDataType type, int channel = 1);
  28. #ifdef ENABLE_FLYCV
  29. // Convert data type of flycv to FDDataType
  30. FDDataType FlyCVDataTypeToFD(fcv::FCVImageType type);
  31. // Create data type of flycv by FDDataType
  32. fcv::FCVImageType CreateFlyCVDataType(FDDataType type, int channel = 1);
  33. // Convert cv::Mat to fcv::Mat
  34. fcv::Mat ConvertOpenCVMatToFlyCV(cv::Mat &im);
  35. // Convert fcv::Mat to fcv::mat
  36. cv::Mat ConvertFlyCVMatToOpenCV(fcv::Mat &fim);
  37. #endif
  38. // Create zero copy OpenCV/FlyCV Mat from FD Tensor / Buffer
  39. cv::Mat CreateZeroCopyOpenCVMatFromBuffer(int height, int width, int channels,
  40. FDDataType type, void *data);
  41. cv::Mat CreateZeroCopyOpenCVMatFromTensor(const FDTensor &tensor,
  42. Layout layout = Layout::HWC);
  43. #ifdef ENABLE_FLYCV
  44. fcv::Mat CreateZeroCopyFlyCVMatFromBuffer(int height, int width, int channels,
  45. FDDataType type, void *data);
  46. fcv::Mat CreateZeroCopyFlyCVMatFromTensor(const FDTensor &tensor);
  47. #endif
  48. } // namespace vision
  49. } // namespace ultra_infer