Skip to content

Commit 6ee9440

Browse files
committed
Added blackborder detection and processing to the image processor
1 parent 046c685 commit 6ee9440

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

include/hyperion/ImageProcessor.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
// Utils includes
55
#include <utils/RgbImage.h>
66

7-
#include <hyperion/LedString.h>
7+
// Hyperion includes
88
#include <hyperion/ImageProcessorFactory.h>
9+
#include <hyperion/LedString.h>
910

1011
// Forward class declaration
11-
namespace hyperion { class ImageToLedsMap; }
12+
namespace hyperion {
13+
class ImageToLedsMap;
14+
class BlackBorderProcessor;
15+
}
1216

1317
/**
1418
* The ImageProcessor translates an RGB-image to RGB-values for the leds. The processing is
@@ -52,9 +56,15 @@ class ImageProcessor
5256

5357
ImageProcessor(const LedString &ledString);
5458

59+
void verifyBorder(const RgbImage& image);
5560
private:
5661
const LedString mLedString;
5762

63+
bool _enableBlackBorderRemoval;
64+
65+
/// The processor for black border detection
66+
hyperion::BlackBorderProcessor* _borderProcessor;
67+
5868
hyperion::ImageToLedsMap* mImageToLeds;
5969
};
6070

libsrc/hyperion/ImageProcessor.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
#include <hyperion/ImageProcessor.h>
21

2+
// Hyperion includes
3+
#include <hyperion/ImageProcessor.h>
34

4-
#include "ImageToLedsMap.h"
5+
// Local-Hyperion includes
6+
#include "BlackBorderProcessor.h"
57
#include "ColorTransform.h"
8+
#include "ImageToLedsMap.h"
69

710
using namespace hyperion;
811

912
ImageProcessor::ImageProcessor(const LedString& ledString) :
1013
mLedString(ledString),
14+
_enableBlackBorderRemoval(true),
15+
_borderProcessor(new BlackBorderProcessor(600, 50, 1)),
1116
mImageToLeds(nullptr)
1217
{
1318
// empty
@@ -16,6 +21,7 @@ ImageProcessor::ImageProcessor(const LedString& ledString) :
1621
ImageProcessor::~ImageProcessor()
1722
{
1823
delete mImageToLeds;
24+
delete _borderProcessor;
1925
}
2026

2127
void ImageProcessor::setSize(const unsigned width, const unsigned height)
@@ -38,6 +44,9 @@ std::vector<RgbColor> ImageProcessor::process(const RgbImage& image)
3844
// Ensure that the buffer-image is the proper size
3945
setSize(image.width(), image.height());
4046

47+
// Check black border detection
48+
verifyBorder(image);
49+
4150
// Create a result vector and call the 'in place' functionl
4251
std::vector<RgbColor> colors = mImageToLeds->getMeanLedColor(image);
4352

@@ -47,6 +56,42 @@ std::vector<RgbColor> ImageProcessor::process(const RgbImage& image)
4756

4857
void ImageProcessor::process(const RgbImage& image, std::vector<RgbColor>& ledColors)
4958
{
59+
// Check black border detection
60+
verifyBorder(image);
61+
5062
// Determine the mean-colors of each led (using the existing mapping)
5163
mImageToLeds->getMeanLedColor(image, ledColors);
5264
}
65+
66+
void ImageProcessor::verifyBorder(const RgbImage& image)
67+
{
68+
if(_enableBlackBorderRemoval && _borderProcessor->process(image))
69+
{
70+
std::cout << "BORDER SWITCH REQUIRED!!" << std::endl;
71+
72+
const BlackBorder border = _borderProcessor->getCurrentBorder();
73+
74+
// Clean up the old mapping
75+
delete mImageToLeds;
76+
77+
switch (border.type)
78+
{
79+
case BlackBorder::none:
80+
case BlackBorder::unknown:
81+
// Construct a new buffer and mapping
82+
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds());
83+
break;
84+
case BlackBorder::horizontal:
85+
// Construct a new buffer and mapping
86+
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), border.size, 0, mLedString.leds());
87+
break;
88+
case BlackBorder::vertical:
89+
// Construct a new buffer and mapping
90+
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), 0, border.size, mLedString.leds());
91+
break;
92+
}
93+
94+
std::cout << "CURRENT BORDER TYPE: " << _borderProcessor->getCurrentBorder().type << " (size=" << _borderProcessor->getCurrentBorder().size << ")" << std::endl;
95+
}
96+
97+
}

0 commit comments

Comments
 (0)