2013-08-21 16:25:27 +02:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
// Hyperion includes
|
2013-11-11 10:00:37 +01:00
|
|
|
#include <utils/ColorRgb.h>
|
2013-08-21 16:25:27 +02:00
|
|
|
|
2014-01-26 14:23:08 +01:00
|
|
|
// Blackborder includes
|
|
|
|
#include <blackborder/BlackBorderDetector.h>
|
|
|
|
|
2013-08-23 07:08:44 +02:00
|
|
|
using namespace hyperion;
|
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
ColorRgb randomColor()
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
|
|
|
|
const uint8_t randomGreenValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
|
|
|
|
const uint8_t randomBlueValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
|
|
|
|
|
|
|
|
return {randomRedValue, randomGreenValue, randomBlueValue};
|
|
|
|
}
|
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
Image<ColorRgb> createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
Image<ColorRgb> image(width, height);
|
2013-08-21 16:25:27 +02:00
|
|
|
for (unsigned x=0; x<image.width(); ++x)
|
|
|
|
{
|
|
|
|
for (unsigned y=0; y<image.height(); ++y)
|
|
|
|
{
|
|
|
|
if (y < topBorder || x < leftBorder)
|
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
image(x,y) = ColorRgb::BLACK;
|
2013-08-21 16:25:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image(x,y) = randomColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TC_NO_BORDER()
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
2014-01-20 20:46:38 +01:00
|
|
|
BlackBorderDetector detector(3);
|
2013-08-21 16:25:27 +02:00
|
|
|
|
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
Image<ColorRgb> image = createImage(64, 64, 0, 0);
|
2013-08-21 16:25:27 +02:00
|
|
|
BlackBorder border = detector.process(image);
|
2013-10-27 09:25:02 +01:00
|
|
|
if (border.unknown != false && border.horizontalSize != 0 && border.verticalSize != 0)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
std::cerr << "Failed to correctly detect no border" << std::endl;
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TC_TOP_BORDER()
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
2014-01-20 20:46:38 +01:00
|
|
|
BlackBorderDetector detector(3);
|
2013-08-21 16:25:27 +02:00
|
|
|
|
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
Image<ColorRgb> image = createImage(64, 64, 12, 0);
|
2013-08-21 16:25:27 +02:00
|
|
|
BlackBorder border = detector.process(image);
|
2013-10-27 09:25:02 +01:00
|
|
|
if (border.unknown != false && border.horizontalSize != 12 && border.verticalSize != 0)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
std::cerr << "Failed to correctly detect horizontal border with correct size" << std::endl;
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TC_LEFT_BORDER()
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
2014-01-20 20:46:38 +01:00
|
|
|
BlackBorderDetector detector(3);
|
2013-08-21 16:25:27 +02:00
|
|
|
|
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
Image<ColorRgb> image = createImage(64, 64, 0, 12);
|
2013-08-21 16:25:27 +02:00
|
|
|
BlackBorder border = detector.process(image);
|
2013-10-27 09:25:02 +01:00
|
|
|
if (border.unknown != false && border.horizontalSize != 0 && border.verticalSize != 12)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
std::cerr << "Failed to detected vertical border with correct size" << std::endl;
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-10-27 09:25:02 +01:00
|
|
|
int TC_DUAL_BORDER()
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
2014-01-20 20:46:38 +01:00
|
|
|
BlackBorderDetector detector(3);
|
2013-08-21 16:25:27 +02:00
|
|
|
|
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
Image<ColorRgb> image = createImage(64, 64, 12, 12);
|
2013-08-21 16:25:27 +02:00
|
|
|
BlackBorder border = detector.process(image);
|
2013-10-27 09:25:02 +01:00
|
|
|
if (border.unknown != false && border.horizontalSize != 12 && border.verticalSize != 12)
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to detected two-sided border" << std::endl;
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TC_UNKNOWN_BORDER()
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
2014-01-20 20:46:38 +01:00
|
|
|
BlackBorderDetector detector(3);
|
2013-10-27 09:25:02 +01:00
|
|
|
|
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
Image<ColorRgb> image = createImage(64, 64, 30, 30);
|
2013-10-27 09:25:02 +01:00
|
|
|
BlackBorder border = detector.process(image);
|
|
|
|
if (border.unknown != true)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
std::cerr << "Failed to detected unknown border" << std::endl;
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
TC_NO_BORDER();
|
|
|
|
TC_TOP_BORDER();
|
|
|
|
TC_LEFT_BORDER();
|
2013-10-27 09:25:02 +01:00
|
|
|
TC_DUAL_BORDER();
|
2013-08-21 16:25:27 +02:00
|
|
|
TC_UNKNOWN_BORDER();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|