Added parameters to constructor of blackborder processor

Added blur line removal
Moved blackborder classes to hyperion namespace
This commit is contained in:
T. van der Zwan 2013-08-23 05:08:44 +00:00
parent c43b99359a
commit 046c68574e
7 changed files with 111 additions and 80 deletions

View File

@ -2,6 +2,8 @@
// Local-Hyperion includes
#include "BlackBorderDetector.h"
using namespace hyperion;
BlackBorderDetector::BlackBorderDetector()
{
// empty

View File

@ -4,64 +4,67 @@
// Utils includes
#include <utils/RgbImage.h>
///
/// Result structure of the detected blackborder.
///
struct BlackBorder
namespace hyperion
{
///
/// Enumeration of the possible types of detected borders
/// Result structure of the detected blackborder.
///
enum Type
struct BlackBorder
{
none,
horizontal,
vertical,
unknown
///
/// Enumeration of the possible types of detected borders
///
enum Type
{
none,
horizontal,
vertical,
unknown
};
/// The type of detected border
Type type;
/// The size of detected border (negative if not applicable)
int size;
};
/// The type of detected border
Type type;
/// 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
{
public:
///
/// Constructs a black-border detector
/// 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.
///
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);
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)
class BlackBorderDetector
{
// Return the simple compare of the color against black
return RgbColor::BLACK == color;
// TODO[TvdZ]: We could add a threshold to check that the color is close to black
}
};
public:
///
/// Constructs a black-border detector
///
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);
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)
{
// Return the simple compare of the color against black
return RgbColor::BLACK == color;
// TODO[TvdZ]: We could add a threshold to check that the color is close to black
}
};
} // end namespace hyperion

View File

@ -1,8 +1,16 @@
// Local-Hyperion includes
#include "BlackBorderProcessor.h"
BlackBorderProcessor::BlackBorderProcessor() :
_unknownSwitchCnt(600),
_borderSwitchCnt(50),
using namespace hyperion;
BlackBorderProcessor::BlackBorderProcessor(
const unsigned unknownFrameCnt,
const unsigned borderFrameCnt,
const unsigned blurRemoveCnt) :
_unknownSwitchCnt(unknownFrameCnt),
_borderSwitchCnt(borderFrameCnt),
_blurRemoveCnt(blurRemoveCnt),
_detector(),
_currentBorder({BlackBorder::unknown, 0}),
_lastDetectedBorder({BlackBorder::unknown, 0}),
@ -12,6 +20,11 @@ BlackBorderProcessor::BlackBorderProcessor() :
BlackBorder BlackBorderProcessor::getCurrentBorder() const
{
if (_currentBorder.size > 0)
{
return {_currentBorder.type, _currentBorder.size+int(_blurRemoveCnt)};
}
return _currentBorder;
}

View File

@ -4,27 +4,34 @@
// Local Hyperion includes
#include "BlackBorderDetector.h"
class BlackBorderProcessor
namespace hyperion
{
public:
BlackBorderProcessor();
class BlackBorderProcessor
{
public:
BlackBorderProcessor(
const unsigned unknownFrameCnt,
const unsigned borderFrameCnt,
const unsigned blurRemoveCnt);
BlackBorder getCurrentBorder() const;
BlackBorder getCurrentBorder() const;
bool process(const RgbImage& image);
bool process(const RgbImage& image);
private:
private:
const unsigned _unknownSwitchCnt;
const unsigned _unknownSwitchCnt;
const unsigned _borderSwitchCnt;
const unsigned _borderSwitchCnt;
BlackBorderDetector _detector;
unsigned _blurRemoveCnt;
BlackBorder _currentBorder;
BlackBorderDetector _detector;
BlackBorder _lastDetectedBorder;
BlackBorder _currentBorder;
unsigned _consistentCnt;
};
BlackBorder _lastDetectedBorder;
unsigned _consistentCnt;
};
} // end namespace hyperion

View File

@ -9,35 +9,35 @@ SET(Hyperion_QT_HEADERS
)
SET(Hyperion_HEADERS
${CURRENT_HEADER_DIR}/LedString.h
${CURRENT_HEADER_DIR}/LedDevice.h
${CURRENT_HEADER_DIR}/ImageProcessor.h
${CURRENT_HEADER_DIR}/ImageProcessorFactory.h
${CURRENT_HEADER_DIR}/LedDevice.h
${CURRENT_HEADER_DIR}/LedString.h
${CURRENT_HEADER_DIR}/PriorityMuxer.h
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
${CURRENT_SOURCE_DIR}/ImageToLedsMap.h
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.h
${CURRENT_SOURCE_DIR}/BlackBorderDetector.h
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.h
${CURRENT_SOURCE_DIR}/ColorTransform.h
${CURRENT_SOURCE_DIR}/HsvTransform.h
${CURRENT_SOURCE_DIR}/ImageToLedsMap.h
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
)
SET(Hyperion_SOURCES
${CURRENT_SOURCE_DIR}/LedString.cpp
${CURRENT_SOURCE_DIR}/Hyperion.cpp
${CURRENT_SOURCE_DIR}/ImageProcessor.cpp
${CURRENT_SOURCE_DIR}/ImageProcessorFactory.cpp
${CURRENT_SOURCE_DIR}/LedString.cpp
${CURRENT_SOURCE_DIR}/PriorityMuxer.cpp
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.cpp
${CURRENT_SOURCE_DIR}/BlackBorderDetector.cpp
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.cpp
${CURRENT_SOURCE_DIR}/ColorTransform.cpp
${CURRENT_SOURCE_DIR}/HsvTransform.cpp
${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
)
set(Hyperion_RESOURCES

View File

@ -5,6 +5,8 @@
// Hyperion includes
#include "hyperion/BlackBorderDetector.h"
using namespace hyperion;
RgbColor randomColor()
{
const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));

View File

@ -5,8 +5,11 @@
// Utils includes
#include <utils/RgbImage.h>
// Local-Hyperion includes
#include "hyperion/BlackBorderProcessor.h"
using namespace hyperion;
RgbColor randomColor()
{
const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
@ -40,8 +43,9 @@ int main()
{
unsigned unknownCnt = 600;
unsigned borderCnt = 50;
unsigned blurCnt = 0;
BlackBorderProcessor processor;
BlackBorderProcessor processor(unknownCnt, borderCnt, blurCnt);
// Start with 'no border' detection
RgbImage noBorderImage = createImage(64, 64, 0, 0);