2013-08-13 11:10:45 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Utils includes
|
2013-11-11 10:00:37 +01:00
|
|
|
#include <utils/Image.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
// Hyperion includes
|
2013-08-13 11:10:45 +02:00
|
|
|
#include <hyperion/ImageProcessorFactory.h>
|
2013-08-23 07:09:09 +02:00
|
|
|
#include <hyperion/LedString.h>
|
2013-11-11 10:00:37 +01:00
|
|
|
#include <hyperion/ImageToLedsMap.h>
|
|
|
|
#include <hyperion/BlackBorderProcessor.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// The ImageProcessor translates an RGB-image to RGB-values for the leds. The processing is
|
|
|
|
/// performed in two steps. First the average color per led-region is computed. Second a
|
|
|
|
/// color-tranform is applied based on a gamma-correction.
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
class ImageProcessor
|
|
|
|
{
|
|
|
|
public:
|
2013-08-13 12:03:00 +02:00
|
|
|
~ImageProcessor();
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// 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] width The new width of the buffer-image
|
|
|
|
/// @param[in] height The new height of the buffer-image
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
void setSize(const unsigned width, const unsigned height);
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
/// @param[in] image The image to translate to led values
|
|
|
|
///
|
|
|
|
/// @return The color value per led
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
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 = mImageToLeds->getMeanLedColor(image);
|
|
|
|
|
|
|
|
// return the computed colors
|
|
|
|
return colors;
|
|
|
|
}
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Determines the led colors of the image in the buffer.
|
|
|
|
///
|
2013-09-09 22:35:28 +02:00
|
|
|
/// @param[in] image The image to translate to led values
|
2013-09-06 21:26:58 +02:00
|
|
|
/// @param[out] ledColors The color value per led
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
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)
|
|
|
|
mImageToLeds->getMeanLedColor(image, ledColors);
|
|
|
|
}
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
///
|
|
|
|
/// Get the hscan and vscan parameters for a single led
|
|
|
|
///
|
|
|
|
/// @param[in] led Index of the led
|
|
|
|
/// @param[out] hscanBegin begin of the hscan
|
|
|
|
/// @param[out] hscanEnd end of the hscan
|
|
|
|
/// @param[out] vscanBegin begin of the hscan
|
|
|
|
/// @param[out] vscanEnd end of the hscan
|
|
|
|
/// @return true if the parameters could be retrieved
|
|
|
|
bool getScanParameters(size_t led, double & hscanBegin, double & hscanEnd, double & vscanBegin, double & vscanEnd) const;
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
private:
|
2013-09-06 21:26:58 +02:00
|
|
|
/// Friend declaration of the factory for creating ImageProcessor's
|
2013-08-13 11:10:45 +02:00
|
|
|
friend class ImageProcessorFactory;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Constructs an image-processor for translating an image to led-color values based on the
|
|
|
|
/// given led-string specification
|
|
|
|
///
|
|
|
|
/// @param[in] ledString The led-string specification
|
|
|
|
///
|
2013-10-20 22:27:05 +02:00
|
|
|
ImageProcessor(const LedString &ledString, bool enableBlackBorderDetector);
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Performs black-border detection (if enabled) on the given image
|
|
|
|
///
|
|
|
|
/// @param[in] image The image to perform black-border detection on
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
template <typename Pixel_T>
|
|
|
|
void verifyBorder(const Image<Pixel_T> & image)
|
|
|
|
{
|
|
|
|
if(_enableBlackBorderRemoval && _borderProcessor->process(image))
|
|
|
|
{
|
|
|
|
std::cout << "BORDER SWITCH REQUIRED!!" << std::endl;
|
|
|
|
|
|
|
|
const hyperion::BlackBorder border = _borderProcessor->getCurrentBorder();
|
|
|
|
|
|
|
|
// Clean up the old mapping
|
|
|
|
delete mImageToLeds;
|
|
|
|
|
|
|
|
if (border.unknown)
|
|
|
|
{
|
|
|
|
// Construct a new buffer and mapping
|
|
|
|
mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Construct a new buffer and mapping
|
|
|
|
mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
private:
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The Led-string specification
|
2013-08-13 11:10:45 +02:00
|
|
|
const LedString mLedString;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// Flag the enables(true)/disabled(false) blackborder detector
|
2013-08-23 07:09:09 +02:00
|
|
|
bool _enableBlackBorderRemoval;
|
|
|
|
|
|
|
|
/// The processor for black border detection
|
2013-11-11 10:00:37 +01:00
|
|
|
hyperion::BlackBorderProcessor * _borderProcessor;
|
2013-08-23 07:09:09 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The mapping of image-pixels to leds
|
2013-08-13 11:10:45 +02:00
|
|
|
hyperion::ImageToLedsMap* mImageToLeds;
|
|
|
|
};
|