rkyolo.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. //NOLINT
  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 "ultra_infer/ultra_infer_model.h"
  16. #include "ultra_infer/vision/detection/contrib/rknpu2/postprocessor.h"
  17. #include "ultra_infer/vision/detection/contrib/rknpu2/preprocessor.h"
  18. namespace ultra_infer {
  19. namespace vision {
  20. namespace detection {
  21. class ULTRAINFER_DECL RKYOLO : public UltraInferModel {
  22. public:
  23. RKYOLO(const std::string &model_file,
  24. const RuntimeOption &custom_option = RuntimeOption(),
  25. const ModelFormat &model_format = ModelFormat::RKNN);
  26. std::string ModelName() const { return "RKYOLO"; }
  27. /** \brief Predict the detection result for an input image
  28. *
  29. * \param[in] img The input image data, comes from cv::imread(), is a 3-D
  30. * array with layout HWC, BGR format \param[in] result The output detection
  31. * result will be written to this structure \return true if the prediction
  32. * succeeded, otherwise false
  33. */
  34. virtual bool Predict(const cv::Mat &img, DetectionResult *result);
  35. /** \brief Predict the detection results for a batch of input images
  36. *
  37. * \param[in] imgs, The input image list, each element comes from cv::imread()
  38. * \param[in] results The output detection result list
  39. * \return true if the prediction succeeded, otherwise false
  40. */
  41. virtual bool BatchPredict(const std::vector<cv::Mat> &imgs,
  42. std::vector<DetectionResult> *results);
  43. /// Get preprocessor reference of YOLOv5
  44. RKYOLOPreprocessor &GetPreprocessor() { return preprocessor_; }
  45. /// Get postprocessor reference of YOLOv5
  46. RKYOLOPostprocessor &GetPostprocessor() { return postprocessor_; }
  47. protected:
  48. bool Initialize();
  49. RKYOLOPreprocessor preprocessor_;
  50. RKYOLOPostprocessor postprocessor_;
  51. };
  52. } // namespace detection
  53. } // namespace vision
  54. } // namespace ultra_infer