2013-08-21 22:44:17 +02:00
// STL includes
2013-11-11 10:00:37 +01:00
# include <cassert>
2013-08-21 22:44:17 +02:00
# include <random>
2013-11-11 10:00:37 +01:00
# include <iostream>
2013-08-21 22:44:17 +02:00
// Utils includes
2013-11-11 10:00:37 +01:00
# include <utils/Image.h>
# include <utils/ColorRgb.h>
2013-08-21 22:44:17 +02:00
2014-01-26 14:23:08 +01:00
// Blackborder includes
# include "blackborder/BlackBorderProcessor.h"
2013-08-21 22:44:17 +02:00
2013-08-23 07:08:44 +02:00
using namespace hyperion ;
2013-11-11 10:00:37 +01:00
ColorRgb randomColor ( )
2013-08-21 22:44:17 +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 22:44:17 +02:00
{
2013-11-11 10:00:37 +01:00
Image < ColorRgb > image ( width , height ) ;
2013-08-21 22:44:17 +02:00
for ( unsigned x = 0 ; x < image . width ( ) ; + + x )
{
for ( unsigned y = 0 ; y < image . height ( ) ; + + y )
{
2016-01-19 23:43:00 +01:00
if ( y < topBorder | | y > ( height - topBorder ) | | x < leftBorder | | x > ( width - leftBorder ) )
2013-08-21 22:44:17 +02:00
{
2013-11-11 10:00:37 +01:00
image ( x , y ) = ColorRgb : : BLACK ;
2013-08-21 22:44:17 +02:00
}
else
{
image ( x , y ) = randomColor ( ) ;
}
}
}
return image ;
}
int main ( )
{
2016-02-07 13:26:40 +01:00
// unsigned unknownCnt = 600;
2013-08-21 22:44:17 +02:00
unsigned borderCnt = 50 ;
2016-02-07 13:26:40 +01:00
// unsigned blurCnt = 0;
Json : : Value config ;
2013-08-21 22:44:17 +02:00
2016-02-07 13:26:40 +01:00
// BlackBorderProcessor processor(unknownCnt, borderCnt, blurCnt, 3, config);
BlackBorderProcessor processor ( config ) ;
2013-08-21 22:44:17 +02:00
// Start with 'no border' detection
2013-11-11 10:00:37 +01:00
Image < ColorRgb > noBorderImage = createImage ( 64 , 64 , 0 , 0 ) ;
2013-08-21 22:44:17 +02:00
for ( unsigned i = 0 ; i < 10 ; + + i )
{
bool newBorder = processor . process ( noBorderImage ) ;
if ( i = = 0 )
{
// Switch to 'no border' should immediate
if ( ! newBorder )
{
std : : cerr < < " Failed to detect 'no border' when required " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
}
else
{
if ( newBorder )
{
std : : cerr < < " Incorrectly detected new border, when there in none " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
}
}
2013-10-27 09:25:02 +01:00
2013-08-21 22:44:17 +02:00
// Verify that the border is indeed
2013-10-27 09:25:02 +01:00
if ( processor . getCurrentBorder ( ) . unknown ! = false | | processor . getCurrentBorder ( ) . horizontalSize ! = 0 | | processor . getCurrentBorder ( ) . verticalSize ! = 0 )
2013-08-21 22:44:17 +02:00
{
2013-10-27 09:25:02 +01:00
std : : cerr < < " Incorrectlty identified 'no border' " < < std : : endl ;
2013-08-21 22:44:17 +02:00
exit ( EXIT_FAILURE ) ;
}
int borderSize = 12 ;
2013-11-11 10:00:37 +01:00
Image < ColorRgb > horzImage = createImage ( 64 , 64 , borderSize , 0 ) ;
2013-08-21 22:44:17 +02:00
for ( unsigned i = 0 ; i < borderCnt * 2 ; + + i )
{
bool newBorder = processor . process ( horzImage ) ;
2016-01-19 23:43:00 +01:00
if ( i = = borderCnt + 10 ) // 10 frames till new border gets a chance to proof consistency
2013-08-21 22:44:17 +02:00
{
if ( ! newBorder )
{
std : : cerr < < " Failed to detect 'horizontal border' when required after " < < borderCnt < < " images " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
}
else
{
if ( newBorder )
{
std : : cerr < < " Incorrectly detected new border, when there in none " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
}
}
2013-10-27 09:25:02 +01:00
if ( processor . getCurrentBorder ( ) . unknown ! = false | | processor . getCurrentBorder ( ) . horizontalSize ! = borderSize | | processor . getCurrentBorder ( ) . verticalSize ! = 0 )
2013-08-21 22:44:17 +02:00
{
2013-10-27 09:25:02 +01:00
std : : cerr < < " Incorrectlty found 'horizontal border' ( " < < processor . getCurrentBorder ( ) . unknown < < " , " < < processor . getCurrentBorder ( ) . horizontalSize < < " , " < < processor . getCurrentBorder ( ) . verticalSize < < " ) " < < std : : endl ;
2013-08-21 22:44:17 +02:00
exit ( EXIT_FAILURE ) ;
}
2016-01-19 23:43:00 +01:00
for ( unsigned i = 0 ; i < borderCnt * 2 ; + + i )
2013-08-21 22:44:17 +02:00
{
2016-01-19 23:43:00 +01:00
bool newBorder = processor . process ( noBorderImage ) ;
if ( i = = borderCnt + 10 ) // 10 frames till new border gets a chance to proof consistency
{
if ( ! newBorder )
{
std : : cerr < < " Failed to detect 'no border' when required after " < < borderCnt < < " images " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
}
else
{
if ( newBorder )
{
std : : cerr < < " Incorrectly detected no border, when there in none " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
}
2013-08-21 22:44:17 +02:00
}
2016-01-19 23:43:00 +01:00
// Check switch back to no border
if ( ( processor . getCurrentBorder ( ) . unknown ! = false | | processor . getCurrentBorder ( ) . horizontalSize ! = 0 | | processor . getCurrentBorder ( ) . verticalSize ! = 0 ) )
{
std : : cerr < < " Failed to switch back to 'no border' " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
2013-11-11 10:00:37 +01:00
Image < ColorRgb > vertImage = createImage ( 64 , 64 , 0 , borderSize ) ;
2013-08-21 22:44:17 +02:00
for ( unsigned i = 0 ; i < borderCnt * 2 ; + + i )
{
bool newBorder = processor . process ( vertImage ) ;
2016-01-19 23:43:00 +01:00
if ( i = = borderCnt + 10 ) // 10 frames till new border gets a chance to proof consistency
2013-08-21 22:44:17 +02:00
{
if ( ! newBorder )
{
std : : cerr < < " Failed to detect 'vertical border' when required after " < < borderCnt < < " images " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
}
else
{
if ( newBorder )
{
std : : cerr < < " Incorrectly detected new border, when there in none " < < std : : endl ;
exit ( EXIT_FAILURE ) ;
}
}
}
2013-10-27 09:25:02 +01:00
if ( processor . getCurrentBorder ( ) . unknown ! = false | | processor . getCurrentBorder ( ) . horizontalSize ! = 0 | | processor . getCurrentBorder ( ) . verticalSize ! = borderSize )
2013-08-21 22:44:17 +02:00
{
2013-10-27 09:25:02 +01:00
std : : cerr < < " Incorrectlty found 'vertical border' " < < std : : endl ;
2013-08-21 22:44:17 +02:00
exit ( EXIT_FAILURE ) ;
}
// Switch back (in one shot) to no border
2016-01-19 23:43:00 +01:00
// assert(processor.process(noBorderImage));
// assert(processor.getCurrentBorder().verticalSize == 0 && processor.getCurrentBorder().horizontalSize == 0);
2013-08-21 22:44:17 +02:00
return 0 ;
}