Disable Stage on Running Pipeline

Disable Stage on Running Pipeline

Hello, Prophesee Team!
I am trying to make FrameGenerationStage to be able to be:
  1. disabled (and free all resources and processing time),
  2. enabled back
  3. reset (new accumulation_time_ms and fps),
Questions:
  1. Does all resources and processing time get free in the Disable()?
  2. Does all resources get reset in the Reset() without excess?
  3. Any recommendation to the code?  

  1. #pragma once
  2. #include <memory>
  3. #include <assert.h>
  4. #include <opencv2/opencv.hpp>
  5. #include "metavision/sdk/base/utils/sdk_log.h"
  6. #include "metavision/sdk/core/pipeline/base_stage.h"
  7. #include "metavision/sdk/core/algorithms/periodic_frame_generation_algorithm.h"

  8. class FrameGenerationStage : public Metavision::BaseStage{
  9. public:
  10.     using FramePool = Metavision::SharedObjectPool<cv::Mat>;
  11.     using FramePtr  = FramePool::ptr_type;
  12.     using Output    = std::pair<Metavision::timestamp, FramePtr>;

  13.     FrameGenerationStage(int width, int height, uint32_t accumulation_time_ms = 10, double fps = 0.,
  14.         const Metavision::ColorPalette& palette = Metavision::BaseFrameGenerationAlgorithm::default_palette()) :
  15.         frame_pool_(FramePool::make_bounded(2)),
  16.         width_(width), height_(height), accumulation_time_ms_(accumulation_time_ms), fps_(fps), palette_(palette) {

  17.         SetCallbacks();
  18.     }

  19.     void SetCallbacks() {
  20.         const uint32_t accumulation_time_us = accumulation_time_ms_ * 1000;
  21.         algo_ = std::make_unique<Metavision::PeriodicFrameGenerationAlgorithm>(width_, height_, accumulation_time_us, fps_, palette_);
  22.         algo_->set_output_callback([this](const Metavision::timestamp ts, cv::Mat& f) {
  23.             crt_frame_ptr_ = frame_pool_.acquire();
  24.             cv::swap(f, *crt_frame_ptr_);

  25.             produce(std::make_pair(ts, crt_frame_ptr_));
  26.             });

  27.         set_consuming_callback([this](const boost::any& data) { consume_cd_events(data); });
  28.     }

  29.     void Reset(uint32_t accumulation_time_ms = 10, double fps = 0.) {
  30.         accumulation_time_ms_ = accumulation_time_ms;
  31.         fps_ = fps;

  32.         SetCallbacks();
  33.     }

  34.     void Disable() {
  35.         algo_->set_output_callback([this](const Metavision::timestamp ts, cv::Mat& f) {});
  36.         set_consuming_callback([this](const boost::any& data) {});
  37.     }

  38.     void Enable() {
  39.         SetCallbacks();
  40.     }

  41. private:
  42.     void consume_cd_events(const boost::any &data) {
  43.         try {
  44.             auto buffer = boost::any_cast<EventBufferPtr>(data);
  45.             algo_->process_events(buffer->cbegin(), buffer->cend());
  46.         } catch (boost::bad_any_cast &c) { MV_SDK_LOG_ERROR() << c.what(); }
  47.     }

  48.     FramePtr crt_frame_ptr_;
  49.     FramePool frame_pool_;
  50.     std::unique_ptr<Metavision::PeriodicFrameGenerationAlgorithm> algo_;

  51.     int width_;
  52.     int height_;
  53.     uint32_t accumulation_time_ms_;
  54.     double fps_;
  55.     const Metavision::ColorPalette& palette_;
  56. };

    As a Prophesee customer, join the community conversation. 
    Request your free access today.

      Information

      In this Community Forum, you can discuss products, technology and applications. Only registred users can post but everyone can read. To ask a private question, enter a support ticket in My Area https://support.prophesee.ai/portal/en/newticket