mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Updated the scan-algorithm to only use half of each border.
Added doxygen comments to the header file.
This commit is contained in:
parent
f8c8fa6c74
commit
f262a9eb11
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
BlackBorderDetector::BlackBorderDetector()
|
BlackBorderDetector::BlackBorderDetector()
|
||||||
{
|
{
|
||||||
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
||||||
@ -9,7 +10,8 @@ BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
|||||||
int firstNonBlackPixelTop = -1;
|
int firstNonBlackPixelTop = -1;
|
||||||
int firstNonBlackPixelLeft = -1;
|
int firstNonBlackPixelLeft = -1;
|
||||||
|
|
||||||
for (unsigned x=0; x<image.width(); ++x)
|
// Find the non-black pixel at the top-half border
|
||||||
|
for (unsigned x=0; x<image.width()/2; ++x)
|
||||||
{
|
{
|
||||||
const RgbColor& color = image(x, 0);
|
const RgbColor& color = image(x, 0);
|
||||||
if (!isBlack(color))
|
if (!isBlack(color))
|
||||||
@ -18,7 +20,8 @@ BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (unsigned y=0; y<image.height(); ++y)
|
// Find the non-black pixel at the left-half border
|
||||||
|
for (unsigned y=0; y<image.height()/2; ++y)
|
||||||
{
|
{
|
||||||
const RgbColor& color = image(0, y);
|
const RgbColor& color = image(0, y);
|
||||||
if (!isBlack(color))
|
if (!isBlack(color))
|
||||||
@ -28,6 +31,7 @@ BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Construct 'unknown' result
|
||||||
BlackBorder detectedBorder;
|
BlackBorder detectedBorder;
|
||||||
detectedBorder.type = BlackBorder::unknown;
|
detectedBorder.type = BlackBorder::unknown;
|
||||||
|
|
||||||
@ -45,27 +49,23 @@ BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
|||||||
}
|
}
|
||||||
else if (firstNonBlackPixelTop < 0)
|
else if (firstNonBlackPixelTop < 0)
|
||||||
{
|
{
|
||||||
if (firstNonBlackPixelLeft < 0 || firstNonBlackPixelLeft > (int)(image.height()/2) )
|
if (firstNonBlackPixelLeft < 0)
|
||||||
{
|
{
|
||||||
// We don't know
|
// We don't know
|
||||||
// B-B-B-B ... B-B-B-B
|
// B-B-B-B ...
|
||||||
// B +---- ... ----- ?
|
// B +---- ...
|
||||||
// B |
|
// B |
|
||||||
// B |
|
// B |
|
||||||
// :
|
// :
|
||||||
// B |
|
|
||||||
// B |
|
|
||||||
// B |
|
|
||||||
// B ?
|
|
||||||
|
|
||||||
detectedBorder.type = BlackBorder::unknown;
|
detectedBorder.type = BlackBorder::unknown;
|
||||||
detectedBorder.size = -1;
|
detectedBorder.size = -1;
|
||||||
}
|
}
|
||||||
else //(firstNonBlackPixelLeft > 0 && firstNonBlackPixelLeft < image.height()/2)
|
else //(firstNonBlackPixelLeft > 0)
|
||||||
{
|
{
|
||||||
// Border at top of screen
|
// Border at top of screen
|
||||||
// B-B-B-B ... B-B-B-B
|
// B-B-B-B ...
|
||||||
// B +---- ... ----- ?
|
// B +---- ...
|
||||||
// C |
|
// C |
|
||||||
// ? |
|
// ? |
|
||||||
// :
|
// :
|
||||||
@ -76,23 +76,19 @@ BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
|||||||
}
|
}
|
||||||
else // (firstNonBlackPixelTop > 0)
|
else // (firstNonBlackPixelTop > 0)
|
||||||
{
|
{
|
||||||
if (firstNonBlackPixelTop < int(image.width()/2) && firstNonBlackPixelLeft < 0)
|
if (firstNonBlackPixelLeft < 0)
|
||||||
{
|
{
|
||||||
// Border at left of screen
|
// Border at left of screen
|
||||||
// B-B-C-? ...
|
// B-B-C-? ...
|
||||||
// B +---- ... ----- ?
|
// B +---- ...
|
||||||
// B |
|
// B |
|
||||||
// B |
|
// B |
|
||||||
// :
|
// :
|
||||||
// B |
|
|
||||||
// B |
|
|
||||||
// B |
|
|
||||||
// B ?
|
|
||||||
|
|
||||||
detectedBorder.type = BlackBorder::vertical;
|
detectedBorder.type = BlackBorder::vertical;
|
||||||
detectedBorder.size = firstNonBlackPixelTop;
|
detectedBorder.size = firstNonBlackPixelTop;
|
||||||
}
|
}
|
||||||
else //(firstNonBlackPixelTop > int(mage.width()/2) || firstNonBlackPixelLeft > 0)
|
else //(firstNonBlackPixelLeft > 0)
|
||||||
{
|
{
|
||||||
// No black border
|
// No black border
|
||||||
// B-B-C-? ...
|
// B-B-C-? ...
|
||||||
|
@ -4,8 +4,14 @@
|
|||||||
// Utils includes
|
// Utils includes
|
||||||
#include <utils/RgbImage.h>
|
#include <utils/RgbImage.h>
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Result structure of the detected blackborder.
|
||||||
|
///
|
||||||
struct BlackBorder
|
struct BlackBorder
|
||||||
{
|
{
|
||||||
|
///
|
||||||
|
/// Enumeration of the possible types of detected borders
|
||||||
|
///
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
none,
|
none,
|
||||||
@ -14,25 +20,48 @@ struct BlackBorder
|
|||||||
unknown
|
unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The type of detected border
|
||||||
Type type;
|
Type type;
|
||||||
int size;
|
|
||||||
|
|
||||||
|
/// The size of detected border (negative if not applicable)
|
||||||
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The BlackBorderDetector performs detection of black-borders on a single image.
|
||||||
|
/// The detector will scan the border of the upper-left quadrant of an image. Based on detected
|
||||||
|
/// black pixels it will give an estimate of the black-border.
|
||||||
|
///
|
||||||
class BlackBorderDetector
|
class BlackBorderDetector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
///
|
||||||
|
/// Constructs a black-border detector
|
||||||
|
///
|
||||||
BlackBorderDetector();
|
BlackBorderDetector();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Performs the actual black-border detection on the given image
|
||||||
|
///
|
||||||
|
/// @param[in] image The image on which detection is performed
|
||||||
|
///
|
||||||
|
/// @return The detected (or not detected) black border info
|
||||||
|
///
|
||||||
BlackBorder process(const RgbImage& image);
|
BlackBorder process(const RgbImage& image);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Checks if a given color is considered black and therefor could be part of the border.
|
||||||
|
///
|
||||||
|
/// @param[in] color The color to check
|
||||||
|
///
|
||||||
|
/// @return True if the color is considered black else false
|
||||||
|
///
|
||||||
inline bool isBlack(const RgbColor& color)
|
inline bool isBlack(const RgbColor& color)
|
||||||
{
|
{
|
||||||
|
// Return the simple compare of the color against black
|
||||||
return RgbColor::BLACK == color;
|
return RgbColor::BLACK == color;
|
||||||
|
// TODO[TvdZ]: We could add a threshold to check that the color is close to black
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user