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(),
|
2013-10-27 09:25:02 +01:00
|
|
|
_currentBorder({true, -1, -1}),
|
|
|
|
_previousDetectedBorder({true, -1, -1}),
|
2013-08-21 22:44:17 +02:00
|
|
|
_consistentCnt(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
|
|
|
{
|
|
|
|
return _currentBorder;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlackBorderProcessor::process(const RgbImage& image)
|
|
|
|
{
|
2013-10-27 09:25:02 +01:00
|
|
|
// get the border for the single image
|
|
|
|
BlackBorder imageBorder = _detector.process(image);
|
|
|
|
|
|
|
|
// add blur to the border
|
|
|
|
if (imageBorder.horizontalSize > 0)
|
|
|
|
{
|
|
|
|
imageBorder.horizontalSize += _blurRemoveCnt;
|
|
|
|
}
|
|
|
|
if (imageBorder.verticalSize > 0)
|
|
|
|
{
|
|
|
|
imageBorder.verticalSize += _blurRemoveCnt;
|
|
|
|
}
|
2013-08-21 22:44:17 +02:00
|
|
|
|
2013-10-27 09:25:02 +01:00
|
|
|
// set the consistency counter
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-27 09:25:02 +01:00
|
|
|
// check if there is a change
|
2013-08-23 18:24:10 +02:00
|
|
|
if (_currentBorder == imageBorder)
|
|
|
|
{
|
|
|
|
// No change required
|
|
|
|
return false;
|
2013-08-21 22:44:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool borderChanged = false;
|
2013-10-27 09:25:02 +01:00
|
|
|
if (imageBorder.unknown)
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
2013-10-27 09:25:02 +01:00
|
|
|
// apply the unknown border if we consistently can't determine a border
|
|
|
|
if (_consistentCnt == _unknownSwitchCnt)
|
2013-08-23 18:24:10 +02:00
|
|
|
{
|
|
|
|
_currentBorder = imageBorder;
|
|
|
|
borderChanged = true;
|
|
|
|
}
|
2013-10-27 09:25:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// apply the detected border if it has been detected consistently
|
|
|
|
if (_currentBorder.unknown || _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;
|
|
|
|
}
|
2013-10-27 09:25:02 +01:00
|
|
|
else
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
2013-10-27 09:25:02 +01:00
|
|
|
// apply smaller borders immediately
|
|
|
|
if (imageBorder.verticalSize < _currentBorder.verticalSize)
|
|
|
|
{
|
|
|
|
_currentBorder.verticalSize = imageBorder.verticalSize;
|
|
|
|
borderChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imageBorder.horizontalSize < _currentBorder.horizontalSize)
|
|
|
|
{
|
|
|
|
_currentBorder.horizontalSize = imageBorder.horizontalSize;
|
|
|
|
borderChanged = true;
|
|
|
|
}
|
2013-08-21 22:44:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return borderChanged;
|
|
|
|
}
|