mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added blackborder detection and processing to the image processor
This commit is contained in:
parent
046c68574e
commit
6ee94409dc
@ -4,11 +4,15 @@
|
||||
// Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
|
||||
#include <hyperion/LedString.h>
|
||||
// Hyperion includes
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
#include <hyperion/LedString.h>
|
||||
|
||||
// Forward class declaration
|
||||
namespace hyperion { class ImageToLedsMap; }
|
||||
namespace hyperion {
|
||||
class ImageToLedsMap;
|
||||
class BlackBorderProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ImageProcessor translates an RGB-image to RGB-values for the leds. The processing is
|
||||
@ -52,9 +56,15 @@ private:
|
||||
|
||||
ImageProcessor(const LedString &ledString);
|
||||
|
||||
void verifyBorder(const RgbImage& image);
|
||||
private:
|
||||
const LedString mLedString;
|
||||
|
||||
bool _enableBlackBorderRemoval;
|
||||
|
||||
/// The processor for black border detection
|
||||
hyperion::BlackBorderProcessor* _borderProcessor;
|
||||
|
||||
hyperion::ImageToLedsMap* mImageToLeds;
|
||||
};
|
||||
|
||||
|
@ -1,13 +1,18 @@
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
|
||||
|
||||
#include "ImageToLedsMap.h"
|
||||
// Local-Hyperion includes
|
||||
#include "BlackBorderProcessor.h"
|
||||
#include "ColorTransform.h"
|
||||
#include "ImageToLedsMap.h"
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
ImageProcessor::ImageProcessor(const LedString& ledString) :
|
||||
mLedString(ledString),
|
||||
_enableBlackBorderRemoval(true),
|
||||
_borderProcessor(new BlackBorderProcessor(600, 50, 1)),
|
||||
mImageToLeds(nullptr)
|
||||
{
|
||||
// empty
|
||||
@ -16,6 +21,7 @@ ImageProcessor::ImageProcessor(const LedString& ledString) :
|
||||
ImageProcessor::~ImageProcessor()
|
||||
{
|
||||
delete mImageToLeds;
|
||||
delete _borderProcessor;
|
||||
}
|
||||
|
||||
void ImageProcessor::setSize(const unsigned width, const unsigned height)
|
||||
@ -38,6 +44,9 @@ std::vector<RgbColor> ImageProcessor::process(const RgbImage& 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<RgbColor> colors = mImageToLeds->getMeanLedColor(image);
|
||||
|
||||
@ -47,6 +56,42 @@ std::vector<RgbColor> ImageProcessor::process(const RgbImage& image)
|
||||
|
||||
void ImageProcessor::process(const RgbImage& image, std::vector<RgbColor>& ledColors)
|
||||
{
|
||||
// Check black border detection
|
||||
verifyBorder(image);
|
||||
|
||||
// Determine the mean-colors of each led (using the existing mapping)
|
||||
mImageToLeds->getMeanLedColor(image, ledColors);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
switch (border.type)
|
||||
{
|
||||
case BlackBorder::none:
|
||||
case BlackBorder::unknown:
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds());
|
||||
break;
|
||||
case BlackBorder::horizontal:
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), border.size, 0, mLedString.leds());
|
||||
break;
|
||||
case BlackBorder::vertical:
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), 0, border.size, mLedString.leds());
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "CURRENT BORDER TYPE: " << _borderProcessor->getCurrentBorder().type << " (size=" << _borderProcessor->getCurrentBorder().size << ")" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user