diff --git a/libsrc/hyperion/BlackBorderDetector.cpp b/libsrc/hyperion/BlackBorderDetector.cpp index 6422bb42..afc3041e 100644 --- a/libsrc/hyperion/BlackBorderDetector.cpp +++ b/libsrc/hyperion/BlackBorderDetector.cpp @@ -2,6 +2,8 @@ // Local-Hyperion includes #include "BlackBorderDetector.h" +using namespace hyperion; + BlackBorderDetector::BlackBorderDetector() { // empty diff --git a/libsrc/hyperion/BlackBorderDetector.h b/libsrc/hyperion/BlackBorderDetector.h index ebd4bccd..118ae56e 100644 --- a/libsrc/hyperion/BlackBorderDetector.h +++ b/libsrc/hyperion/BlackBorderDetector.h @@ -4,64 +4,67 @@ // Utils includes #include -/// -/// 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 diff --git a/libsrc/hyperion/BlackBorderProcessor.cpp b/libsrc/hyperion/BlackBorderProcessor.cpp index 2ad17f14..c397fe87 100644 --- a/libsrc/hyperion/BlackBorderProcessor.cpp +++ b/libsrc/hyperion/BlackBorderProcessor.cpp @@ -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; } diff --git a/libsrc/hyperion/BlackBorderProcessor.h b/libsrc/hyperion/BlackBorderProcessor.h index 7ff2542b..3f0b2c20 100644 --- a/libsrc/hyperion/BlackBorderProcessor.h +++ b/libsrc/hyperion/BlackBorderProcessor.h @@ -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 diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 8add1fd4..46ff3048 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -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 diff --git a/test/TestBlackBorderDetector.cpp b/test/TestBlackBorderDetector.cpp index 4d576e5c..ba14b377 100644 --- a/test/TestBlackBorderDetector.cpp +++ b/test/TestBlackBorderDetector.cpp @@ -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::max() + 1)); diff --git a/test/TestBlackBorderProcessor.cpp b/test/TestBlackBorderProcessor.cpp index cfe88b6b..58da95fb 100644 --- a/test/TestBlackBorderProcessor.cpp +++ b/test/TestBlackBorderProcessor.cpp @@ -5,8 +5,11 @@ // Utils includes #include +// Local-Hyperion includes #include "hyperion/BlackBorderProcessor.h" +using namespace hyperion; + RgbColor randomColor() { const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits::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);