From 633985930b8ba55e001656d06f81b0034613e37c Mon Sep 17 00:00:00 2001 From: wisc Date: Mon, 4 Jan 2016 00:20:47 +0100 Subject: [PATCH] 3line detection Former-commit-id: a63c03bc276ef218981213fbb9743a3d6d12d8b6 --- include/blackborder/BlackBorderDetector.h | 14 ++++++++++---- libsrc/blackborder/BlackBorderProcessor.cpp | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/blackborder/BlackBorderDetector.h b/include/blackborder/BlackBorderDetector.h index 3f190c5c..cd955b8a 100644 --- a/include/blackborder/BlackBorderDetector.h +++ b/include/blackborder/BlackBorderDetector.h @@ -65,6 +65,8 @@ namespace hyperion // only test the topleft third of the image int width = image.width() / 3; int height = image.height() / 3; + int width2 = width * 2; + int height2 = height * 2; int xCenter = image.width() / 2; int yCenter = image.height() / 2; // int maxSize = std::max(width, height); @@ -77,8 +79,10 @@ namespace hyperion // find first X pixel of the image for (int x = 0; x < width; ++x) { - const Pixel_T & color = image(x, yCenter); - if (!isBlack(color)) + const Pixel_T & color1 = image(x, yCenter); + const Pixel_T & color2 = image(x, height); + const Pixel_T & color3 = image(x, height2); + if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3)) { firstNonBlackXPixelIndex = x; break; @@ -88,8 +92,10 @@ namespace hyperion // find first Y pixel of the image for (int y = 0; y < height; ++y) { - const Pixel_T & color = image(xCenter, y); - if (!isBlack(color)) + const Pixel_T & color1 = image(xCenter, y); + const Pixel_T & color2 = image(width, y); + const Pixel_T & color3 = image(width2, y); + if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3)) { firstNonBlackYPixelIndex = y; break; diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index ee78efb9..b9c21eea 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -1,4 +1,4 @@ - +//#include // Blackborder includes #include @@ -29,7 +29,10 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) // set the consistency counter if (newDetectedBorder == _previousDetectedBorder) { - ++_consistentCnt; + if (_consistentCnt < 100000) + { + ++_consistentCnt; + } } else { @@ -37,6 +40,8 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) _consistentCnt = 0; } +// std::cout << "new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " cur: " << _currentBorder.verticalSize << " " << _currentBorder.horizontalSize << " cc " << _consistentCnt << std::endl; + // check if there is a change if (_currentBorder == newDetectedBorder) { @@ -48,7 +53,8 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) if (newDetectedBorder.unknown) { // apply the unknown border if we consistently can't determine a border - if (_consistentCnt == _unknownSwitchCnt) +// if (_consistentCnt == _unknownSwitchCnt) + if (_consistentCnt >= _unknownSwitchCnt) { _currentBorder = newDetectedBorder; borderChanged = true; @@ -57,7 +63,8 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) else { // apply the detected border if it has been detected consistently - if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt) +// if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt) + if (_currentBorder.unknown || _consistentCnt >= _borderSwitchCnt) { _currentBorder = newDetectedBorder; borderChanged = true; @@ -65,13 +72,15 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) else { // apply smaller borders immediately - if (newDetectedBorder.verticalSize < _currentBorder.verticalSize) +// if (newDetectedBorder.verticalSize < _currentBorder.verticalSize) + if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (_consistentCnt >= 1) )// almost immediatly - avoid switching for "abnormal" frames { _currentBorder.verticalSize = newDetectedBorder.verticalSize; borderChanged = true; } - if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) +// if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) + if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (_consistentCnt >= 1) ) { _currentBorder.horizontalSize = newDetectedBorder.horizontalSize; borderChanged = true;