Merge pull request #483 from wisc17/blackborder

Blackborder Improved + (bugfix and enhancement)

Former-commit-id: 2d82dca6fafbe6eb019027c37abf679fd7066980
This commit is contained in:
tvdzwan
2016-02-08 14:54:48 +01:00
11 changed files with 213 additions and 60 deletions

View File

@@ -1,11 +1,26 @@
#include <iostream>
// BlackBorders includes
#include <blackborder/BlackBorderDetector.h>
using namespace hyperion;
BlackBorderDetector::BlackBorderDetector(uint8_t blackborderThreshold) :
_blackborderThreshold(blackborderThreshold)
BlackBorderDetector::BlackBorderDetector(double threshold) :
_blackborderThreshold(calculateThreshold(threshold))
{
// empty
}
uint8_t BlackBorderDetector::calculateThreshold(double threshold)
{
int rgbThreshold = int(std::ceil(threshold * 255));
if (rgbThreshold < 0)
rgbThreshold = 0;
else if (rgbThreshold > 255)
rgbThreshold = 255;
uint8_t blackborderThreshold = uint8_t(rgbThreshold);
std::cout << "Black border threshold set to " << threshold << " (" << int(blackborderThreshold) << ")" << std::endl;
return blackborderThreshold;
}

View File

@@ -1,23 +1,31 @@
//#include <iostream>
//*
#include <iostream>
/*
#include <iomanip>
using std::cout;
using std::endl;
using std::setw;
using std::left;
//*/
// Blackborder includes
#include <blackborder/BlackBorderProcessor.h>
using namespace hyperion;
BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt,
const unsigned borderFrameCnt,
const unsigned blurRemoveCnt,
uint8_t blackborderThreshold) :
_unknownSwitchCnt(unknownFrameCnt),
_borderSwitchCnt(borderFrameCnt),
_blurRemoveCnt(blurRemoveCnt),
_detector(blackborderThreshold),
BlackBorderProcessor::BlackBorderProcessor(const Json::Value &blackborderConfig) :
_unknownSwitchCnt(blackborderConfig.get("unknownFrameCnt", 600).asUInt()),
_borderSwitchCnt(blackborderConfig.get("borderFrameCnt", 50).asUInt()),
_maxInconsistentCnt(blackborderConfig.get("maxInconsistentCnt", 10).asUInt()),
_blurRemoveCnt(blackborderConfig.get("blurRemoveCnt", 1).asUInt()),
_detectionMode(blackborderConfig.get("mode", "default").asString()),
_detector(blackborderConfig.get("threshold", 0.01).asDouble()),
_currentBorder({true, -1, -1}),
_previousDetectedBorder({true, -1, -1}),
_consistentCnt(0),
_inconsistentCnt(10)
{
std::cout << "DETECTION MODE:" << _detectionMode << std::endl;
// empty
}
@@ -39,7 +47,7 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
// makes it look like the border detectionn is not working - since the new 3 line detection algorithm is more precise this became a problem specialy in dark scenes
// wisc
// std::cout << "cur: " << _currentBorder.verticalSize << " " << _currentBorder.horizontalSize << " new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " c:i " << _consistentCnt << ":" << _inconsistentCnt << std::endl;
// std::cout << "c: " << setw(2) << _currentBorder.verticalSize << " " << setw(2) << _currentBorder.horizontalSize << " p: " << setw(2) << _previousDetectedBorder.verticalSize << " " << setw(2) << _previousDetectedBorder.horizontalSize << " n: " << setw(2) << newDetectedBorder.verticalSize << " " << setw(2) << newDetectedBorder.horizontalSize << " c:i " << setw(2) << _consistentCnt << ":" << setw(2) << _inconsistentCnt << std::endl;
// set the consistency counter
if (newDetectedBorder == _previousDetectedBorder)
@@ -50,7 +58,7 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
else
{
++_inconsistentCnt;
if (_inconsistentCnt <= 10)// few inconsistent frames
if (_inconsistentCnt <= _maxInconsistentCnt)// only few inconsistent frames
{
//discard the newDetectedBorder -> keep the consistent count for previousDetectedBorder
return false;

View File

@@ -282,8 +282,8 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) :
// initialize the image processor factory
ImageProcessorFactory::getInstance().init(
_ledString,
jsonConfig["blackborderdetector"].get("enable", true).asBool(),
jsonConfig["blackborderdetector"].get("threshold", 0.01).asDouble());
jsonConfig["blackborderdetector"]
);
// initialize the color smoothing filter
_device = createColorSmoothing(jsonConfig["color"]["smoothing"], _device);

View File

@@ -8,10 +8,11 @@
using namespace hyperion;
ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector, uint8_t blackborderThreshold) :
//ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector, uint8_t blackborderThreshold) :
ImageProcessor::ImageProcessor(const LedString& ledString, const Json::Value & blackborderConfig) :
_ledString(ledString),
_enableBlackBorderRemoval(enableBlackBorderDetector),
_borderProcessor(new BlackBorderProcessor(600, 50, 1, blackborderThreshold)),
_enableBlackBorderRemoval(blackborderConfig.get("enable", true).asBool()),
_borderProcessor(new BlackBorderProcessor(blackborderConfig) ),
_imageToLeds(nullptr)
{
// empty

View File

@@ -13,25 +13,13 @@ ImageProcessorFactory& ImageProcessorFactory::getInstance()
return instance;
}
void ImageProcessorFactory::init(const LedString& ledString, bool enableBlackBorderDetector, double blackborderThreshold)
void ImageProcessorFactory::init(const LedString& ledString, const Json::Value & blackborderConfig)
{
_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;
}
_blackborderConfig = blackborderConfig;
}
ImageProcessor* ImageProcessorFactory::newImageProcessor() const
{
return new ImageProcessor(_ledString, _enableBlackBorderDetector, _blackborderThreshold);
return new ImageProcessor(_ledString, _blackborderConfig);
}