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> template <typename Pixel_T>
BlackBorder process(const Image<Pixel_T> & image) BlackBorder process(const Image<Pixel_T> & image)
{ {
// only test the topleft third of the image
int width = image.width() /3; // test center and 1/3, 2/3 of width/heigth
int width = image.width() / 3;
int height = image.height() / 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 firstNonBlackXPixelIndex = -1;
int firstNonBlackYPixelIndex = -1; int firstNonBlackYPixelIndex = -1;
// find some pixel of the image // find first X pixel of the image
for (int i = 0; i < maxSize; ++i) for (int x = 0; x < width; ++x)
{ {
int x = std::min(i, width); const Pixel_T & color1 = image(x, yCenter);
int y = std::min(i, height); const Pixel_T & color2 = image(x, height);
const Pixel_T & color3 = image(x, height2);
const Pixel_T & color = image(x, y); if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
if (!isBlack(color))
{ {
firstNonBlackXPixelIndex = x; 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; firstNonBlackYPixelIndex = y;
break; 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;

View File

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

View File

@ -14,7 +14,8 @@ BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt,
_detector(blackborderThreshold), _detector(blackborderThreshold),
_currentBorder({true, -1, -1}), _currentBorder({true, -1, -1}),
_previousDetectedBorder({true, -1, -1}), _previousDetectedBorder({true, -1, -1}),
_consistentCnt(0) _consistentCnt(0),
_inconsistentCnt(0)
{ {
// empty // empty
} }
@ -30,11 +31,13 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
if (newDetectedBorder == _previousDetectedBorder) if (newDetectedBorder == _previousDetectedBorder)
{ {
++_consistentCnt; ++_consistentCnt;
_inconsistentCnt = 0;
} }
else else
{ {
_previousDetectedBorder = newDetectedBorder; _previousDetectedBorder = newDetectedBorder;
_consistentCnt = 0; _consistentCnt = 0;
++_inconsistentCnt;
} }
// check if there is a change // check if there is a change
@ -64,14 +67,18 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
} }
else else
{ {
// apply smaller borders immediately bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 );
if (newDetectedBorder.verticalSize < _currentBorder.verticalSize) //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; _currentBorder.verticalSize = newDetectedBorder.verticalSize;
borderChanged = true; borderChanged = true;
} }
if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (stable) )
{ {
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize; _currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
borderChanged = true; borderChanged = true;