Disable Stage on Running Pipeline
Hello, Prophesee Team!I am trying to make FrameGenerationStage to be able to be:
- disabled (and free all resources and processing time),
- enabled back
- reset (new accumulation_time_ms and fps),
Questions:
- Does all resources and processing time get free in the Disable()?
- Does all resources get reset in the Reset() without excess?
- Any recommendation to the code?
- #pragma once
- #include <memory>
- #include <assert.h>
- #include <opencv2/opencv.hpp>
- #include "metavision/sdk/base/utils/sdk_log.h"
- #include "metavision/sdk/core/pipeline/base_stage.h"
- #include "metavision/sdk/core/algorithms/periodic_frame_generation_algorithm.h"
- class FrameGenerationStage : public Metavision::BaseStage{
- public:
- using FramePool = Metavision::SharedObjectPool<cv::Mat>;
- using FramePtr = FramePool::ptr_type;
- using Output = std::pair<Metavision::timestamp, FramePtr>;
- FrameGenerationStage(int width, int height, uint32_t accumulation_time_ms = 10, double fps = 0.,
- const Metavision::ColorPalette& palette = Metavision::BaseFrameGenerationAlgorithm::default_palette()) :
- frame_pool_(FramePool::make_bounded(2)),
- width_(width), height_(height), accumulation_time_ms_(accumulation_time_ms), fps_(fps), palette_(palette) {
- SetCallbacks();
- }
- void SetCallbacks() {
- const uint32_t accumulation_time_us = accumulation_time_ms_ * 1000;
- algo_ = std::make_unique<Metavision::PeriodicFrameGenerationAlgorithm>(width_, height_, accumulation_time_us, fps_, palette_);
- algo_->set_output_callback([this](const Metavision::timestamp ts, cv::Mat& f) {
- crt_frame_ptr_ = frame_pool_.acquire();
- cv::swap(f, *crt_frame_ptr_);
- produce(std::make_pair(ts, crt_frame_ptr_));
- });
- set_consuming_callback([this](const boost::any& data) { consume_cd_events(data); });
- }
- void Reset(uint32_t accumulation_time_ms = 10, double fps = 0.) {
- accumulation_time_ms_ = accumulation_time_ms;
- fps_ = fps;
- SetCallbacks();
- }
- void Disable() {
- algo_->set_output_callback([this](const Metavision::timestamp ts, cv::Mat& f) {});
- set_consuming_callback([this](const boost::any& data) {});
- }
- void Enable() {
- SetCallbacks();
- }
- private:
- void consume_cd_events(const boost::any &data) {
- try {
- auto buffer = boost::any_cast<EventBufferPtr>(data);
- algo_->process_events(buffer->cbegin(), buffer->cend());
- } catch (boost::bad_any_cast &c) { MV_SDK_LOG_ERROR() << c.what(); }
- }
- FramePtr crt_frame_ptr_;
- FramePool frame_pool_;
- std::unique_ptr<Metavision::PeriodicFrameGenerationAlgorithm> algo_;
- int width_;
- int height_;
- uint32_t accumulation_time_ms_;
- double fps_;
- const Metavision::ColorPalette& palette_;
- };
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