Merge pull request #448 from wisc17/blackborder_alternative

Blackborder Improved

Former-commit-id: 762bb519ebefd6755362178fdc5b9d5ed3508c3b
This commit is contained in:
tvdzwan 2016-01-13 22:43:30 +01:00
commit 424c00e767
3 changed files with 40 additions and 35 deletions

View File

@ -61,49 +61,45 @@ namespace hyperion
template <typename Pixel_T>
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 height = image.height() / 3;
int maxSize = std::max(width, height);
int width2 = width * 2;
int height2 = height * 2;
int xCenter = image.width() / 2;
int yCenter = image.height() / 2;
int firstNonBlackXPixelIndex = -1;
int firstNonBlackYPixelIndex = -1;
// find some pixel of the image
for (int i = 0; i < maxSize; ++i)
// find first X pixel of the image
for (int x = 0; x < width; ++x)
{
int x = std::min(i, width);
int y = std::min(i, height);
const Pixel_T & color = image(x, y);
if (!isBlack(color))
const Pixel_T & color1 = image(x, yCenter);
const Pixel_T & color2 = image(x, height);
const Pixel_T & color3 = image(x, height2);
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
{
firstNonBlackXPixelIndex = x;
break;
}
}
// find first Y pixel of the image
for (int y = 0; y < height; ++y)
{
const Pixel_T & color1 = image(xCenter, y);
const Pixel_T & color2 = image(width, y);
const Pixel_T & color3 = image(width2, y);
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
{
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
BlackBorder detectedBorder;
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;

View File

@ -94,5 +94,7 @@ namespace hyperion
/// The number of frame the previous detected border matched the incomming border
unsigned _consistentCnt;
/// The number of frame the previous detected border NOT matched the incomming border
unsigned _inconsistentCnt;
};
} // end namespace hyperion

View File

@ -14,7 +14,8 @@ BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt,
_detector(blackborderThreshold),
_currentBorder({true, -1, -1}),
_previousDetectedBorder({true, -1, -1}),
_consistentCnt(0)
_consistentCnt(0),
_inconsistentCnt(0)
{
// empty
}
@ -30,11 +31,13 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
if (newDetectedBorder == _previousDetectedBorder)
{
++_consistentCnt;
_inconsistentCnt = 0;
}
else
{
_previousDetectedBorder = newDetectedBorder;
_consistentCnt = 0;
++_inconsistentCnt;
}
// check if there is a change
@ -64,14 +67,18 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
}
else
{
// apply smaller borders immediately
if (newDetectedBorder.verticalSize < _currentBorder.verticalSize)
bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 );
//more then 10 consistent seems like a new size not only a short flicker
//more then 30 inconsistent seems like the image is changing a lot and we need to set smaller border
// apply smaller borders (almost) immediately -> avoid switching for "abnormal" frames
if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (stable) )
{
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
borderChanged = true;
}
if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize)
if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (stable) )
{
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
borderChanged = true;