From 6a6fdab5e52f8f0d09bb97bec52a4b44c61fe281 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 23 Feb 2015 18:20:24 +0000 Subject: [PATCH] Add new command line tools and improve the quality measuring --- lib/PlaYUVerCmdParser.cpp | 4 +- tools/PlaYUVerTools.cpp | 101 +++++++++++++++++++++++++++++--------- tools/PlaYUVerTools.h | 6 ++- tools/main.cpp | 14 +++++- 4 files changed, 95 insertions(+), 30 deletions(-) diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index c965f41..d3b7808 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -49,10 +49,10 @@ po::options_description PlaYUVerCmdParser::GetCommandOpts() po::options_description inputOpts( "Input" ); inputOpts.add_options() ( "input,i", po::value >(), "input file" ) + ( "output,o", po::value >(), "output file" ) ( "size,s", po::value(), "size (WxH)" ) ( "pel_fmt", po::value(), "pixel format name" ) - ( "width,w", po::value(), "width" ) - ( "height,h", po::value(), "height" ); + ( "frames,f", po::value(), "number of frames" ); po::options_description operationOpts( "Operation" ); operationOpts.add_options() diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 6d2e9c6..39d87a9 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -30,6 +30,7 @@ namespace plaYUVer PlaYUVerTools::PlaYUVerTools() { m_uiOperation = INVALID_OPERATION; + m_uiNumberOfFrames = -1; } PlaYUVerTools::~PlaYUVerTools() @@ -44,7 +45,7 @@ PlaYUVerTools::~PlaYUVerTools() } } -Int PlaYUVerTools::Init( Int argc, Char *argv[] ) +Int PlaYUVerTools::Open( Int argc, Char *argv[] ) { PlaYUVerCmdParser cCommandLineParser( argc, argv ); @@ -54,14 +55,16 @@ Int PlaYUVerTools::Init( Int argc, Char *argv[] ) return 1; } + /** + * Create input streams + */ if( cCommandLineParser.getOptionsMap().count( "input" ) ) { - if( !cCommandLineParser.getOptionsMap().count( "size" ) ) + std::string resolutionString; + if( cCommandLineParser.getOptionsMap().count( "size" ) ) { - printf( "Invalid resolution! " ); - return 2; + resolutionString = cCommandLineParser.getOptionsMap()["size"].as(); } - std::string resolutionString = cCommandLineParser.getOptionsMap()["size"].as(); std::string fmtString( "yuv420p" ); if( cCommandLineParser.getOptionsMap().count( "pel_fmt" ) ) { @@ -82,15 +85,31 @@ Int PlaYUVerTools::Init( Int argc, Char *argv[] ) m_apcInputStreams.push_back( pcStream ); } m_uiNumberOfFrames = MAX_UINT; - UInt currFrameNum; + if( cCommandLineParser.getOptionsMap().count( "frames" ) ) + { + m_uiNumberOfFrames = cCommandLineParser.getOptionsMap()["frames"].as(); + } + + m_uiNumberOfComponents = MAX_UINT; for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) { - currFrameNum = m_apcInputStreams[i]->getFrameNum(); - if( currFrameNum < m_uiNumberOfFrames ) - m_uiNumberOfFrames = currFrameNum; + if( m_apcInputStreams[i]->getFrameNum() < m_uiNumberOfFrames ) + m_uiNumberOfFrames = m_apcInputStreams[i]->getFrameNum(); + if( m_apcInputStreams[i]->getCurrFrame()->getNumberChannels() < m_uiNumberOfComponents ) + m_uiNumberOfComponents = m_apcInputStreams[i]->getCurrFrame()->getNumberChannels(); } } + /** + * Create output streams + */ + if( cCommandLineParser.getOptionsMap().count( "output" ) ) + { + + } + /** + * Check Quality operation + */ if( cCommandLineParser.getOptionsMap().count( "quality" ) ) { m_uiOperationIndex = -1; @@ -115,6 +134,14 @@ Int PlaYUVerTools::Init( Int argc, Char *argv[] ) m_uiOperation = QUALITY_OPERATION; } + /** + * Check Module operation + */ + if( cCommandLineParser.getOptionsMap().count( "module" ) ) + { + + } + if( m_uiOperation == INVALID_OPERATION ) { printf( "No operation was selected! " ); @@ -123,49 +150,75 @@ Int PlaYUVerTools::Init( Int argc, Char *argv[] ) return 0; } -Void PlaYUVerTools::Process() +Int PlaYUVerTools::Process() { switch( m_uiOperation ) { case QUALITY_OPERATION: + printf( " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiOperationIndex].c_str() ); qualityOperation(); break; } + return 0; +} + +Int PlaYUVerTools::Close() +{ +// Finish + return 0; } Void PlaYUVerTools::qualityOperation() { PlaYUVerFrame* apcCurrFrame[m_apcInputStreams.size()]; Bool abEOF[m_apcInputStreams.size()]; + Double adAverageQuality[m_apcInputStreams.size() - 1][m_uiNumberOfComponents]; Double dQuality; - for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) - abEOF[i] = false; - + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) + { + abEOF[s] = false; + for( UInt c = 0; c < m_uiNumberOfComponents; c++ ) + { + adAverageQuality[s][c] = 0; + } + } for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ ) { printf( " %3d", frame ); - for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) - apcCurrFrame[i] = m_apcInputStreams[i]->getCurrFrame(); + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) + apcCurrFrame[s] = m_apcInputStreams[s]->getCurrFrame(); - for( UInt i = 1; i < m_apcInputStreams.size(); i++ ) + for( UInt s = 1; s < m_apcInputStreams.size(); s++ ) { printf( " " ); - for( Int component = 0; component < 3; component++ ) + for( UInt c = 0; c < m_uiNumberOfComponents; c++ ) { - dQuality = apcCurrFrame[i]->getQuality( m_uiOperationIndex, apcCurrFrame[0], component ); - printf( " %5.3f", dQuality ); + dQuality = apcCurrFrame[s]->getQuality( m_uiOperationIndex, apcCurrFrame[0], c ); + adAverageQuality[s - 1][c] = ( adAverageQuality[s - 1][c] * Double( frame ) + dQuality ) / Double( frame + 1 ); + printf( " %5.3f", dQuality ); } } printf( "\n" ); - for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) { - if( !abEOF[i] ) - m_apcInputStreams[i]->readFrame(); - abEOF[i] |= m_apcInputStreams[i]->checkErrors( PlaYUVerStream::LAST_FRAME ); - m_apcInputStreams[i]->setNextFrame(); + m_apcInputStreams[s]->setNextFrame(); + if( !abEOF[s] ) + { + m_apcInputStreams[s]->readFrame(); + abEOF[s] = m_apcInputStreams[s]->checkErrors( PlaYUVerStream::LAST_FRAME ); + } } } + printf( "\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] ); + } + } + printf( "\n"); } } // NAMESPACE diff --git a/tools/PlaYUVerTools.h b/tools/PlaYUVerTools.h index ce3b48d..5e6f4a3 100644 --- a/tools/PlaYUVerTools.h +++ b/tools/PlaYUVerTools.h @@ -40,8 +40,9 @@ public: PlaYUVerTools(); ~PlaYUVerTools(); - Int Init( Int argc, Char *argv[] ); - Void Process(); + Int Open( Int argc, Char *argv[] ); + Int Process(); + Int Close(); private: UInt m_uiOperation; @@ -54,6 +55,7 @@ private: }; UInt m_uiNumberOfFrames; + UInt m_uiNumberOfComponents; std::vector m_apcInputStreams; std::vector m_apcOutputStreams; diff --git a/tools/main.cpp b/tools/main.cpp index df3a9f3..910ddc6 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -31,12 +31,22 @@ int main( int argc, char *argv[] ) { PlaYUVerTools PlaYUVerToolsApp; - if( PlaYUVerToolsApp.Init( argc, argv ) > 1 ) + if( PlaYUVerToolsApp.Open( argc, argv ) > 1 ) { printf( "Exiting\n" ); return 1; } - PlaYUVerToolsApp.Process(); + if( PlaYUVerToolsApp.Process() > 1 ) + { + printf( "Exiting\n" ); + return 1; + } + + if( PlaYUVerToolsApp.Close() > 1 ) + { + printf( "Exiting\n" ); + return 1; + } }