grabber api and feature unification (#462)

* move setvideomode to common place

* implement more croping and 3d support

* more api unification

* more refactoring

* osx fix

* next step

* add a mock for osx grabber. Now it is possible to test compile on none osx platforms.

* more unifications ...

* remove obsolete includes and grabbers are not dyn allocated. dispmanx needs rework an probaly not work atm

* first version of dispmanx mock. it compiles, but outputs a black image

* now dispmanx mock works!

* activate mocks in travis linux build
prepare dispmanx to rgb image out

* dispmanx now with image rgb output
fix deadlock with w/h -1 in grabber v4l
cleanups

* fix json

* fix some runtime stuff

* Update FramebufferWrapper.cpp

fix missing code

* unify grabframe

* 3d and croping for amlogic

* fix setimage not working

* make use of templates
save some codelines

* save more code lines
This commit is contained in:
redPanther
2017-08-12 07:55:32 +02:00
committed by GitHub
parent 317a903b14
commit 9eff6384cc
61 changed files with 830 additions and 748 deletions

View File

@@ -3,6 +3,7 @@
#include <QObject>
#include <cstdint>
#include <utils/ColorRgb.h>
#include <utils/Image.h>
#include <utils/VideoMode.h>
#include <utils/GrabbingMode.h>
@@ -16,24 +17,28 @@ class Grabber : public QObject
public:
Grabber(QString grabberName, int width=0, int height=0, int cropLeft=0, int cropRight=0, int cropTop=0, int cropBottom=0);
~Grabber();
virtual ~Grabber();
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
void setVideoMode(VideoMode mode);
virtual void setVideoMode(VideoMode mode);
virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);
/// gets resulting height of image
const int getImageWidth() { return _width; };
virtual const int getImageWidth() { return _width; };
/// gets resulting width of image
const int getImageHeight() { return _height; };
virtual const int getImageHeight() { return _height; };
protected:
ImageResampler _imageResampler;
bool _useImageResampler;
/// the selected VideoMode
VideoMode _videoMode;

View File

@@ -9,14 +9,20 @@
#include <utils/Components.h>
#include <utils/GrabbingMode.h>
#include <hyperion/Hyperion.h>
#include <hyperion/ImageProcessor.h>
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/VideoMode.h>
class ImageProcessor;
class Grabber;
class DispmanxFrameGrabber;
class GrabberWrapper : public QObject
{
Q_OBJECT
public:
GrabberWrapper(QString grabberName, const int priority, hyperion::Components grabberComponentId=hyperion::COMP_GRABBER);
GrabberWrapper(QString grabberName, Grabber * ggrabber, unsigned width, unsigned height, const unsigned updateRate_Hz, const int priority, hyperion::Components grabberComponentId=hyperion::COMP_GRABBER);
virtual ~GrabberWrapper();
@@ -30,8 +36,32 @@ public:
///
virtual void stop();
void setImageProcessorEnabled(bool enable);
static QStringList availableGrabbers();
public:
template <typename Grabber_T>
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);
@@ -50,8 +80,9 @@ public slots:
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
virtual void setVideoMode(const VideoMode videoMode) = 0;
virtual void setVideoMode(const VideoMode videoMode);
virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);
signals:
void emitImage(int priority, const Image<ColorRgb> & image, const int timeout_ms);
@@ -59,6 +90,7 @@ signals:
protected:
void setColors(const std::vector<ColorRgb> &ledColors, const int timeout_ms);
QString _grabberName;
/// Pointer to Hyperion for writing led values
@@ -70,6 +102,12 @@ protected:
/// 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;
@@ -80,4 +118,15 @@ protected:
ImageProcessor * _processor;
hyperion::Components _grabberComponentId;
Grabber *_ggrabber;
/// The image used for grabbing frames
Image<ColorRgb> _image;
/// The list with computed led colors
std::vector<ColorRgb> _ledColors;
bool _imageProcessorEnabled;
};

View File

@@ -260,7 +260,7 @@ public slots:
///
/// Clears all priority channels. This will switch the leds off until a new priority is written.
///
void clearall();
void clearall(bool forceClearAll=false);
/// Run the specified effect on the given priority channel and optionally specify a timeout
/// @param effectName Name of the effec to run

View File

@@ -42,7 +42,6 @@ public:
///
void setSize(const unsigned width, const unsigned height);
/// Returns starte of black border detector
bool blackBorderDetectorEnabled();
@@ -59,7 +58,20 @@ public slots:
/// Enable or disable the black border detector
void setLedMappingType(int mapType);
public:
public:
///
/// Specifies the width and height of 'incomming' images. This will resize the buffer-image to
/// match the given size.
/// NB All earlier obtained references will be invalid.
///
/// @param[in] image The dimensions taken from image
///
template <typename Pixel_T>
void setSize(const Image<Pixel_T> &image)
{
setSize(image.width(), image.height());
}
///
/// Processes the image to a list of led colors. This will update the size of the buffer-image
/// if required and call the image-to-leds mapping to determine the mean color per led.
@@ -71,18 +83,25 @@ public:
template <typename Pixel_T>
std::vector<ColorRgb> process(const Image<Pixel_T>& image)
{
// Ensure that the buffer-image is the proper size
setSize(image.width(), image.height());
// Check black border detection
verifyBorder(image);
// Create a result vector and call the 'in place' functionl
std::vector<ColorRgb> colors;
switch (_mappingType)
if (image.width()>0 && image.height()>0)
{
case 1: colors = _imageToLeds->getUniLedColor(image); break;
default: colors = _imageToLeds->getMeanLedColor(image);
// Ensure that the buffer-image is the proper size
setSize(image);
// Check black border detection
verifyBorder(image);
// Create a result vector and call the 'in place' functionl
switch (_mappingType)
{
case 1: colors = _imageToLeds->getUniLedColor(image); break;
default: colors = _imageToLeds->getMeanLedColor(image);
}
}
else
{
Warning(_log, "ImageProcessor::process called without image size 0");
}
// return the computed colors
@@ -98,19 +117,25 @@ public:
template <typename Pixel_T>
void process(const Image<Pixel_T>& image, std::vector<ColorRgb>& ledColors)
{
// Ensure that the buffer-image is the proper size
setSize(image.width(), image.height());
// Check black border detection
verifyBorder(image);
// Determine the mean-colors of each led (using the existing mapping)
switch (_mappingType)
if ( image.width()>0 && image.height()>0)
{
case 1: _imageToLeds->getUniLedColor(image, ledColors); break;
default: _imageToLeds->getMeanLedColor(image, ledColors);
}
// Ensure that the buffer-image is the proper size
setSize(image);
// Check black border detection
verifyBorder(image);
// Determine the mean-colors of each led (using the existing mapping)
switch (_mappingType)
{
case 1: _imageToLeds->getUniLedColor(image, ledColors); break;
default: _imageToLeds->getMeanLedColor(image, ledColors);
}
}
else
{
Warning(_log, "ImageProcessor::process called without image size 0");
}
}
///

View File

@@ -118,7 +118,7 @@ public:
///
/// Clears all priority channels
///
void clearAll();
void clearAll(bool forceClearAll=false);
///
/// Updates the current time. Channels with a configured time out will be checked and cleared if
@@ -152,5 +152,4 @@ private:
QTimer _timer;
QTimer _blockTimer;
};