Change functions in PlaYUVerFrame in order to enable more advance comparison between frames in PlaYUVerModules

This commit is contained in:
jfmcarreira committed 2015-11-08 01:42:27 +00:00
1 parent 51fa281693
commit 3ed990c102
10 files changed
+213 -188

No files matched your search

+4 -2
View File
@@ -359,7 +359,8 @@ Void FramePropertiesDock::setSelection( const QRect &selectionArea )
if( selectionArea.isValid() )
{
histogramWidget->stopHistogramComputation();
histogramWidget->updateSelectionData( new PlaYUVerFrame( m_pcFrame, selectionArea.x(), selectionArea.y(), selectionArea.width(), selectionArea.height() ) );
histogramWidget->updateSelectionData(
new PlaYUVerFrame( m_pcFrame, selectionArea.x(), selectionArea.y(), selectionArea.width(), selectionArea.height() ) );
fullImageButton->show();
selectionImageButton->show();
selectionImageButton->click();
@@ -376,7 +377,8 @@ Void FramePropertiesDock::setSelection( const QRect &selectionArea )
Void FramePropertiesDock::updateDataHistogram()
{
if( m_pcFrame->isValid() && isVisible() )
//if( m_pcFrame->isValid() && isVisible() )
if( m_pcFrame && isVisible() )
{
if( !( *pbMainPlaySwitch && m_pbIsPlaying ) )
{
+12 -7
View File
@@ -316,13 +316,18 @@ Void ModulesHandle::activateModule()
}
}
}
// Check for same fmt in more than one frame modules
for( Int i = 1; i < videoSubWindowList.size(); i++ )
if( pcCurrAppModuleIf->m_pcModule->m_iModuleAPI == MODULE_API_1 )
{
if( !videoSubWindowList.at( i )->getCurrFrame()->haveSameFmt( videoSubWindowList.at( 0 )->getCurrFrame() ) )
// Check for same fmt in more than one frame modules
for( Int i = 1; i < videoSubWindowList.size(); i++ )
{
videoSubWindowList.clear();
break;
if( !videoSubWindowList.at( i )->getCurrFrame()->haveSameFmt( videoSubWindowList.at( 0 )->getCurrFrame() ) )
{
videoSubWindowList.clear();
qobject_cast<PlaYUVerApp*>( m_pcParent )->printMessage( "Error! Incompatible frames", LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
return;
}
}
}
}
@@ -333,7 +338,7 @@ Void ModulesHandle::activateModule()
if( videoSubWindowList.size() == 0 )
{
qobject_cast<PlaYUVerApp*>( m_pcParent )->printMessage( "Error! Module cannot be applied", LOG_ERROR );
qobject_cast<PlaYUVerApp*>( m_pcParent )->printMessage( "Error! There is no windows to apply the module", LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
return;
}
@@ -423,7 +428,7 @@ Void ModulesHandle::activateModule()
if( !moduleCreated )
{
qobject_cast<PlaYUVerApp*>( m_pcParent )->printMessage( "Error! Module cannot be applied", LOG_ERROR );
qobject_cast<PlaYUVerApp*>( m_pcParent )->printMessage( "Error! Module cannot be created", LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
return;
}
+1 -1
View File
@@ -560,7 +560,7 @@ Void PlaYUVerApp::printMessage( const QString& msg, UInt logLevel )
{
if( !msg.isEmpty() )
{
statusBar()->showMessage( msg, 5000 );
statusBar()->showMessage( msg, 10000 );
if( logLevel >= LOG_INFO )
{
m_pcWindowHandle->processLogMsg( msg );
+71 -47
View File
@@ -104,7 +104,7 @@ PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pelFormat, Int bitsPi
init( width, height, pelFormat, bitsPixel );
}
PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other )
PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other, Bool bCopy )
{
init( other->getWidth(), other->getHeight(), other->getPelFormat(), other->getBitsPel() );
copyFrom( other );
@@ -190,6 +190,7 @@ static Int getMem3ImageComponents( Pel**** array3D, Int dim1, Int dim2, Int log2
Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel )
{
m_bInit = false;
m_pppcInputPel = NULL;
m_pcARGB32 = NULL;
m_uiWidth = width;
@@ -227,6 +228,8 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
m_uiHistoChannels = m_pcPelFormat->numberChannels;
m_cPelFmtName = PlaYUVerFrame::supportedPixelFormatListNames()[m_iPixelFormat].c_str();
m_bInit = true;
}
Void PlaYUVerFrame::clear()
@@ -247,6 +250,25 @@ Void PlaYUVerFrame::clear()
}
}
Bool PlaYUVerFrame::haveSameFmt( PlaYUVerFrame* other, FormatMatching match ) const
{
Bool bRet = true;
if( other )
{
if( match & MATCH_RESOLUTION )
bRet &= ( m_uiWidth == other->getWidth() ) && ( m_uiHeight == other->getHeight() );
if( match & MATCH_PEL_FMT )
bRet &= ( m_iPixelFormat == other->getPelFormat() );
if( match & MATCH_BITS )
bRet &= ( m_iBitsPel == other->getBitsPel() );
}
else
{
bRet = false;
}
return bRet;
}
std::string PlaYUVerFrame::getPelFmtName()
{
return m_pcPelFormat->name;
@@ -319,6 +341,49 @@ UInt PlaYUVerFrame::getChromaSize() const
return getChromaWidth() * getChromaHeight();
}
PlaYUVerFrame::Pixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, ColorSpace eColorSpace )
{
PlaYUVerFrame::Pixel PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 );
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{
Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0;
Int ratioW = ch > 0 ? m_pcPelFormat->log2ChromaHeight : 0;
PixelValue.Components()[ch] = m_pppcInputPel[ch][( yPos >> ratioH )][( xPos >> ratioW )];
}
if( eColorSpace != COLOR_INVALID )
{
PixelValue = ConvertPixel( PixelValue, eColorSpace );
}
return PixelValue;
}
Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame )
{
if( m_iPixelFormat != input_frame->getPelFormat() && m_uiWidth == input_frame->getWidth() && m_uiHeight == input_frame->getHeight() )
return;
m_bHasRGBPel = false;
m_bHasHistogram = false;
memcpy( *m_pppcInputPel[LUMA], input_frame->getPelBufferYUV()[LUMA][0], getBytesPerFrame() * sizeof(Pel) );
}
Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos )
{
if( m_iPixelFormat != input_frame->getPelFormat() )
return;
Pel ***pInput = input_frame->getPelBufferYUV();
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{
Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0;
Int ratioW = ch > 0 ? m_pcPelFormat->log2ChromaHeight : 0;
for( UInt i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ); i++ )
{
memcpy( m_pppcInputPel[ch][i], &( pInput[ch][( yPos >> ratioH ) + i][( xPos >> ratioW )] ), ( m_uiWidth >> ratioW ) * sizeof(Pel) );
}
}
m_bHasRGBPel = false;
m_bHasHistogram = false;
}
Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize )
{
if( uiBuffSize != getBytesPerFrame() )
@@ -402,7 +467,6 @@ Void PlaYUVerFrame::frameToBuffer( Byte *output_buffer )
pTmpBuff += step;
}
}
}
Void PlaYUVerFrame::fillRGBBuffer()
@@ -487,7 +551,10 @@ Void PlaYUVerFrame::fillRGBBuffer()
m_bHasRGBPel = true;
}
// statistics
/**
* Histogram
*/
Void PlaYUVerFrame::calcHistogram()
{
if( m_bHasHistogram )
@@ -822,49 +889,6 @@ Double PlaYUVerFrame::getMaximum( Int channel )
return max;
}
Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame )
{
if( m_iPixelFormat != input_frame->getPelFormat() && m_uiWidth == input_frame->getWidth() && m_uiHeight == input_frame->getHeight() )
return;
m_bHasRGBPel = false;
m_bHasHistogram = false;
memcpy( *m_pppcInputPel[LUMA], input_frame->getPelBufferYUV()[LUMA][0], getBytesPerFrame() * sizeof(Pel) );
}
Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos )
{
if( m_iPixelFormat != input_frame->getPelFormat() )
return;
Pel ***pInput = input_frame->getPelBufferYUV();
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{
Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0;
Int ratioW = ch > 0 ? m_pcPelFormat->log2ChromaHeight : 0;
for( UInt i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ); i++ )
{
memcpy( m_pppcInputPel[ch][i], &( pInput[ch][( yPos >> ratioH ) + i][( xPos >> ratioW )] ), ( m_uiWidth >> ratioW ) * sizeof(Pel) );
}
}
m_bHasRGBPel = false;
m_bHasHistogram = false;
}
PlaYUVerFrame::Pixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, ColorSpace eColorSpace )
{
PlaYUVerFrame::Pixel PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 );
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{
Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0;
Int ratioW = ch > 0 ? m_pcPelFormat->log2ChromaHeight : 0;
PixelValue.Components()[ch] = m_pppcInputPel[ch][( yPos >> ratioH )][( xPos >> ratioW )];
}
if( eColorSpace != COLOR_INVALID )
{
PixelValue = ConvertPixel( PixelValue, eColorSpace );
}
return PixelValue;
}
/*
**************************************************************
* Interface to other libs
@@ -981,7 +1005,7 @@ Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame )
}
}
if( !isValid() )
if( !m_bInit )
{
init( pcCvFrame->cols, pcCvFrame->rows, m_iPixelFormat, 8 );
}
+68 -79
View File
@@ -144,6 +144,16 @@ public:
NUMBER_FORMATS
};
/** Format match opts
*/
enum FormatMatching
{
MATCH_RESOLUTION = 1,
MATCH_PEL_FMT = 2,
MATCH_BITS = 4,
MATCH_ALL = 0xFFFF,
};
/**
* Function that handles the supported color space
* of PlaYUVerFrame
@@ -191,7 +201,7 @@ public:
*
* @param other existing frame to copy from
*/
PlaYUVerFrame( PlaYUVerFrame * );
PlaYUVerFrame( PlaYUVerFrame *other, Bool copy = true );
/**
* Creates and new frame with the configuration of an
@@ -210,68 +220,6 @@ public:
Void clear();
/**
* Get number of bytes per frame of an existing frame
* @return number of bytes per frame
*/
UInt64 getBytesPerFrame();
Int getColorSpace() const;
UInt getNumberChannels() const;
UInt getPixels() const;
UInt8 getChromaWidthRatio() const;
UInt8 getChromaHeightRatio() const;
UInt getChromaWidth() const;
UInt getChromaHeight() const;
UInt getChromaLength() const;
UInt getChromaSize() const;
Void frameFromBuffer( Byte*, UInt64 );
Void frameToBuffer( Byte* );
Void fillRGBBuffer();
Void calcHistogram();
// Methods for to manipulate the histogram data.
Double getCount( Int channel, UInt start, UInt end );
Double getMean( Int channel, UInt start, UInt end );
Int getMedian( Int channel, UInt start, UInt end );
/**
* @return Number of image pixels
*/
Double getStdDev( Int channel, UInt start, UInt end );
Double getHistogramValue( Int channel, UInt bin );
Double getMaximum( Int channel );
/**
* @return Number of histogram segments: 256 or 65536 for 8 or 16 bits per
* sample.
*/
Int getHistogramSegment();
/**
* Control calculation
*/
Void setRunningFlag( Bool bFlag )
{
m_bRunningFlag = bFlag;
}
Bool getHasHistogram()
{
return m_bHasHistogram;
}
Void copyFrom( PlaYUVerFrame* );
Void copyFrom( PlaYUVerFrame*, UInt, UInt );
PlaYUVerFrame::Pixel getPixelValue( Int xPos, Int yPos, ColorSpace eColorSpace = COLOR_INVALID );
std::string getPelFmtName();
UInt getWidth() const
{
return m_uiWidth;
@@ -288,21 +236,7 @@ public:
{
return m_iBitsPel;
}
Bool isValid() const
{
return ( m_uiWidth > 0 ) && ( m_uiHeight > 0 ) && ( m_iPixelFormat >= 0 );
}
Bool haveSameFmt( PlaYUVerFrame* other ) const
{
if( other )
{
return ( m_uiWidth == other->getWidth() ) && ( m_uiHeight == other->getHeight() ) && ( m_iPixelFormat == other->getPelFormat() );
}
else
{
return false;
}
}
Pel*** getPelBufferYUV() const
{
return m_pppcInputPel;
@@ -331,6 +265,59 @@ public:
return m_pcARGB32;
}
/**
* Get number of bytes per frame of an existing frame
* @return number of bytes per frame
*/
UInt64 getBytesPerFrame();
Int getColorSpace() const;
UInt getNumberChannels() const;
UInt getPixels() const;
UInt8 getChromaWidthRatio() const;
UInt8 getChromaHeightRatio() const;
UInt getChromaWidth() const;
UInt getChromaHeight() const;
UInt getChromaLength() const;
UInt getChromaSize() const;
PlaYUVerFrame::Pixel getPixelValue( Int xPos, Int yPos, ColorSpace eColorSpace = COLOR_INVALID );
Void copyFrom( PlaYUVerFrame* );
Void copyFrom( PlaYUVerFrame*, UInt, UInt );
Void frameFromBuffer( Byte*, UInt64 );
Void frameToBuffer( Byte* );
Void fillRGBBuffer();
Bool haveSameFmt( PlaYUVerFrame* other, FormatMatching match = MATCH_ALL ) const;
std::string getPelFmtName();
/**
* Histogram
*/
Void calcHistogram();
Double getCount( Int channel, UInt start, UInt end );
Double getMean( Int channel, UInt start, UInt end );
Int getMedian( Int channel, UInt start, UInt end );
Double getStdDev( Int channel, UInt start, UInt end );
Double getHistogramValue( Int channel, UInt bin );
Double getMaximum( Int channel );
Int getHistogramSegment();
Void setRunningFlag( Bool bFlag )
{
m_bRunningFlag = bFlag;
}
Bool getHasHistogram()
{
return m_bHasHistogram;
}
/**
* Interface with OpenCV lib
*/
@@ -375,7 +362,9 @@ public:
private:
//! Strcut with the pixel format description.
Bool m_bInit;
//! Struct with the pixel format description.
PlaYUVerPixFmtDescriptor* m_pcPelFormat;
std::string m_cPelFmtName;
+1 -1
View File
@@ -47,7 +47,7 @@ if( apcFrameList.size() != m_uiNumberOfFrames ) \
return false; \
for( UInt i = 0; i < apcFrameList.size(); i++ ) \
if( !apcFrameList[i] ) \
return false;
return false;
enum // Module API
{
+46 -46
View File
@@ -75,52 +75,6 @@ typedef struct
*/
class PlaYUVerStream
{
private:
Bool m_bInit;
Bool m_bIsInput;
Bool m_bIsOpened;
Bool m_bLoadAll;
enum PlaYUVerStreamHandlers
{
INVALID_HANDLER = -1,
YUV_IO,
OPENCV_HANDLER,
FFMPEG,
TOTAL_HANDLERR
};
Int m_iStreamHandler;
LibAvContextHandle* m_cLibAvContext;
std::string m_cFilename;
Char* m_pchFilename;
std::string m_cFormatName;
std::string m_cCodedName;
UInt m_uiWidth;
UInt m_uiHeight;
Int m_iPixelFormat;
UInt m_uiBitsPerPixel;
Double m_dFrameRate;
UInt64 m_uiTotalFrameNum;
Int64 m_iCurrFrameNum;
FILE* m_pFile; /**< The input file pointer >*/
std::fstream m_fsIOStream; /**< The input file pointer >*/
Byte* m_pStreamBuffer;
UInt m_uiFrameBufferSize;
PlaYUVerFrame **m_ppcFrameBuffer;
PlaYUVerFrame *m_pcCurrFrame;
PlaYUVerFrame *m_pcNextFrame;
UInt m_uiFrameBufferIndex;
UInt64 m_uiCurrFrameFileIdx;
Void findHandler();
public:
static std::vector<PlaYUVerSupportedFormat> supportedReadFormats();
@@ -211,6 +165,52 @@ public:
}
Void getDuration( Int* duration_array );
private:
Bool m_bInit;
Bool m_bIsInput;
Bool m_bIsOpened;
Bool m_bLoadAll;
enum PlaYUVerStreamHandlers
{
INVALID_HANDLER = -1,
YUV_IO,
OPENCV_HANDLER,
FFMPEG,
TOTAL_HANDLERR
};
Int m_iStreamHandler;
LibAvContextHandle* m_cLibAvContext;
std::string m_cFilename;
Char* m_pchFilename;
std::string m_cFormatName;
std::string m_cCodedName;
UInt m_uiWidth;
UInt m_uiHeight;
Int m_iPixelFormat;
UInt m_uiBitsPerPixel;
Double m_dFrameRate;
UInt64 m_uiTotalFrameNum;
Int64 m_iCurrFrameNum;
FILE* m_pFile; /**< The input file pointer >*/
std::fstream m_fsIOStream; /**< The input file pointer >*/
Byte* m_pStreamBuffer;
UInt m_uiFrameBufferSize;
PlaYUVerFrame **m_ppcFrameBuffer;
PlaYUVerFrame *m_pcCurrFrame;
PlaYUVerFrame *m_pcNextFrame;
UInt m_uiFrameBufferIndex;
UInt64 m_uiCurrFrameFileIdx;
Void findHandler();
};
} // NAMESPACE
+6 -1
View File
@@ -37,7 +37,7 @@ AbsoluteFrameDifference::AbsoluteFrameDifference()
m_pchModuleCategory = "Measurements"; // Category (sub-menu)
m_pchModuleName = "AbsoluteFrameDifference"; // Name
m_pchModuleTooltip = "Measure the absolute difference " // Description
"between two images (Y plane), e. g., abs( Y1 - Y2 )";
"between two images (Y plane), e. g., abs( Y1 - Y2 )";
m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES)
m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; // Module requirements (check PlaYUVerModulesIf.h).
// Several requirements should be "or" between each others.
@@ -48,6 +48,11 @@ AbsoluteFrameDifference::AbsoluteFrameDifference()
Bool AbsoluteFrameDifference::create( std::vector<PlaYUVerFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
for( UInt i = 0; i < apcFrameList.size(); i++ )
if( !apcFrameList[i]->haveSameFmt( apcFrameList[i], PlaYUVerFrame::MATCH_RESOLUTION ) )
return false;
m_pcFrameDifference = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY );
return true;
}
+3 -4
View File
@@ -39,7 +39,8 @@ FrameShift::FrameShift()
m_uiModuleRequirements = MODULE_REQUIRES_OPTIONS | MODULE_USES_KEYS;
m_cModuleOptions.addOptions()/**/
( "ShiftHorizontal", m_iShiftHor, "Amount of pixels to shift in horizontal direction" );
( "ShiftHorizontal", m_iShiftHor, "Amount of pixels to shift in horizontal direction" )/**/
( "ShiftVertical", m_iShiftVer, "Amount of pixels to shift in vertical direction" );
m_pcProcessedFrame = NULL;
m_iShiftHor = 10;
@@ -48,9 +49,7 @@ FrameShift::FrameShift()
Bool FrameShift::create( std::vector<PlaYUVerFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_pcProcessedFrame = NULL;
m_pcProcessedFrame = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel() );
m_pcProcessedFrame = new PlaYUVerFrame( apcFrameList[0], false );
m_iShiftHor = ( ( m_iShiftHor + 1 ) >> 1 ) << 1;
return true;
+1
View File
@@ -37,6 +37,7 @@ REGISTER_CLASS_FACTORY( FrameShift )
private:
PlaYUVerFrame* m_pcProcessedFrame;
Int m_iShiftHor;
Int m_iShiftVer;
public:
FrameShift();
virtual ~FrameShift()