Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 95b77de

Browse files
committed
Configurable blackborder threshold added
1 parent 022ed45 commit 95b77de

15 files changed

+120
-48
lines changed

config/hyperion.config.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@
5656
"red" :
5757
{
5858
"threshold" : 0.0000,
59-
"gamma" : 2.0000,
59+
"gamma" : 1.0000,
6060
"blacklevel" : 0.0000,
6161
"whitelevel" : 1.0000
6262
},
6363
"green" :
6464
{
6565
"threshold" : 0.0000,
66-
"gamma" : 2.0000,
66+
"gamma" : 1.0000,
6767
"blacklevel" : 0.0000,
6868
"whitelevel" : 1.0000
6969
},
7070
"blue" :
7171
{
7272
"threshold" : 0.0000,
73-
"gamma" : 2.0000,
73+
"gamma" : 1.0000,
7474
"blacklevel" : 0.0000,
7575
"whitelevel" : 1.0000
7676
}
@@ -348,10 +348,12 @@
348348
],
349349

350350
/// The black border configuration, contains the following items:
351-
/// * enable : true if the detector should be activated
351+
/// * enable : true if the detector should be activated
352+
/// * threshold : Value below which a pixel is regarded as black (value between 0.0 and 1.0)
352353
"blackborderdetector" :
353354
{
354-
"enable" : true
355+
"enable" : true,
356+
"threshold" : 0.01
355357
},
356358

357359
/// The configuration of the effect engine, contains the following items:

config/hyperion_x86.config.json

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"device" :
1414
{
1515
"name" : "MyPi",
16-
"type" : "test",
17-
"output" : "~/hyperion.test.out",
18-
"rate" : 250000,
16+
"type" : "adalight",
17+
"output" : "/dev/ttyUSB0",
18+
"rate" : 115200,
1919
"colorOrder" : "rgb"
2020
},
2121

@@ -348,10 +348,12 @@
348348
],
349349

350350
/// The black border configuration, contains the following items:
351-
/// * enable : true if the detector should be activated
351+
/// * enable : true if the detector should be activated
352+
/// * threshold : Value below which a pixel is regarded as black (value between 0.0 and 1.0)
352353
"blackborderdetector" :
353354
{
354-
"enable" : true
355+
"enable" : true,
356+
"threshold" : 0.01
355357
},
356358

357359
/// The configuration of the effect engine, contains the following items:
@@ -371,6 +373,38 @@
371373
"duration_ms" : 3000
372374
},
373375

376+
/// The configuration for the frame-grabber, contains the following items:
377+
/// * width : The width of the grabbed frames [pixels]
378+
/// * height : The height of the grabbed frames [pixels]
379+
/// * frequency_Hz : The frequency of the frame grab [Hz]
380+
// "framegrabber" :
381+
// {
382+
// "width" : 64,
383+
// "height" : 64,
384+
// "frequency_Hz" : 10.0
385+
// },
386+
387+
/// The configuration of the XBMC connection used to enable and disable the frame-grabber. Contains the following fields:
388+
/// * xbmcAddress : The IP address of the XBMC-host
389+
/// * xbmcTcpPort : The TCP-port of the XBMC-server
390+
/// * grabVideo : Flag indicating that the frame-grabber is on(true) during video playback
391+
/// * grabPictures : Flag indicating that the frame-grabber is on(true) during picture show
392+
/// * grabAudio : Flag indicating that the frame-grabber is on(true) during audio playback
393+
/// * grabMenu : Flag indicating that the frame-grabber is on(true) in the XBMC menu
394+
/// * grabScreensaver : Flag indicating that the frame-grabber is on(true) when XBMC is on screensaver
395+
/// * enable3DDetection : Flag indicating that the frame-grabber should switch to a 3D compatible modus if a 3D video is playing
396+
// "xbmcVideoChecker" :
397+
// {
398+
// "xbmcAddress" : "127.0.0.1",
399+
// "xbmcTcpPort" : 9090,
400+
// "grabVideo" : true,
401+
// "grabPictures" : true,
402+
// "grabAudio" : true,
403+
// "grabMenu" : false,
404+
// "grabScreensaver" : true,
405+
// "enable3DDetection" : true
406+
// },
407+
374408
/// The configuration of the Json server which enables the json remote interface
375409
/// * port : Port at which the json server is started
376410
"jsonServer" :

deploy/hyperion.tar.gz

-100 Bytes
Binary file not shown.

include/hyperion/BlackBorderDetector.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ namespace hyperion
4848
public:
4949
///
5050
/// Constructs a black-border detector
51+
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
5152
///
52-
BlackBorderDetector();
53+
BlackBorderDetector(uint8_t blackborderThreshold);
5354

5455
///
5556
/// Performs the actual black-border detection on the given image
@@ -125,7 +126,11 @@ namespace hyperion
125126
inline bool isBlack(const Pixel_T & color)
126127
{
127128
// Return the simple compare of the color against black
128-
return color.red < 3 && color.green < 3 && color.green < 3;
129+
return color.red < _blackborderThreshold && color.green < _blackborderThreshold && color.green < _blackborderThreshold;
129130
}
131+
132+
private:
133+
/// Threshold for the blackborder detector [0 .. 255]
134+
const uint8_t _blackborderThreshold;
130135
};
131136
} // end namespace hyperion

include/hyperion/BlackBorderProcessor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ namespace hyperion
2121
/// horizontal border becomes the current border
2222
/// @param blurRemoveCnt The size to add to a horizontal or vertical border (because the
2323
/// outer pixels is blurred (black and color combined due to image scaling))
24+
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
2425
///
2526
BlackBorderProcessor(
2627
const unsigned unknownFrameCnt,
2728
const unsigned borderFrameCnt,
28-
const unsigned blurRemoveCnt);
29+
const unsigned blurRemoveCnt,
30+
uint8_t blackborderThreshold);
2931

