2013-08-23 07:08:44 +02:00
|
|
|
|
|
|
|
// Local-Hyperion includes
|
2013-08-21 22:44:17 +02:00
|
|
|
#include "BlackBorderProcessor.h"
|
|
|
|
|
2013-08-23 07:08:44 +02:00
|
|
|
using namespace hyperion;
|
|
|
|
|
|
|
|
BlackBorderProcessor::BlackBorderProcessor(
|
|
|
|
const unsigned unknownFrameCnt,
|
|
|
|
const unsigned borderFrameCnt,
|
|
|
|
const unsigned blurRemoveCnt) :
|
|
|
|
_unknownSwitchCnt(unknownFrameCnt),
|
|
|
|
_borderSwitchCnt(borderFrameCnt),
|
|
|
|
_blurRemoveCnt(blurRemoveCnt),
|
2013-08-21 22:44:17 +02:00
|
|
|
_detector(),
|
|
|
|
_currentBorder({BlackBorder::unknown, 0}),
|
2013-08-23 18:24:10 +02:00
|
|
|
_previousDetectedBorder({BlackBorder::unknown, 0}),
|
2013-08-21 22:44:17 +02:00
|
|
|
_consistentCnt(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
|
|
|
{
|
2013-08-23 07:08:44 +02:00
|
|
|
if (_currentBorder.size > 0)
|
|
|
|
{
|
|
|
|
return {_currentBorder.type, _currentBorder.size+int(_blurRemoveCnt)};
|
|
|
|
}
|
|
|
|
|
2013-08-21 22:44:17 +02:00
|
|
|
return _currentBorder;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlackBorderProcessor::process(const RgbImage& image)
|
|
|
|
{
|
|
|
|
const BlackBorder imageBorder = _detector.process(image);
|
|
|
|
|
2013-08-23 18:24:10 +02:00
|
|
|
if (imageBorder == _previousDetectedBorder)
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
|
|
|
++_consistentCnt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-23 18:24:10 +02:00
|
|
|
_previousDetectedBorder = imageBorder;
|
|
|
|
_consistentCnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_currentBorder == imageBorder)
|
|
|
|
{
|
|
|
|
// No change required
|
|
|
|
return false;
|
2013-08-21 22:44:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool borderChanged = false;
|
2013-08-23 18:24:10 +02:00
|
|
|
switch (imageBorder.type)
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
|
|
|
case BlackBorder::none:
|
2013-08-23 18:24:10 +02:00
|
|
|
if (_consistentCnt == 0)
|
|
|
|
{
|
|
|
|
_currentBorder = imageBorder;
|
|
|
|
borderChanged = true;
|
|
|
|
}
|
2013-08-21 22:44:17 +02:00
|
|
|
break;
|
|
|
|
case BlackBorder::horizontal:
|
2013-08-23 18:24:10 +02:00
|
|
|
if (_currentBorder.type == BlackBorder::vertical || imageBorder.size < _currentBorder.size || _consistentCnt == _borderSwitchCnt)
|
|
|
|
{
|
|
|
|
_currentBorder = imageBorder;
|
|
|
|
borderChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
2013-08-21 22:44:17 +02:00
|
|
|
case BlackBorder::vertical:
|
2013-08-23 18:24:10 +02:00
|
|
|
if (_currentBorder.type == BlackBorder::horizontal || imageBorder.size < _currentBorder.size || _consistentCnt == _borderSwitchCnt)
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
2013-08-23 18:24:10 +02:00
|
|
|
_currentBorder = imageBorder;
|
2013-08-21 22:44:17 +02:00
|
|
|
borderChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BlackBorder::unknown:
|
|
|
|
if (_consistentCnt == _unknownSwitchCnt)
|
|
|
|
{
|
2013-08-23 18:24:10 +02:00
|
|
|
_currentBorder = imageBorder;
|
2013-08-21 22:44:17 +02:00
|
|
|
borderChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return borderChanged;
|
|
|
|
}
|