Added wrapper for the blackborder detector to maintain state about detected borders.

Added simple unit test for blackborder processor.
This commit is contained in:
T. van der Zwan
2013-08-21 20:44:17 +00:00
parent 7c9ac7d151
commit 0ff4058ba4
6 changed files with 239 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
// Local-Hyperion includes
#include "BlackBorderDetector.h"
BlackBorderDetector::BlackBorderDetector()

View File

@@ -0,0 +1,57 @@
#include "BlackBorderProcessor.h"
BlackBorderProcessor::BlackBorderProcessor() :
_unknownSwitchCnt(600),
_borderSwitchCnt(50),
_detector(),
_currentBorder({BlackBorder::unknown, 0}),
_lastDetectedBorder({BlackBorder::unknown, 0}),
_consistentCnt(0)
{
}
BlackBorder BlackBorderProcessor::getCurrentBorder() const
{
return _currentBorder;
}
bool BlackBorderProcessor::process(const RgbImage& image)
{
const BlackBorder imageBorder = _detector.process(image);
if (imageBorder.type == _lastDetectedBorder.type && imageBorder.size == _lastDetectedBorder.size)
{
++_consistentCnt;
}
else
{
_lastDetectedBorder = imageBorder;
_consistentCnt = 0;
}
bool borderChanged = false;
switch (_lastDetectedBorder.type)
{
case BlackBorder::none:
borderChanged = (_currentBorder.type != BlackBorder::none);
_currentBorder = _lastDetectedBorder;
break;
case BlackBorder::horizontal:
case BlackBorder::vertical:
if (_consistentCnt == _borderSwitchCnt)
{
_currentBorder = _lastDetectedBorder;
borderChanged = true;
}
break;
case BlackBorder::unknown:
if (_consistentCnt == _unknownSwitchCnt)
{
_currentBorder = _lastDetectedBorder;
borderChanged = true;
}
break;
}
return borderChanged;
}

View File

@@ -0,0 +1,30 @@
#pragma once
// Local Hyperion includes
#include "BlackBorderDetector.h"
class BlackBorderProcessor
{
public:
BlackBorderProcessor();
BlackBorder getCurrentBorder() const;
bool process(const RgbImage& image);
private:
const unsigned _unknownSwitchCnt;
const unsigned _borderSwitchCnt;
BlackBorderDetector _detector;
BlackBorder _currentBorder;
BlackBorder _lastDetectedBorder;
unsigned _consistentCnt;
};

View File

@@ -18,6 +18,7 @@ SET(Hyperion_HEADERS
${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}/ColorTransform.h
)
@@ -32,6 +33,7 @@ SET(Hyperion_SOURCES
${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}/ColorTransform.cpp
)