mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added wrapper for the blackborder detector to maintain state about detected borders.
Added simple unit test for blackborder processor.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
|
||||
// Local-Hyperion includes
|
||||
#include "BlackBorderDetector.h"
|
||||
|
||||
BlackBorderDetector::BlackBorderDetector()
|
||||
|
57
libsrc/hyperion/BlackBorderProcessor.cpp
Normal file
57
libsrc/hyperion/BlackBorderProcessor.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "BlackBorderProcessor.h"
|
||||
|
||||
BlackBorderProcessor::BlackBorderProcessor() :
|
||||
_unknownSwitchCnt(600),
|
||||
_borderSwitchCnt(50),
|
||||
_detector(),
|
||||
_currentBorder({BlackBorder::unknown, 0}),
|
||||
_lastDetectedBorder({BlackBorder::unknown, 0}),
|
||||
_consistentCnt(0)
|
||||
{
|
||||
}
|
||||
|
||||
BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
||||
{
|
||||
return _currentBorder;
|
||||
}
|
||||
|
||||
bool BlackBorderProcessor::process(const RgbImage& image)
|
||||
{
|
||||
const BlackBorder imageBorder = _detector.process(image);
|
||||
|
||||
if (imageBorder.type == _lastDetectedBorder.type && imageBorder.size == _lastDetectedBorder.size)
|
||||
{
|
||||
++_consistentCnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastDetectedBorder = imageBorder;
|
||||
_consistentCnt = 0;
|
||||
}
|
||||
|
||||
bool borderChanged = false;
|
||||
switch (_lastDetectedBorder.type)
|
||||
{
|
||||
case BlackBorder::none:
|
||||
borderChanged = (_currentBorder.type != BlackBorder::none);
|
||||
_currentBorder = _lastDetectedBorder;
|
||||
break;
|
||||
case BlackBorder::horizontal:
|
||||
case BlackBorder::vertical:
|
||||
if (_consistentCnt == _borderSwitchCnt)
|
||||
{
|
||||
_currentBorder = _lastDetectedBorder;
|
||||
borderChanged = true;
|
||||
}
|
||||
break;
|
||||
case BlackBorder::unknown:
|
||||
if (_consistentCnt == _unknownSwitchCnt)
|
||||
{
|
||||
_currentBorder = _lastDetectedBorder;
|
||||
borderChanged = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return borderChanged;
|
||||
}
|
30
libsrc/hyperion/BlackBorderProcessor.h
Normal file
30
libsrc/hyperion/BlackBorderProcessor.h
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "BlackBorderDetector.h"
|
||||
|
||||
class BlackBorderProcessor
|
||||
{
|
||||
public:
|
||||
BlackBorderProcessor();
|
||||
|
||||
BlackBorder getCurrentBorder() const;
|
||||
|
||||
bool process(const RgbImage& image);
|
||||
|
||||
private:
|
||||
|
||||
const unsigned _unknownSwitchCnt;
|
||||
|
||||
const unsigned _borderSwitchCnt;
|
||||
|
||||
BlackBorderDetector _detector;
|
||||
|
||||
BlackBorder _currentBorder;
|
||||
|
||||
BlackBorder _lastDetectedBorder;
|
||||
|
||||
unsigned _consistentCnt;
|
||||
};
|
||||
|
@@ -18,6 +18,7 @@ SET(Hyperion_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||
${CURRENT_SOURCE_DIR}/ImageToLedsMap.h
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.h
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderDetector.h
|
||||
${CURRENT_SOURCE_DIR}/ColorTransform.h
|
||||
)
|
||||
@@ -32,6 +33,7 @@ SET(Hyperion_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
|
||||
${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.cpp
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderDetector.cpp
|
||||
${CURRENT_SOURCE_DIR}/ColorTransform.cpp
|
||||
)
|
||||
|
Reference in New Issue
Block a user