hyperion.ng/libsrc/hyperion/BlackBorderProcessor.cpp
T. van der Zwan 0ff4058ba4 Added wrapper for the blackborder detector to maintain state about detected borders.
Added simple unit test for blackborder processor.
2013-08-21 20:44:17 +00:00

58 lines
1.2 KiB
C++

#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;
}