mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
faster detection less false positive
Former-commit-id: 501de9bca4c20600fe1e6250e82143f0b0d6ade3
This commit is contained in:
parent
ac86a779b0
commit
4bc11548b4
@ -62,15 +62,13 @@ namespace hyperion
|
|||||||
BlackBorder process(const Image<Pixel_T> & image)
|
BlackBorder process(const Image<Pixel_T> & image)
|
||||||
{
|
{
|
||||||
|
|
||||||
// only test the topleft third of the image
|
// test center and 1/3, 2/3 of width/heigth
|
||||||
int width = image.width() / 3;
|
int width = image.width() / 3;
|
||||||
int height = image.height() / 3;
|
int height = image.height() / 3;
|
||||||
int width2 = width * 2;
|
int width2 = width * 2;
|
||||||
int height2 = height * 2;
|
int height2 = height * 2;
|
||||||
int xCenter = image.width() / 2;
|
int xCenter = image.width() / 2;
|
||||||
int yCenter = image.height() / 2;
|
int yCenter = image.height() / 2;
|
||||||
// int maxSize = std::max(width, height);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int firstNonBlackXPixelIndex = -1;
|
int firstNonBlackXPixelIndex = -1;
|
||||||
@ -102,55 +100,6 @@ namespace hyperion
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
// only test the topleft third of the image
|
|
||||||
int width = image.width() /3;
|
|
||||||
int height = image.height() / 3;
|
|
||||||
int maxSize = std::max(width, height);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int firstNonBlackXPixelIndex = -1;
|
|
||||||
int firstNonBlackYPixelIndex = -1;
|
|
||||||
|
|
||||||
// find some pixel of the image
|
|
||||||
for (int i = 0; i < maxSize; ++i)
|
|
||||||
{
|
|
||||||
int x = std::min(i, width);
|
|
||||||
int y = std::min(i, height);
|
|
||||||
|
|
||||||
const Pixel_T & color = image(x, y);
|
|
||||||
if (!isBlack(color))
|
|
||||||
{
|
|
||||||
firstNonBlackXPixelIndex = x;
|
|
||||||
firstNonBlackYPixelIndex = y;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// expand image to the left
|
|
||||||
for(; firstNonBlackXPixelIndex > 0; --firstNonBlackXPixelIndex)
|
|
||||||
{
|
|
||||||
const Pixel_T & color = image(firstNonBlackXPixelIndex-1, firstNonBlackYPixelIndex);
|
|
||||||
if (isBlack(color))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// expand image to the top
|
|
||||||
for(; firstNonBlackYPixelIndex > 0; --firstNonBlackYPixelIndex)
|
|
||||||
{
|
|
||||||
const Pixel_T & color = image(firstNonBlackXPixelIndex, firstNonBlackYPixelIndex-1);
|
|
||||||
if (isBlack(color))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Construct result
|
// Construct result
|
||||||
BlackBorder detectedBorder;
|
BlackBorder detectedBorder;
|
||||||
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
|
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
|
||||||
|
@ -73,8 +73,6 @@ namespace hyperion
|
|||||||
/// @return True if the current border changed else false
|
/// @return True if the current border changed else false
|
||||||
///
|
///
|
||||||
bool updateBorder(const BlackBorder & newDetectedBorder);
|
bool updateBorder(const BlackBorder & newDetectedBorder);
|
||||||
bool updateBorder1(const BlackBorder & newDetectedBorder);
|
|
||||||
bool updateBorder2(const BlackBorder & newDetectedBorder);
|
|
||||||
|
|
||||||
/// The number of unknown-borders detected before it becomes the current border
|
/// The number of unknown-borders detected before it becomes the current border
|
||||||
const unsigned _unknownSwitchCnt;
|
const unsigned _unknownSwitchCnt;
|
||||||
|
@ -51,8 +51,7 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
|||||||
if (newDetectedBorder.unknown)
|
if (newDetectedBorder.unknown)
|
||||||
{
|
{
|
||||||
// apply the unknown border if we consistently can't determine a border
|
// apply the unknown border if we consistently can't determine a border
|
||||||
// if (_consistentCnt == _unknownSwitchCnt)
|
if (_consistentCnt == _unknownSwitchCnt)
|
||||||
if (_consistentCnt >= _unknownSwitchCnt)
|
|
||||||
{
|
{
|
||||||
_currentBorder = newDetectedBorder;
|
_currentBorder = newDetectedBorder;
|
||||||
borderChanged = true;
|
borderChanged = true;
|
||||||
@ -61,8 +60,7 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// apply the detected border if it has been detected consistently
|
// apply the detected border if it has been detected consistently
|
||||||
// if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt)
|
if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt)
|
||||||
if (_currentBorder.unknown || _consistentCnt >= _borderSwitchCnt)
|
|
||||||
{
|
{
|
||||||
_currentBorder = newDetectedBorder;
|
_currentBorder = newDetectedBorder;
|
||||||
borderChanged = true;
|
borderChanged = true;
|
||||||
@ -70,17 +68,16 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 );
|
bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 );
|
||||||
//more then A consistent seems like a new size not only a short flicker
|
//more then 10 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
|
//more then 30 inconsistent seems like the image is changing a lot and we need to set smaller border
|
||||||
// apply smaller borders immediately
|
|
||||||
// if (newDetectedBorder.verticalSize < _currentBorder.verticalSize)
|
// apply smaller borders (almost) immediately -> avoid switching for "abnormal" frames
|
||||||
if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (stable) )// almost immediatly - avoid switching for "abnormal" frames
|
if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (stable) )
|
||||||
{
|
{
|
||||||
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
|
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
|
||||||
borderChanged = true;
|
borderChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize)
|
|
||||||
if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (stable) )
|
if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (stable) )
|
||||||
{
|
{
|
||||||
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
|
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user