2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
// Hyperion includes
|
|
|
|
#include <hyperion/ImageProcessor.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-23 18:24:10 +02:00
|
|
|
#include <utils/ColorTransform.h>
|
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
// Local-Hyperion includes
|
|
|
|
#include "BlackBorderProcessor.h"
|
|
|
|
#include "ImageToLedsMap.h"
|
2013-08-13 11:10:45 +02:00
|
|
|
|
|
|
|
using namespace hyperion;
|
|
|
|
|
2013-10-20 22:27:05 +02:00
|
|
|
ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector) :
|
2013-08-13 11:10:45 +02:00
|
|
|
mLedString(ledString),
|
2013-10-20 22:27:05 +02:00
|
|
|
_enableBlackBorderRemoval(enableBlackBorderDetector),
|
2013-08-23 07:09:09 +02:00
|
|
|
_borderProcessor(new BlackBorderProcessor(600, 50, 1)),
|
2013-08-13 11:10:45 +02:00
|
|
|
mImageToLeds(nullptr)
|
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageProcessor::~ImageProcessor()
|
|
|
|
{
|
|
|
|
delete mImageToLeds;
|
2013-08-23 07:09:09 +02:00
|
|
|
delete _borderProcessor;
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImageProcessor::setSize(const unsigned width, const unsigned height)
|
|
|
|
{
|
|
|
|
// Check if the existing buffer-image is already the correct dimensions
|
2013-08-14 17:02:09 +02:00
|
|
|
if (mImageToLeds && mImageToLeds->width() == width && mImageToLeds->height() == height)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up the old buffer and mapping
|
|
|
|
delete mImageToLeds;
|
|
|
|
|
|
|
|
// Construct a new buffer and mapping
|
2013-08-21 17:24:42 +02:00
|
|
|
mImageToLeds = new ImageToLedsMap(width, height, 0, 0, mLedString.leds());
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
std::vector<RgbColor> ImageProcessor::process(const RgbImage& image)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
2013-08-14 17:02:09 +02:00
|
|
|
// Ensure that the buffer-image is the proper size
|
|
|
|
setSize(image.width(), image.height());
|
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
// Check black border detection
|
|
|
|
verifyBorder(image);
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
// Create a result vector and call the 'in place' functionl
|
|
|
|
std::vector<RgbColor> colors = mImageToLeds->getMeanLedColor(image);
|
|
|
|
|
|
|
|
// return the computed colors
|
|
|
|
return colors;
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
void ImageProcessor::process(const RgbImage& image, std::vector<RgbColor>& ledColors)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
2013-10-21 21:13:01 +02:00
|
|
|
// Ensure that the buffer-image is the proper size
|
|
|
|
setSize(image.width(), image.height());
|
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
// Check black border detection
|
|
|
|
verifyBorder(image);
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// Determine the mean-colors of each led (using the existing mapping)
|
2013-08-14 17:02:09 +02:00
|
|
|
mImageToLeds->getMeanLedColor(image, ledColors);
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
2013-08-23 07:09:09 +02:00
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &hscanEnd, double &vscanBegin, double &vscanEnd) const
|
|
|
|
{
|
|
|
|
if (led < mLedString.leds().size())
|
|
|
|
{
|
|
|
|
const Led & l = mLedString.leds()[led];
|
|
|
|
hscanBegin = l.minX_frac;
|
|
|
|
hscanEnd = l.maxX_frac;
|
|
|
|
vscanBegin = l.minY_frac;
|
|
|
|
vscanEnd = l.maxY_frac;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
void ImageProcessor::verifyBorder(const RgbImage& image)
|
|
|
|
{
|
|
|
|
if(_enableBlackBorderRemoval && _borderProcessor->process(image))
|
|
|
|
{
|
|
|
|
std::cout << "BORDER SWITCH REQUIRED!!" << std::endl;
|
|
|
|
|
|
|
|
const BlackBorder border = _borderProcessor->getCurrentBorder();
|
|
|
|
|
|
|
|
// Clean up the old mapping
|
|
|
|
delete mImageToLeds;
|
|
|
|
|
2013-10-27 09:25:02 +01:00
|
|
|
if (border.unknown)
|
2013-08-23 07:09:09 +02:00
|
|
|
{
|
|
|
|
// Construct a new buffer and mapping
|
|
|
|
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds());
|
2013-10-27 09:25:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-23 07:09:09 +02:00
|
|
|
// Construct a new buffer and mapping
|
2013-10-27 09:25:02 +01:00
|
|
|
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds());
|
2013-08-23 07:09:09 +02:00
|
|
|
}
|
|
|
|
|
2013-10-27 09:25:02 +01:00
|
|
|
std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl;
|
2013-08-23 07:09:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|