2016-08-11 07:13:55 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTimer>
|
2017-02-17 08:33:34 +01:00
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2016-08-11 07:13:55 +02:00
|
|
|
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <utils/Components.h>
|
2016-08-12 23:07:32 +02:00
|
|
|
#include <utils/GrabbingMode.h>
|
2016-08-11 07:13:55 +02:00
|
|
|
#include <hyperion/Hyperion.h>
|
2017-08-12 07:55:32 +02:00
|
|
|
#include <hyperion/ImageProcessor.h>
|
|
|
|
#include <utils/Image.h>
|
|
|
|
#include <utils/ColorRgb.h>
|
|
|
|
#include <utils/VideoMode.h>
|
2016-08-11 07:13:55 +02:00
|
|
|
|
|
|
|
class ImageProcessor;
|
2017-08-12 07:55:32 +02:00
|
|
|
class Grabber;
|
|
|
|
class DispmanxFrameGrabber;
|
2016-08-11 07:13:55 +02:00
|
|
|
|
|
|
|
class GrabberWrapper : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2017-08-12 07:55:32 +02:00
|
|
|
GrabberWrapper(QString grabberName, Grabber * ggrabber, unsigned width, unsigned height, const unsigned updateRate_Hz, const int priority, hyperion::Components grabberComponentId=hyperion::COMP_GRABBER);
|
2016-08-11 07:13:55 +02:00
|
|
|
|
|
|
|
virtual ~GrabberWrapper();
|
|
|
|
|
2016-08-12 23:07:32 +02:00
|
|
|
///
|
|
|
|
/// Starts the grabber wich produces led values with the specified update rate
|
|
|
|
///
|
2016-08-11 07:13:55 +02:00
|
|
|
virtual bool start();
|
2016-08-12 23:07:32 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Stop grabber
|
|
|
|
///
|
2016-08-11 07:13:55 +02:00
|
|
|
virtual void stop();
|
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
void setImageProcessorEnabled(bool enable);
|
|
|
|
|
2017-02-17 08:33:34 +01:00
|
|
|
static QStringList availableGrabbers();
|
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
public:
|
|
|
|
template <typename Grabber_T>
|
2017-09-01 08:50:37 +02:00
|
|
|
bool transferFrame(Grabber_T &grabber)
|
2017-08-12 07:55:32 +02:00
|
|
|
{
|
|
|
|
unsigned w = grabber.getImageWidth();
|
|
|
|
unsigned h = grabber.getImageHeight();
|
|
|
|
if (_imageProcessorEnabled && ( _image.width() != w || _image.height() != h))
|
|
|
|
{
|
|
|
|
_processor->setSize(w, h);
|
|
|
|
_image.resize(w, h);
|
|
|
|
}
|
|
|
|
|
2017-09-01 08:50:37 +02:00
|
|
|
int ret = grabber.grabFrame(_image);
|
|
|
|
if (ret >= 0)
|
2017-08-12 07:55:32 +02:00
|
|
|
{
|
|
|
|
emit emitImage(_priority, _image, _timeout_ms);
|
|
|
|
_processor->process(_image, _ledColors);
|
|
|
|
setColors(_ledColors, _timeout_ms);
|
2017-09-01 08:50:37 +02:00
|
|
|
return true;
|
2017-08-12 07:55:32 +02:00
|
|
|
}
|
2017-09-01 08:50:37 +02:00
|
|
|
return false;
|
2017-08-12 07:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
public slots:
|
|
|
|
void componentStateChanged(const hyperion::Components component, bool enable);
|
2016-08-12 23:07:32 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// virtual method, should perform single frame grab and computes the led-colors
|
|
|
|
///
|
2016-08-11 07:13:55 +02:00
|
|
|
virtual void action() = 0;
|
|
|
|
|
2017-09-01 08:50:37 +02:00
|
|
|
void actionWrapper();
|
|
|
|
|
2016-08-12 23:07:32 +02:00
|
|
|
///
|
|
|
|
/// Set the grabbing mode
|
|
|
|
/// @param[in] mode The new grabbing mode
|
|
|
|
///
|
|
|
|
void setGrabbingMode(const GrabbingMode mode);
|
|
|
|
|
2017-08-04 23:08:15 +02:00
|
|
|
///
|
|
|
|
/// Set the video mode (2D/3D)
|
|
|
|
/// @param[in] mode The new video mode
|
|
|
|
///
|
2017-08-12 07:55:32 +02:00
|
|
|
virtual void setVideoMode(const VideoMode videoMode);
|
2017-08-04 23:08:15 +02:00
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);
|
2017-08-04 23:08:15 +02:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
signals:
|
|
|
|
void emitImage(int priority, const Image<ColorRgb> & image, const int timeout_ms);
|
|
|
|
|
|
|
|
protected:
|
2016-08-12 23:07:32 +02:00
|
|
|
|
2016-10-10 18:29:54 +02:00
|
|
|
void setColors(const std::vector<ColorRgb> &ledColors, const int timeout_ms);
|
2017-08-12 07:55:32 +02:00
|
|
|
|
2017-02-17 08:33:34 +01:00
|
|
|
QString _grabberName;
|
2016-08-11 07:13:55 +02:00
|
|
|
|
|
|
|
/// 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;
|
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
/// The update rate [Hz]
|
|
|
|
const int _updateInterval_ms;
|
|
|
|
|
|
|
|
/// The timeout of the led colors [ms]
|
|
|
|
const int _timeout_ms;
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
/// The Logger instance
|
|
|
|
Logger * _log;
|
|
|
|
|
|
|
|
// forwarding enabled
|
|
|
|
bool _forward;
|
|
|
|
|
|
|
|
/// The processor for transforming images to led colors
|
|
|
|
ImageProcessor * _processor;
|
|
|
|
|
2016-08-31 00:54:47 +02:00
|
|
|
hyperion::Components _grabberComponentId;
|
2017-08-12 07:55:32 +02:00
|
|
|
|
|
|
|
Grabber *_ggrabber;
|
|
|
|
|
|
|
|
/// The image used for grabbing frames
|
|
|
|
Image<ColorRgb> _image;
|
|
|
|
|
|
|
|
/// The list with computed led colors
|
|
|
|
std::vector<ColorRgb> _ledColors;
|
|
|
|
|
|
|
|
bool _imageProcessorEnabled;
|
2016-08-11 07:13:55 +02:00
|
|
|
};
|
2017-08-12 07:55:32 +02:00
|
|
|
|