Implement letterbox-only blackbar detection mode (#1063)

This commit is contained in:
Peter Eskdale
2020-11-01 18:20:27 +00:00
committed by GitHub
parent 958975975c
commit 85a55de28c
7 changed files with 52 additions and 4 deletions

View File

@@ -234,6 +234,49 @@ namespace hyperion
}
///
/// letterbox detection mode (5lines top-bottom only detection)
template <typename Pixel_T>
BlackBorder process_letterbox(const Image<Pixel_T> & image) const
{
// test center and 25%, 75% of width
// 25 and 75 will check both top and bottom
// center will only check top (minimise false detection of captions)
int width = image.width();
int height = image.height();
int width25percent = width / 4;
int height33percent = height / 3;
int width75percent = width25percent * 3;
int xCenter = width / 2;
int firstNonBlackYPixelIndex = -1;
height--; // remove 1 pixel to get end pixel index
// find first Y pixel of the image
for (int y = 0; y < height33percent; ++y)
{
if (!isBlack(image(xCenter, y))
|| !isBlack(image(width25percent, y))
|| !isBlack(image(width75percent, y))
|| !isBlack(image(width25percent, (height - y)))
|| !isBlack(image(width75percent, (height - y))))
{
firstNonBlackYPixelIndex = y;
break;
}
}
// Construct result
BlackBorder detectedBorder;
detectedBorder.unknown = firstNonBlackYPixelIndex == -1;
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
detectedBorder.verticalSize = 0;
return detectedBorder;
}
private:

View File

@@ -79,6 +79,8 @@ namespace hyperion
imageBorder = _detector->process_classic(image);
} else if (_detectionMode == "osd") {
imageBorder = _detector->process_osd(image);
} else if (_detectionMode == "letterbox") {
imageBorder = _detector->process_letterbox(image);
}
// add blur to the border
if (imageBorder.horizontalSize > 0)