Merge branch 'master' into develPlots

This commit is contained in:
jfmcarreira committed 2015-03-19 01:01:32 +00:00
commit 99e964203c
7 files changed
+98 -46

No files matched your search

+2 -1
View File
@@ -53,7 +53,7 @@ Void PlaYUVerCmdParser::Config( Int argc, Char *argv[] )
po::options_description PlaYUVerCmdParser::GetCommandOpts()
{
po::options_description inputOpts( "Input" );
po::options_description inputOpts( "InputOutput" );
inputOpts.add_options()/**/
( "input,i", po::value<std::vector<std::string> >(), "input file" ) /**/
( "output,o", po::value<std::vector<std::string> >(), "output file" ) /**/
@@ -64,6 +64,7 @@ po::options_description PlaYUVerCmdParser::GetCommandOpts()
po::options_description commonOpts( "Common" );
commonOpts.add_options()/**/
( "quiet,q", "disable verbose" )/**/
( "help", "produce help message" )/**/
( "version", "show version and exit" );
commonOpts.add( inputOpts );
+4 -1
View File
@@ -390,7 +390,10 @@ Bool PlaYUVerStream::openFile()
{
return false;
}
fseek( m_pFile, m_iCurrFrameNum >= 0 ? m_iCurrFrameNum : 0, SEEK_SET );
if ( m_bIsInput )
{
fseek( m_pFile, m_iCurrFrameNum >= 0 ? m_iCurrFrameNum : 0, SEEK_SET );
}
return true;
}
+13 -1
View File
@@ -23,6 +23,7 @@
*/
#include <cstring>
#include <cstdarg>
#include "CommandLineHandle.h"
#include "lib/PlaYUVerFrame.h"
#include "modules/PlaYUVerModuleIf.h"
@@ -33,7 +34,7 @@ namespace plaYUVer
CommandLineHandle::CommandLineHandle()
{
m_uiLogLevel = 0;
}
CommandLineHandle::~CommandLineHandle()
@@ -41,6 +42,17 @@ CommandLineHandle::~CommandLineHandle()
}
Void CommandLineHandle::log( UInt level, const char *fmt, ... )
{
if( level >= m_uiLogLevel )
{
std::va_list args;
va_start( args, fmt );
vfprintf( stdout, fmt, args );
va_end( args );
}
}
Int CommandLineHandle::parseToolsArgs()
{
Int iRet = 0;
+28
View File
@@ -38,9 +38,37 @@ public:
CommandLineHandle();
~CommandLineHandle();
enum LOG_LEVEL
{
INFO = 0,
WARNINGS = 1,
RESULT = 2,
ERROR = 3,
};
Void setLogLevel( enum LOG_LEVEL level )
{
m_uiLogLevel = level;
}
/**
* Send the specified message to the log if the level is higher than or equal
* to the current LogLevel. By default, all logging messages are sent to
* stdout.
*
* @param level The importance level of the message expressed using a @ref
* lavu_log_constants "Logging Constant".
* @param fmt The format string (printf-compatible) that specifies how
* subsequent arguments are converted to output.
*
* @note this function might not be safe in C++ (try to upgrade it)
*/
Void log( UInt level, const char *fmt, ... );
Int parseToolsArgs();
Void listModules();
private:
UInt m_uiLogLevel;
};
} // NAMESPACE
+46 -39
View File
@@ -31,6 +31,7 @@ namespace plaYUVer
PlaYUVerTools::PlaYUVerTools()
{
m_bVerbose = true;
m_uiOperation = INVALID_OPERATION;
m_uiNumberOfFrames = -1;
@@ -53,23 +54,28 @@ PlaYUVerTools::~PlaYUVerTools()
Int PlaYUVerTools::openInputs()
{
if( m_cCmdLineHandler.getOptionsMap().count( "quiet" ) )
{
m_bVerbose = false;
m_cCmdLineHandler.setLogLevel( CommandLineHandle::RESULT );
}
/**
* Create input streams
*/
if( m_cCommandLineParser.getOptionsMap().count( "input" ) )
if( m_cCmdLineHandler.getOptionsMap().count( "input" ) )
{
std::string resolutionString( "" );
if( m_cCommandLineParser.getOptionsMap().count( "size" ) )
if( m_cCmdLineHandler.getOptionsMap().count( "size" ) )
{
resolutionString = m_cCommandLineParser.getOptionsMap()["size"].as<std::string>();
resolutionString = m_cCmdLineHandler.getOptionsMap()["size"].as<std::string>();
}
std::string fmtString( "yuv420p" );
if( m_cCommandLineParser.getOptionsMap().count( "pel_fmt" ) )
if( m_cCmdLineHandler.getOptionsMap().count( "pel_fmt" ) )
{
fmtString = m_cCommandLineParser.getOptionsMap()["pel_fmt"].as<std::string>();
fmtString = m_cCmdLineHandler.getOptionsMap()["pel_fmt"].as<std::string>();
}
std::vector<std::string> inputFileNames = m_cCommandLineParser.getOptionsMap()["input"].as<std::vector<std::string> >();
std::vector<std::string> inputFileNames = m_cCmdLineHandler.getOptionsMap()["input"].as<std::vector<std::string> >();
PlaYUVerStream* pcStream;
for( UInt i = 0; i < inputFileNames.size(); i++ )
@@ -79,21 +85,21 @@ Int PlaYUVerTools::openInputs()
{
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, 1 ) )
{
printf( "Cannot open input stream %s! ", inputFileNames[i].c_str() );
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() );
return 2;
}
m_apcInputStreams.push_back( pcStream );
}
catch( const char *msg )
{
printf( "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg );
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg );
return 2;
}
}
m_uiNumberOfFrames = MAX_UINT;
if( m_cCommandLineParser.getOptionsMap().count( "frames" ) )
if( m_cCmdLineHandler.getOptionsMap().count( "frames" ) )
{
m_uiNumberOfFrames = m_cCommandLineParser.getOptionsMap()["frames"].as<UInt>();
m_uiNumberOfFrames = m_cCmdLineHandler.getOptionsMap()["frames"].as<UInt>();
}
m_uiNumberOfComponents = MAX_UINT;
@@ -110,7 +116,7 @@ Int PlaYUVerTools::openInputs()
Int PlaYUVerTools::openOutputs()
{
if( m_cCommandLineParser.getOptionsMap().count( "output" ) )
if( m_cCmdLineHandler.getOptionsMap().count( "output" ) )
{
}
@@ -121,8 +127,8 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
{
Int iRet = 0;
m_cCommandLineParser.Config( argc, argv );
if( ( iRet = m_cCommandLineParser.parseToolsArgs() ) > 0 )
m_cCmdLineHandler.Config( argc, argv );
if( ( iRet = m_cCmdLineHandler.parseToolsArgs() ) > 0 )
{
return iRet;
}
@@ -135,12 +141,12 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
/**
* Check Quality operation
*/
if( m_cCommandLineParser.getOptionsMap().count( "quality" ) )
if( m_cCmdLineHandler.getOptionsMap().count( "quality" ) )
{
std::string qualityMetric = m_cCommandLineParser.getOptionsMap()["quality"].as<std::string>();
std::string qualityMetric = m_cCmdLineHandler.getOptionsMap()["quality"].as<std::string>();
if( m_apcInputStreams.size() != 2 )
{
printf( "Invalid number of inputs! " );
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid number of inputs! " );
return 2;
}
for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ )
@@ -152,20 +158,20 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
if( m_uiQualityMetric == -1 )
{
printf( "Invalid quality metric! " );
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid quality metric! " );
return 2;
}
m_uiOperation = QUALITY_OPERATION;
m_fpProcess = &PlaYUVerTools::QualityOperation;
printf( "PlaYUVer Quality\n" );
m_cCmdLineHandler.log( CommandLineHandle::INFO, "PlaYUVer Quality\n" );
}
/**
* Check Module operation
*/
if( m_cCommandLineParser.getOptionsMap().count( "module" ) )
if( m_cCmdLineHandler.getOptionsMap().count( "module" ) )
{
std::string moduleName = m_cCommandLineParser.getOptionsMap()["module"].as<std::string>();
std::string moduleName = m_cCmdLineHandler.getOptionsMap()["module"].as<std::string>();
PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap();
PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin();
@@ -180,7 +186,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
if( m_apcInputStreams.size() != m_pcCurrModuleIf->m_uiNumberOfFrames )
{
printf( "Invalid number of inputs! " );
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid number of inputs! " );
return 2;
}
@@ -190,8 +196,8 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
{
// Check outputs
std::vector<std::string> outputFileNames;
if( m_cCommandLineParser.getOptionsMap().count( "output" ) )
outputFileNames = m_cCommandLineParser.getOptionsMap()["output"].as<std::vector<std::string> >();
if( m_cCmdLineHandler.getOptionsMap().count( "output" ) )
outputFileNames = m_cCmdLineHandler.getOptionsMap()["output"].as<std::vector<std::string> >();
if( outputFileNames.size() == 1 )
{
@@ -207,19 +213,19 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
else
{
printf( "One output is required! " );
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "One output is required! " );
return 2;
}
}
m_uiOperation = MODULE_OPERATION;
m_fpProcess = &PlaYUVerTools::ModuleOperation;
printf( "PlaYUVer Module\n" );
m_cCmdLineHandler.log( CommandLineHandle::INFO, "PlaYUVer Module\n" );
}
if( m_uiOperation == INVALID_OPERATION )
{
printf( "No operation was selected! " );
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "No operation was selected! " );
return 2;
}
return iRet;
@@ -243,7 +249,8 @@ Int PlaYUVerTools::QualityOperation()
Double adAverageQuality[m_apcInputStreams.size() - 1][m_uiNumberOfComponents];
Double dQuality;
printf( " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiQualityMetric].c_str() );
m_cCmdLineHandler.log( CommandLineHandle::INFO, " Measuring Quality using %s ... \n",
PlaYUVerFrame::supportedQualityMetricsList()[m_uiQualityMetric].c_str() );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
{
@@ -255,21 +262,21 @@ Int PlaYUVerTools::QualityOperation()
}
for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ )
{
printf( " %3d", frame );
m_cCmdLineHandler.log( CommandLineHandle::INFO, " %3d", frame );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
apcCurrFrame[s] = m_apcInputStreams[s]->getCurrFrame();
for( UInt s = 1; s < m_apcInputStreams.size(); s++ )
{
printf( " " );
m_cCmdLineHandler.log( CommandLineHandle::RESULT, " " );
for( UInt c = 0; c < m_uiNumberOfComponents; c++ )
{
dQuality = apcCurrFrame[s]->getQuality( m_uiQualityMetric, apcCurrFrame[0], c );
adAverageQuality[s - 1][c] = ( adAverageQuality[s - 1][c] * Double( frame ) + dQuality ) / Double( frame + 1 );
printf( " %5.3f", dQuality );
m_cCmdLineHandler.log( CommandLineHandle::RESULT, " %5.3f", dQuality );
}
}
printf( "\n" );
m_cCmdLineHandler.log( CommandLineHandle::RESULT, "\n" );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
{
abEOF[s] = m_apcInputStreams[s]->setNextFrame();
@@ -279,15 +286,15 @@ Int PlaYUVerTools::QualityOperation()
}
}
}
printf( "\n Mean Values: \n " );
m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n Mean Values: \n " );
for( UInt s = 0; s < m_apcInputStreams.size() - 1; s++ )
{
for( UInt c = 0; c < m_uiNumberOfComponents; c++ )
{
printf( " %5.3f", adAverageQuality[s][c] );
m_cCmdLineHandler.log( CommandLineHandle::INFO, " %5.3f", adAverageQuality[s][c] );
}
}
printf( "\n" );
m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n" );
return 0;
}
@@ -311,7 +318,7 @@ PlaYUVerFrame* PlaYUVerTools::applyFrameModule()
Int PlaYUVerTools::ModuleOperation()
{
printf( " Applying Module %s/%s ... \n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName );
m_cCmdLineHandler.log( CommandLineHandle::INFO, " Applying Module %s/%s ...\n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName );
PlaYUVerFrame* pcProcessedFrame = NULL;
Double dMeasurementResult = 0.0;
@@ -329,7 +336,7 @@ Int PlaYUVerTools::ModuleOperation()
if( m_pcCurrModuleIf->m_iModuleType == FRAME_PROCESSING_MODULE )
{
pcProcessedFrame = applyFrameModule();
m_apcInputStreams[0]->writeFrame( pcProcessedFrame );
m_apcOutputStreams[0]->writeFrame( pcProcessedFrame );
}
else if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE )
{
@@ -342,7 +349,8 @@ Int PlaYUVerTools::ModuleOperation()
dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame(), m_apcInputStreams[1]->getCurrFrame() );
break;
}
printf( " %3d %8.3f \n", frame, dMeasurementResult );
m_cCmdLineHandler.log( CommandLineHandle::INFO, " %3d", frame );
m_cCmdLineHandler.log( CommandLineHandle::RESULT, " %8.3f \n", dMeasurementResult );
dAveragedMeasurementResult = ( dAveragedMeasurementResult * Double( frame ) + dMeasurementResult ) / Double( frame + 1 );
}
@@ -354,12 +362,11 @@ Int PlaYUVerTools::ModuleOperation()
m_apcInputStreams[s]->readFrame();
}
}
}
if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE )
{
printf( "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult );
m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult );
}
return 0;
+2 -1
View File
@@ -47,7 +47,8 @@ public:
Int Close();
private:
CommandLineHandle m_cCommandLineParser;
CommandLineHandle m_cCmdLineHandler;
Bool m_bVerbose;
UInt m_uiOperation;
enum TOOLS_OPERATIONS_LIST
+3 -3
View File
@@ -39,19 +39,19 @@ int main( int argc, char *argv[] )
}
if( iRet > 1 )
{
printf( "Exiting\n" );
printf( "Exiting with error \n" );
return 1;
}
if( PlaYUVerToolsApp.Process() > 1 )
{
printf( "Exiting\n" );
printf( "Exiting with error \n" );
return 1;
}
if( PlaYUVerToolsApp.Close() > 1 )
{
printf( "Exiting\n" );
printf( "Exiting with error \n" );
return 1;
}