3032
///
3133
/// Return the current (detected) border

include/hyperion/ImageProcessor.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ImageProcessor
5353
verifyBorder(image);
5454

5555
// Create a result vector and call the 'in place' functionl
56-
std::vector<ColorRgb> colors = mImageToLeds->getMeanLedColor(image);
56+
std::vector<ColorRgb> colors = _imageToLeds->getMeanLedColor(image);
5757

5858
// return the computed colors
5959
return colors;
@@ -75,7 +75,7 @@ class ImageProcessor
7575
verifyBorder(image);
7676

7777
// Determine the mean-colors of each led (using the existing mapping)
78-
mImageToLeds->getMeanLedColor(image, ledColors);
78+
_imageToLeds->getMeanLedColor(image, ledColors);
7979
}
8080

8181
///
@@ -98,8 +98,10 @@ class ImageProcessor
9898
/// given led-string specification
9999
///
100100
/// @param[in] ledString The led-string specification
101+
/// @param[in] enableBlackBorderDetector Flag indicating if the blacborder detector should be enabled
102+
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
101103
///
102-
ImageProcessor(const LedString &ledString, bool enableBlackBorderDetector);
104+
ImageProcessor(const LedString &ledString, bool enableBlackBorderDetector, uint8_t blackborderThreshold);
103105

104106
///
105107
/// Performs black-border detection (if enabled) on the given image
@@ -116,17 +118,17 @@ class ImageProcessor
116118
const hyperion::BlackBorder border = _borderProcessor->getCurrentBorder();
117119

118120
// Clean up the old mapping
119-
delete mImageToLeds;
121+
delete _imageToLeds;
120122

121123
if (border.unknown)
122124
{
123125
// Construct a new buffer and mapping
124-
mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds());
126+
_imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, _ledString.leds());
125127
}
126128
else
127129
{
128130
// Construct a new buffer and mapping
129-
mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds());
131+
_imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, _ledString.leds());
130132
}
131133

132134
std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl;
@@ -135,14 +137,14 @@ class ImageProcessor
135137

136138
private:
137139
/// The Led-string specification
138-
const LedString mLedString;
140+
const LedString _ledString;
139141

140142
/// Flag the enables(true)/disabled(false) blackborder detector
141-
bool _enableBlackBorderRemoval;
143+
const bool _enableBlackBorderRemoval;
142144

143145
/// The processor for black border detection
144146
hyperion::BlackBorderProcessor * _borderProcessor;
145147

146148
/// The mapping of image-pixels to leds
147-
hyperion::ImageToLedsMap* mImageToLeds;
149+
hyperion::ImageToLedsMap* _imageToLeds;
148150
};

include/hyperion/ImageProcessorFactory.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class ImageProcessorFactory
3030
/// Initialises this factory with the given led-configuration
3131
///
3232
/// @param[in] ledString The led configuration
33+
/// @param[in] enableBlackBorderDetector Flag indicating if the blacborder detector should be enabled
34+
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
3335
///
34-
void init(const LedString& ledString, bool enableBlackBorderDetector);
36+
void init(const LedString& ledString, bool enableBlackBorderDetector, double blackborderThreshold);
3537

3638
///
3739
/// Creates a new ImageProcessor. The onwership of the processor is transferred to the caller.
@@ -46,4 +48,7 @@ class ImageProcessorFactory
4648

4749
/// Flag indicating if the black border detector should be used
4850
bool _enableBlackBorderDetector;
51+
52+
/// Threshold for the blackborder detector [0 .. 255]
53+
uint8_t _blackborderThreshold;
4954
};

libsrc/hyperion/BlackBorderDetector.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
using namespace hyperion;
66

7-
BlackBorderDetector::BlackBorderDetector()
7+
BlackBorderDetector::BlackBorderDetector(uint8_t blackborderThreshold) :
8+
_blackborderThreshold(blackborderThreshold)
89
{
910
// empty
1011
}

libsrc/hyperion/BlackBorderProcessor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
using namespace hyperion;
66

7-
BlackBorderProcessor::BlackBorderProcessor(
8-
const unsigned unknownFrameCnt,
7+
BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt,
98
const unsigned borderFrameCnt,
10-
const unsigned blurRemoveCnt) :
9+
const unsigned blurRemoveCnt,
10+
uint8_t blackborderThreshold) :
1111
_unknownSwitchCnt(unknownFrameCnt),
1212
_borderSwitchCnt(borderFrameCnt),
1313
_blurRemoveCnt(blurRemoveCnt),
14-
_detector(),
14+
_detector(blackborderThreshold),
1515
_currentBorder({true, -1, -1}),
1616
_previousDetectedBorder({true, -1, -1}),
1717
_consistentCnt(0)

libsrc/hyperion/Hyperion.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) :
270270
throw std::runtime_error("Color transformation incorrectly set");
271271
}
272272
// initialize the image processor factory
273-
ImageProcessorFactory::getInstance().init(_ledString, jsonConfig["blackborderdetector"].get("enable", true).asBool());
273+
ImageProcessorFactory::getInstance().init(
274+
_ledString,
275+
jsonConfig["blackborderdetector"].get("enable", true).asBool(),
276+
jsonConfig["blackborderdetector"].get("threshold", 0.01).asDouble());
274277

275278
// initialize the color smoothing filter
276279
_device = createColorSmoothing(jsonConfig["color"]["smoothing"], _device);

0 commit comments

Comments
 (0)