video_postproc.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*************************************************************************
  2. * Copyright (C) [2021] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #ifndef MODULES_INFERENCE2_INCLUDE_VIDEO_POSTPROC_HPP_
  21. #define MODULES_INFERENCE2_INCLUDE_VIDEO_POSTPROC_HPP_
  22. /**
  23. * \file video_postproc.hpp
  24. *
  25. * This file contains a declaration of class VideoPostproc
  26. */
  27. #include <memory>
  28. #include <string>
  29. #include <vector>
  30. #include "cnis/infer_server.h"
  31. #include "cnis/processor.h"
  32. #include "cnstream_frame.hpp"
  33. #include "cnstream_frame_va.hpp"
  34. #include "reflex_object.h"
  35. namespace cnstream {
  36. /*!
  37. * @class VideoPostproc
  38. *
  39. * @brief VideoPostproc is the base class of post processing classes for Inference2.
  40. */
  41. class VideoPostproc : virtual public ReflexObjectEx<VideoPostproc> {
  42. public:
  43. /**
  44. * @brief Destructs an object.
  45. *
  46. * @return No return value.
  47. */
  48. virtual ~VideoPostproc() = 0;
  49. /**
  50. * @brief Creates a postprocess object with the given postprocess's class name.
  51. *
  52. * @param[in] proc_name The postprocess class name.
  53. *
  54. * @return Returns the pointer to postprocess object.
  55. */
  56. static VideoPostproc* Create(const std::string& proc_name);
  57. /**
  58. * @brief Sets threshold.
  59. *
  60. * @param[in] threshold The value between 0 and 1.
  61. *
  62. * @return No return value.
  63. */
  64. void SetThreshold(const float threshold);
  65. /**
  66. * @brief Executes postprocessing on the model's output data.
  67. *
  68. * @param[out] output_data The postprocessing result. The result of postprocessing should be set to it.
  69. * You could set any type of data to this parameter and get it in UserProcess function.
  70. * @param[in] model_output The neural network origin output data.
  71. * @param[in] model_info The model information, such as input/output number and shape.
  72. *
  73. * @return Returns true if successful, otherwise returns false.
  74. *
  75. * @note This function is executed by infer server postproc processor. You could override it to develop custom
  76. * postprocessing.
  77. * To set any type of data to output_data, use this statement,
  78. * e.g., `int example_var = 1; output_data->Set(example_var);`
  79. *
  80. */
  81. virtual bool Execute(infer_server::InferData* output_data, const infer_server::ModelIO& model_output,
  82. const infer_server::ModelInfo& model_info) = 0;
  83. protected:
  84. float threshold_ = 0;
  85. }; // class VideoPostproc
  86. } // namespace cnstream
  87. #endif // MODULES_INFERENCE2_INCLUDE_VIDEO_POSTPROC_HPP_