#pragma once #include #include #include #include #include #include #include #include #include #include #include #include class ImageProcessor; class Grabber; class DispmanxFrameGrabber; class GrabberWrapper : public QObject { Q_OBJECT public: GrabberWrapper(QString grabberName, Grabber * ggrabber, unsigned width, unsigned height, const unsigned updateRate_Hz, const int priority, hyperion::Components grabberComponentId=hyperion::COMP_GRABBER); virtual ~GrabberWrapper(); /// /// Starts the grabber wich produces led values with the specified update rate /// virtual bool start(); /// /// Stop grabber /// virtual void stop(); void setImageProcessorEnabled(bool enable); static QStringList availableGrabbers(); public: template void transferFrame(Grabber_T &grabber) { unsigned w = grabber.getImageWidth(); unsigned h = grabber.getImageHeight(); if (_imageProcessorEnabled && ( _image.width() != w || _image.height() != h)) { _processor->setSize(w, h); _image.resize(w, h); } if (grabber.grabFrame(_image) >= 0) { emit emitImage(_priority, _image, _timeout_ms); _processor->process(_image, _ledColors); setColors(_ledColors, _timeout_ms); } } public slots: void componentStateChanged(const hyperion::Components component, bool enable); /// /// virtual method, should perform single frame grab and computes the led-colors /// virtual void action() = 0; /// /// Set the grabbing mode /// @param[in] mode The new grabbing mode /// void setGrabbingMode(const GrabbingMode mode); /// /// Set the video mode (2D/3D) /// @param[in] mode The new video mode /// virtual void setVideoMode(const VideoMode videoMode); virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom); signals: void emitImage(int priority, const Image & image, const int timeout_ms); protected: void setColors(const std::vector &ledColors, const int timeout_ms); QString _grabberName; /// Pointer to Hyperion for writing led values Hyperion * _hyperion; /// The priority of the led colors const int _priority; /// The timer for generating events with the specified update rate QTimer _timer; /// The update rate [Hz] const int _updateInterval_ms; /// The timeout of the led colors [ms] const int _timeout_ms; /// The Logger instance Logger * _log; // forwarding enabled bool _forward; /// The processor for transforming images to led colors ImageProcessor * _processor; hyperion::Components _grabberComponentId; Grabber *_ggrabber; /// The image used for grabbing frames Image _image; /// The list with computed led colors std::vector _ledColors; bool _imageProcessorEnabled; };