From a7110ec64cc72f6bb5e439bc7809c782834cab68 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 20 Jan 2014 20:46:38 +0100 Subject: [PATCH] Configurable blackborder threshold added Former-commit-id: 95b77dee2869b41bf556e0e374bea3c5e4534e61 --- config/hyperion.config.json | 12 ++++--- config/hyperion_x86.config.json | 44 ++++++++++++++++++++--- deploy/hyperion.tar.gz.REMOVED.git-id | 2 +- include/hyperion/BlackBorderDetector.h | 9 +++-- include/hyperion/BlackBorderProcessor.h | 4 ++- include/hyperion/ImageProcessor.h | 20 ++++++----- include/hyperion/ImageProcessorFactory.h | 7 +++- libsrc/hyperion/BlackBorderDetector.cpp | 3 +- libsrc/hyperion/BlackBorderProcessor.cpp | 8 ++--- libsrc/hyperion/Hyperion.cpp | 5 ++- libsrc/hyperion/ImageProcessor.cpp | 22 ++++++------ libsrc/hyperion/ImageProcessorFactory.cpp | 16 +++++++-- libsrc/hyperion/hyperion.schema.json | 6 ++++ test/TestBlackBorderDetector.cpp | 10 +++--- test/TestBlackBorderProcessor.cpp | 2 +- 15 files changed, 121 insertions(+), 49 deletions(-) diff --git a/config/hyperion.config.json b/config/hyperion.config.json index 648f970d..fa08d80d 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -56,21 +56,21 @@ "red" : { "threshold" : 0.0000, - "gamma" : 2.0000, + "gamma" : 1.0000, "blacklevel" : 0.0000, "whitelevel" : 1.0000 }, "green" : { "threshold" : 0.0000, - "gamma" : 2.0000, + "gamma" : 1.0000, "blacklevel" : 0.0000, "whitelevel" : 1.0000 }, "blue" : { "threshold" : 0.0000, - "gamma" : 2.0000, + "gamma" : 1.0000, "blacklevel" : 0.0000, "whitelevel" : 1.0000 } @@ -348,10 +348,12 @@ ], /// The black border configuration, contains the following items: - /// * enable : true if the detector should be activated + /// * enable : true if the detector should be activated + /// * threshold : Value below which a pixel is regarded as black (value between 0.0 and 1.0) "blackborderdetector" : { - "enable" : true + "enable" : true, + "threshold" : 0.01 }, /// The configuration of the effect engine, contains the following items: diff --git a/config/hyperion_x86.config.json b/config/hyperion_x86.config.json index 89376b20..071713aa 100644 --- a/config/hyperion_x86.config.json +++ b/config/hyperion_x86.config.json @@ -13,9 +13,9 @@ "device" : { "name" : "MyPi", - "type" : "test", - "output" : "~/hyperion.test.out", - "rate" : 250000, + "type" : "adalight", + "output" : "/dev/ttyUSB0", + "rate" : 115200, "colorOrder" : "rgb" }, @@ -348,10 +348,12 @@ ], /// The black border configuration, contains the following items: - /// * enable : true if the detector should be activated + /// * enable : true if the detector should be activated + /// * threshold : Value below which a pixel is regarded as black (value between 0.0 and 1.0) "blackborderdetector" : { - "enable" : true + "enable" : true, + "threshold" : 0.01 }, /// The configuration of the effect engine, contains the following items: @@ -371,6 +373,38 @@ "duration_ms" : 3000 }, + /// The configuration for the frame-grabber, contains the following items: + /// * width : The width of the grabbed frames [pixels] + /// * height : The height of the grabbed frames [pixels] + /// * frequency_Hz : The frequency of the frame grab [Hz] +// "framegrabber" : +// { +// "width" : 64, +// "height" : 64, +// "frequency_Hz" : 10.0 +// }, + + /// The configuration of the XBMC connection used to enable and disable the frame-grabber. Contains the following fields: + /// * xbmcAddress : The IP address of the XBMC-host + /// * xbmcTcpPort : The TCP-port of the XBMC-server + /// * grabVideo : Flag indicating that the frame-grabber is on(true) during video playback + /// * grabPictures : Flag indicating that the frame-grabber is on(true) during picture show + /// * grabAudio : Flag indicating that the frame-grabber is on(true) during audio playback + /// * grabMenu : Flag indicating that the frame-grabber is on(true) in the XBMC menu + /// * grabScreensaver : Flag indicating that the frame-grabber is on(true) when XBMC is on screensaver + /// * enable3DDetection : Flag indicating that the frame-grabber should switch to a 3D compatible modus if a 3D video is playing +// "xbmcVideoChecker" : +// { +// "xbmcAddress" : "127.0.0.1", +// "xbmcTcpPort" : 9090, +// "grabVideo" : true, +// "grabPictures" : true, +// "grabAudio" : true, +// "grabMenu" : false, +// "grabScreensaver" : true, +// "enable3DDetection" : true +// }, + /// The configuration of the Json server which enables the json remote interface /// * port : Port at which the json server is started "jsonServer" : diff --git a/deploy/hyperion.tar.gz.REMOVED.git-id b/deploy/hyperion.tar.gz.REMOVED.git-id index d1df5729..e41e5906 100644 --- a/deploy/hyperion.tar.gz.REMOVED.git-id +++ b/deploy/hyperion.tar.gz.REMOVED.git-id @@ -1 +1 @@ -96b8f6c7e0241930c944a7358af473dabecf1dae \ No newline at end of file +2ad39031528c40c14e352cbc84784f48564cc59b \ No newline at end of file diff --git a/include/hyperion/BlackBorderDetector.h b/include/hyperion/BlackBorderDetector.h index c3393bdb..ce0bf25d 100644 --- a/include/hyperion/BlackBorderDetector.h +++ b/include/hyperion/BlackBorderDetector.h @@ -48,8 +48,9 @@ namespace hyperion public: /// /// Constructs a black-border detector + /// @param[in] blackborderThreshold The threshold which the blackborder detector should use /// - BlackBorderDetector(); + BlackBorderDetector(uint8_t blackborderThreshold); /// /// Performs the actual black-border detection on the given image @@ -125,7 +126,11 @@ namespace hyperion inline bool isBlack(const Pixel_T & color) { // Return the simple compare of the color against black - return color.red < 3 && color.green < 3 && color.green < 3; + return color.red < _blackborderThreshold && color.green < _blackborderThreshold && color.green < _blackborderThreshold; } + + private: + /// Threshold for the blackborder detector [0 .. 255] + const uint8_t _blackborderThreshold; }; } // end namespace hyperion diff --git a/include/hyperion/BlackBorderProcessor.h b/include/hyperion/BlackBorderProcessor.h index 3ec2fe42..4d0c4fca 100644 --- a/include/hyperion/BlackBorderProcessor.h +++ b/include/hyperion/BlackBorderProcessor.h @@ -21,11 +21,13 @@ namespace hyperion /// horizontal border becomes the current border /// @param blurRemoveCnt The size to add to a horizontal or vertical border (because the /// outer pixels is blurred (black and color combined due to image scaling)) + /// @param[in] blackborderThreshold The threshold which the blackborder detector should use /// BlackBorderProcessor( const unsigned unknownFrameCnt, const unsigned borderFrameCnt, - const unsigned blurRemoveCnt); + const unsigned blurRemoveCnt, + uint8_t blackborderThreshold); /// /// Return the current (detected) border diff --git a/include/hyperion/ImageProcessor.h b/include/hyperion/ImageProcessor.h index 6c4b4739..990b6593 100644 --- a/include/hyperion/ImageProcessor.h +++ b/include/hyperion/ImageProcessor.h @@ -53,7 +53,7 @@ public: verifyBorder(image); // Create a result vector and call the 'in place' functionl - std::vector colors = mImageToLeds->getMeanLedColor(image); + std::vector colors = _imageToLeds->getMeanLedColor(image); // return the computed colors return colors; @@ -75,7 +75,7 @@ public: verifyBorder(image); // Determine the mean-colors of each led (using the existing mapping) - mImageToLeds->getMeanLedColor(image, ledColors); + _imageToLeds->getMeanLedColor(image, ledColors); } /// @@ -98,8 +98,10 @@ private: /// given led-string specification /// /// @param[in] ledString The led-string specification + /// @param[in] enableBlackBorderDetector Flag indicating if the blacborder detector should be enabled + /// @param[in] blackborderThreshold The threshold which the blackborder detector should use /// - ImageProcessor(const LedString &ledString, bool enableBlackBorderDetector); + ImageProcessor(const LedString &ledString, bool enableBlackBorderDetector, uint8_t blackborderThreshold); /// /// Performs black-border detection (if enabled) on the given image @@ -116,17 +118,17 @@ private: const hyperion::BlackBorder border = _borderProcessor->getCurrentBorder(); // Clean up the old mapping - delete mImageToLeds; + delete _imageToLeds; if (border.unknown) { // Construct a new buffer and mapping - mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds()); + _imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, _ledString.leds()); } else { // Construct a new buffer and mapping - mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds()); + _imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, _ledString.leds()); } std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl; @@ -135,14 +137,14 @@ private: private: /// The Led-string specification - const LedString mLedString; + const LedString _ledString; /// Flag the enables(true)/disabled(false) blackborder detector - bool _enableBlackBorderRemoval; + const bool _enableBlackBorderRemoval; /// The processor for black border detection hyperion::BlackBorderProcessor * _borderProcessor; /// The mapping of image-pixels to leds - hyperion::ImageToLedsMap* mImageToLeds; + hyperion::ImageToLedsMap* _imageToLeds; }; diff --git a/include/hyperion/ImageProcessorFactory.h b/include/hyperion/ImageProcessorFactory.h index a377bafa..cde64440 100644 --- a/include/hyperion/ImageProcessorFactory.h +++ b/include/hyperion/ImageProcessorFactory.h @@ -30,8 +30,10 @@ public: /// Initialises this factory with the given led-configuration /// /// @param[in] ledString The led configuration + /// @param[in] enableBlackBorderDetector Flag indicating if the blacborder detector should be enabled + /// @param[in] blackborderThreshold The threshold which the blackborder detector should use /// - void init(const LedString& ledString, bool enableBlackBorderDetector); + void init(const LedString& ledString, bool enableBlackBorderDetector, double blackborderThreshold); /// /// Creates a new ImageProcessor. The onwership of the processor is transferred to the caller. @@ -46,4 +48,7 @@ private: /// Flag indicating if the black border detector should be used bool _enableBlackBorderDetector; + + /// Threshold for the blackborder detector [0 .. 255] + uint8_t _blackborderThreshold; }; diff --git a/libsrc/hyperion/BlackBorderDetector.cpp b/libsrc/hyperion/BlackBorderDetector.cpp index e86ba9ed..ed97bebe 100644 --- a/libsrc/hyperion/BlackBorderDetector.cpp +++ b/libsrc/hyperion/BlackBorderDetector.cpp @@ -4,7 +4,8 @@ using namespace hyperion; -BlackBorderDetector::BlackBorderDetector() +BlackBorderDetector::BlackBorderDetector(uint8_t blackborderThreshold) : + _blackborderThreshold(blackborderThreshold) { // empty } diff --git a/libsrc/hyperion/BlackBorderProcessor.cpp b/libsrc/hyperion/BlackBorderProcessor.cpp index 87ada03f..efc97724 100644 --- a/libsrc/hyperion/BlackBorderProcessor.cpp +++ b/libsrc/hyperion/BlackBorderProcessor.cpp @@ -4,14 +4,14 @@ using namespace hyperion; -BlackBorderProcessor::BlackBorderProcessor( - const unsigned unknownFrameCnt, +BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt, const unsigned borderFrameCnt, - const unsigned blurRemoveCnt) : + const unsigned blurRemoveCnt, + uint8_t blackborderThreshold) : _unknownSwitchCnt(unknownFrameCnt), _borderSwitchCnt(borderFrameCnt), _blurRemoveCnt(blurRemoveCnt), - _detector(), + _detector(blackborderThreshold), _currentBorder({true, -1, -1}), _previousDetectedBorder({true, -1, -1}), _consistentCnt(0) diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index bfe14a9d..a81e4f3c 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -270,7 +270,10 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) : throw std::runtime_error("Color transformation incorrectly set"); } // initialize the image processor factory - ImageProcessorFactory::getInstance().init(_ledString, jsonConfig["blackborderdetector"].get("enable", true).asBool()); + ImageProcessorFactory::getInstance().init( + _ledString, + jsonConfig["blackborderdetector"].get("enable", true).asBool(), + jsonConfig["blackborderdetector"].get("threshold", 0.01).asDouble()); // initialize the color smoothing filter _device = createColorSmoothing(jsonConfig["color"]["smoothing"], _device); diff --git a/libsrc/hyperion/ImageProcessor.cpp b/libsrc/hyperion/ImageProcessor.cpp index ec10f52c..cd39dd1e 100644 --- a/libsrc/hyperion/ImageProcessor.cpp +++ b/libsrc/hyperion/ImageProcessor.cpp @@ -6,46 +6,46 @@ using namespace hyperion; -ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector) : - mLedString(ledString), +ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector, uint8_t blackborderThreshold) : + _ledString(ledString), _enableBlackBorderRemoval(enableBlackBorderDetector), - _borderProcessor(new BlackBorderProcessor(600, 50, 1)), - mImageToLeds(nullptr) + _borderProcessor(new BlackBorderProcessor(600, 50, 1, blackborderThreshold)), + _imageToLeds(nullptr) { // empty } ImageProcessor::~ImageProcessor() { - delete mImageToLeds; + delete _imageToLeds; delete _borderProcessor; } unsigned ImageProcessor::getLedCount() const { - return mLedString.leds().size(); + return _ledString.leds().size(); } void ImageProcessor::setSize(const unsigned width, const unsigned height) { // Check if the existing buffer-image is already the correct dimensions - if (mImageToLeds && mImageToLeds->width() == width && mImageToLeds->height() == height) + if (_imageToLeds && _imageToLeds->width() == width && _imageToLeds->height() == height) { return; } // Clean up the old buffer and mapping - delete mImageToLeds; + delete _imageToLeds; // Construct a new buffer and mapping - mImageToLeds = new ImageToLedsMap(width, height, 0, 0, mLedString.leds()); + _imageToLeds = new ImageToLedsMap(width, height, 0, 0, _ledString.leds()); } bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &hscanEnd, double &vscanBegin, double &vscanEnd) const { - if (led < mLedString.leds().size()) + if (led < _ledString.leds().size()) { - const Led & l = mLedString.leds()[led]; + const Led & l = _ledString.leds()[led]; hscanBegin = l.minX_frac; hscanEnd = l.maxX_frac; vscanBegin = l.minY_frac; diff --git a/libsrc/hyperion/ImageProcessorFactory.cpp b/libsrc/hyperion/ImageProcessorFactory.cpp index a5a7fb06..70987845 100644 --- a/libsrc/hyperion/ImageProcessorFactory.cpp +++ b/libsrc/hyperion/ImageProcessorFactory.cpp @@ -10,13 +10,25 @@ ImageProcessorFactory& ImageProcessorFactory::getInstance() return instance; } -void ImageProcessorFactory::init(const LedString& ledString, bool enableBlackBorderDetector) +void ImageProcessorFactory::init(const LedString& ledString, bool enableBlackBorderDetector, double blackborderThreshold) { _ledString = ledString; _enableBlackBorderDetector = enableBlackBorderDetector; + + int threshold = int(std::ceil(blackborderThreshold * 255)); + if (threshold < 0) + threshold = 0; + else if (threshold > 255) + threshold = 255; + _blackborderThreshold = uint8_t(threshold); + + if (_enableBlackBorderDetector) + { + std::cout << "Black border threshold set to " << blackborderThreshold << " (" << int(_blackborderThreshold) << ")" << std::endl; + } } ImageProcessor* ImageProcessorFactory::newImageProcessor() const { - return new ImageProcessor(_ledString, _enableBlackBorderDetector); + return new ImageProcessor(_ledString, _enableBlackBorderDetector, _blackborderThreshold); } diff --git a/libsrc/hyperion/hyperion.schema.json b/libsrc/hyperion/hyperion.schema.json index bd059aa4..38192312 100644 --- a/libsrc/hyperion/hyperion.schema.json +++ b/libsrc/hyperion/hyperion.schema.json @@ -223,6 +223,12 @@ "enable" : { "type" : "boolean", "required" : true + }, + "threshold" : { + "type" : "number", + "required" : false, + "minimum" : 0.0, + "maximum" : 1.0 } }, "additionalProperties" : false diff --git a/test/TestBlackBorderDetector.cpp b/test/TestBlackBorderDetector.cpp index 8a92cba9..1d91079f 100644 --- a/test/TestBlackBorderDetector.cpp +++ b/test/TestBlackBorderDetector.cpp @@ -41,7 +41,7 @@ int TC_NO_BORDER() { int result = 0; - BlackBorderDetector detector; + BlackBorderDetector detector(3); { Image image = createImage(64, 64, 0, 0); @@ -60,7 +60,7 @@ int TC_TOP_BORDER() { int result = 0; - BlackBorderDetector detector; + BlackBorderDetector detector(3); { Image image = createImage(64, 64, 12, 0); @@ -79,7 +79,7 @@ int TC_LEFT_BORDER() { int result = 0; - BlackBorderDetector detector; + BlackBorderDetector detector(3); { Image image = createImage(64, 64, 0, 12); @@ -98,7 +98,7 @@ int TC_DUAL_BORDER() { int result = 0; - BlackBorderDetector detector; + BlackBorderDetector detector(3); { Image image = createImage(64, 64, 12, 12); @@ -116,7 +116,7 @@ int TC_UNKNOWN_BORDER() { int result = 0; - BlackBorderDetector detector; + BlackBorderDetector detector(3); { Image image = createImage(64, 64, 30, 30); diff --git a/test/TestBlackBorderProcessor.cpp b/test/TestBlackBorderProcessor.cpp index f5317f05..e0eef0d2 100644 --- a/test/TestBlackBorderProcessor.cpp +++ b/test/TestBlackBorderProcessor.cpp @@ -48,7 +48,7 @@ int main() unsigned borderCnt = 50; unsigned blurCnt = 0; - BlackBorderProcessor processor(unknownCnt, borderCnt, blurCnt); + BlackBorderProcessor processor(unknownCnt, borderCnt, blurCnt, 3); // Start with 'no border' detection Image noBorderImage = createImage(64, 64, 0, 0);