2016-01-10 14:41:47 +01:00
|
|
|
#include <iostream>
|
2014-01-26 14:23:08 +01:00
|
|
|
// Blackborder includes
|
|
|
|
#include <blackborder/BlackBorderProcessor.h>
|
2013-08-21 22:44:17 +02:00
|
|
|
|
2013-08-23 07:08:44 +02:00
|
|
|
using namespace hyperion;
|
|
|
|
|
2014-01-20 20:46:38 +01:00
|
|
|
BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt,
|
2013-08-23 07:08:44 +02:00
|
|
|
const unsigned borderFrameCnt,
|
2014-01-20 20:46:38 +01:00
|
|
|
const unsigned blurRemoveCnt,
|
|
|
|
uint8_t blackborderThreshold) :
|
2013-08-23 07:08:44 +02:00
|
|
|
_unknownSwitchCnt(unknownFrameCnt),
|
|
|
|
_borderSwitchCnt(borderFrameCnt),
|
|
|
|
_blurRemoveCnt(blurRemoveCnt),
|
2014-01-20 20:46:38 +01:00
|
|
|
_detector(blackborderThreshold),
|
2016-01-10 14:41:47 +01:00
|
|
|
_currentBorder1({true, -1, -1}),
|
2013-10-27 09:25:02 +01:00
|
|
|
_currentBorder({true, -1, -1}),
|
2016-01-10 14:41:47 +01:00
|
|
|
_previousDetectedBorder1({true, -1, -1}),
|
2013-10-27 09:25:02 +01:00
|
|
|
_previousDetectedBorder({true, -1, -1}),
|
2016-01-10 14:41:47 +01:00
|
|
|
_consistentCnt1(0),
|
|
|
|
_consistentCnt(0),
|
|
|
|
_inconsistentCnt1(0),
|
|
|
|
_inconsistentCnt(0)
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
// empty
|
2013-08-21 22:44:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
|
|
|
{
|
|
|
|
return _currentBorder;
|
|
|
|
}
|
|
|
|
|
2016-01-10 14:41:47 +01:00
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
2016-01-10 14:41:47 +01:00
|
|
|
{
|
|
|
|
bool result1 = updateBorder1(newDetectedBorder);
|
|
|
|
if (result1)
|
|
|
|
{
|
|
|
|
std::cout << "border change v1 " << _currentBorder1.horizontalSize << ":" << _currentBorder1.verticalSize << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result2 = updateBorder2(newDetectedBorder);
|
|
|
|
if (result2)
|
|
|
|
{
|
|
|
|
std::cout << "border change v2 " << _currentBorder.horizontalSize << ":" << _currentBorder.verticalSize << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BlackBorderProcessor::updateBorder1(const BlackBorder & newDetectedBorder)
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
2013-10-27 09:25:02 +01:00
|
|
|
// set the consistency counter
|
2016-01-10 14:41:47 +01:00
|
|
|
if (newDetectedBorder == _previousDetectedBorder1)
|
|
|
|
{
|
|
|
|
++_consistentCnt1;
|
|
|
|
}
|
|
|
|
else
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
2016-01-10 14:41:47 +01:00
|
|
|
_previousDetectedBorder1 = newDetectedBorder;
|
|
|
|
_consistentCnt1 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// std::cout << "cur: " << _currentBorder1.verticalSize << " " << _currentBorder1.horizontalSize << " new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " c:i " << _consistentCnt1 << ":" << _inconsistentCnt1 << std::endl;
|
|
|
|
|
|
|
|
// check if there is a change
|
|
|
|
if (_currentBorder1 == newDetectedBorder)
|
|
|
|
{
|
|
|
|
// No change required
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool borderChanged = false;
|
|
|
|
if (newDetectedBorder.unknown)
|
|
|
|
{
|
|
|
|
// apply the unknown border if we consistently can't determine a border
|
|
|
|
if (_consistentCnt1 == _unknownSwitchCnt)
|
2016-01-04 00:20:47 +01:00
|
|
|
{
|
2016-01-10 14:41:47 +01:00
|
|
|
_currentBorder1 = newDetectedBorder;
|
|
|
|
borderChanged = true;
|
2016-01-04 00:20:47 +01:00
|
|
|
}
|
2013-08-21 22:44:17 +02:00
|
|
|
}
|
|
|
|
else
|
2016-01-10 14:41:47 +01:00
|
|
|
{
|
|
|
|
// apply the detected border if it has been detected consistently
|
|
|
|
if (_currentBorder1.unknown || _consistentCnt1 == _borderSwitchCnt)
|
|
|
|
{
|
|
|
|
_currentBorder1 = newDetectedBorder;
|
|
|
|
borderChanged = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 );
|
|
|
|
// apply smaller borders immediately
|
|
|
|
if ((newDetectedBorder.verticalSize < _currentBorder1.verticalSize) && (stable))
|
|
|
|
{
|
|
|
|
_currentBorder1.verticalSize = newDetectedBorder.verticalSize;
|
|
|
|
borderChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((newDetectedBorder.horizontalSize < _currentBorder1.horizontalSize) && (stable))
|
|
|
|
{
|
|
|
|
_currentBorder1.horizontalSize = newDetectedBorder.horizontalSize;
|
|
|
|
borderChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return borderChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlackBorderProcessor::updateBorder2(const BlackBorder & newDetectedBorder)
|
|
|
|
{
|
|
|
|
// set the consistency counter
|
|
|
|
if (newDetectedBorder == _previousDetectedBorder)
|
|
|
|
{
|
|
|
|
++_consistentCnt;
|
|
|
|
_inconsistentCnt = 0;
|
|
|
|
}
|
|
|
|
else
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
_previousDetectedBorder = newDetectedBorder;
|
2013-08-23 18:24:10 +02:00
|
|
|
_consistentCnt = 0;
|
2016-01-10 14:41:47 +01:00
|
|
|
++_inconsistentCnt;
|
2013-08-23 18:24:10 +02:00
|
|
|
}
|
|
|
|
|
2016-01-10 14:41:47 +01:00
|
|
|
// std::cout << "cur: " << _currentBorder.verticalSize << " " << _currentBorder.horizontalSize << " new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " c:i " << _consistentCnt << ":" << _inconsistentCnt << std::endl;
|
2016-01-04 00:20:47 +01:00
|
|
|
|
2013-10-27 09:25:02 +01:00
|
|
|
// check if there is a change
|
2013-11-11 10:00:37 +01:00
|
|
|
if (_currentBorder == newDetectedBorder)
|
2013-08-23 18:24:10 +02:00
|
|
|
{
|
|
|
|
// No change required
|
|
|
|
return false;
|
2013-08-21 22:44:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool borderChanged = false;
|
2013-11-11 10:00:37 +01:00
|
|
|
if (newDetectedBorder.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
|
2016-01-04 00:20:47 +01:00
|
|
|
// if (_consistentCnt == _unknownSwitchCnt)
|
|
|
|
if (_consistentCnt >= _unknownSwitchCnt)
|
2013-08-23 18:24:10 +02:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
_currentBorder = newDetectedBorder;
|
2013-08-23 18:24:10 +02:00
|
|
|
borderChanged = true;
|
|
|
|
}
|
2013-10-27 09:25:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// apply the detected border if it has been detected consistently
|
2016-01-04 00:20:47 +01:00
|
|
|
// if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt)
|
|
|
|
if (_currentBorder.unknown || _consistentCnt >= _borderSwitchCnt)
|
2013-08-21 22:44:17 +02:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
_currentBorder = newDetectedBorder;
|
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
|
|
|
{
|
2016-01-10 14:41:47 +01:00
|
|
|
bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 );
|
|
|
|
//more then A consistent seems like a new size not only a short flicker
|
|
|
|
//more then B inconsistent seems like the image is changing a lot and we need to set smaller border
|
2013-10-27 09:25:02 +01:00
|
|
|
// apply smaller borders immediately
|
2016-01-04 00:20:47 +01:00
|
|
|
// if (newDetectedBorder.verticalSize < _currentBorder.verticalSize)
|
2016-01-10 14:41:47 +01:00
|
|
|
if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (stable) )// almost immediatly - avoid switching for "abnormal" frames
|
2013-10-27 09:25:02 +01:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
|
2013-10-27 09:25:02 +01:00
|
|
|
borderChanged = true;
|
|
|
|
}
|
|
|
|
|
2016-01-04 00:20:47 +01:00
|
|
|
// if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize)
|
2016-01-10 14:41:47 +01:00
|
|
|
if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (stable) )
|
2013-10-27 09:25:02 +01:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
|
2013-10-27 09:25:02 +01:00
|
|
|
borderChanged = true;
|
|
|
|
}
|
2013-08-21 22:44:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return borderChanged;
|
2016-01-10 14:41:47 +01:00
|
|
|
}
|