Fix minor errors when loading images with opencv

This commit is contained in:
jfmcarreira committed 2015-03-05 01:07:28 +00:00
1 parent d1ad36c28a
commit ee8f0c65d4
3 files changed
+82 -44

No files matched your search

+66 -34
View File
@@ -237,7 +237,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
m_uiStreamHandler = YUV_IO;
}
//#ifdef USE_OPENCV
// else if ( m_cFormatName == "png" )
// else if( m_cFormatName == "png" || m_cFormatName == "jpg" )
// {
// m_uiStreamHandler = OPENCV_HANDLER;
// }
@@ -279,6 +279,19 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
}
#endif
#ifdef USE_OPENCV
if( m_uiStreamHandler == OPENCV_HANDLER )
{
m_pcCurrFrame = LibOpenCVHandler::loadFrame( m_cFilename );
if( m_pcCurrFrame )
{
m_uiWidth = m_pcCurrFrame->getWidth();
m_uiHeight = m_pcCurrFrame->getHeight();
m_iPixelFormat = m_pcCurrFrame->getPelFormat();
}
}
#endif
if( m_uiWidth <= 0 || m_uiHeight <= 0 || m_iPixelFormat < 0 )
{
close();
@@ -286,49 +299,59 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
return m_bInit;
}
if( m_uiStreamHandler == YUV_IO )
if( m_uiStreamHandler != OPENCV_HANDLER )
{
if( !openFile() )
if( m_uiStreamHandler == YUV_IO )
{
close();
throw "[PlaYUVerStream] Cannot open file";
return m_bInit;
if( !openFile() )
{
close();
throw "[PlaYUVerStream] Cannot open file";
return m_bInit;
}
m_cFormatName = "YUV";
m_cCodedName = "Raw Video";
}
m_cFormatName = "YUV";
m_cCodedName = "Raw Video";
}
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
{
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
if( !m_ppcFrameBuffer[i] )
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
{
close();
throw "[PlaYUVerStream] Cannot allocated frame buffer";
return m_bInit;
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
if( !m_ppcFrameBuffer[i] )
{
close();
throw "[PlaYUVerStream] Cannot allocated frame buffer";
return m_bInit;
}
}
}
m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame();
UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame();
if( m_uiStreamHandler == YUV_IO && m_bIsInput )
{
fseek( m_pFile, 0, SEEK_END );
UInt64 fileSize = ftell( m_pFile );
if( m_uiStreamHandler == YUV_IO && m_bIsInput )
{
fseek( m_pFile, 0, SEEK_END );
UInt64 fileSize = ftell( m_pFile );
#if 0
if( fileSize % frame_bytes_input )
{
Int remaining = fileSize % frame_bytes_input;
close();
throw "[PlaYUVerStream] Incorrect configuration: failed ( fileSize % frame_bytes_input = " << remaining << " )";
return m_bInit;
}
if( fileSize % frame_bytes_input )
{
Int remaining = fileSize % frame_bytes_input;
close();
throw "[PlaYUVerStream] Incorrect configuration: failed ( fileSize % frame_bytes_input = " << remaining << " )";
return m_bInit;
}
#endif
m_uiTotalFrameNum = fileSize / frame_bytes_input;
fseek( m_pFile, 0, SEEK_SET );
m_uiTotalFrameNum = fileSize / frame_bytes_input;
fseek( m_pFile, 0, SEEK_SET );
}
}
else
{
m_pcNextFrame = NULL;
m_uiFrameBufferSize = 0;
m_uiFrameBufferIndex = 0;
m_uiTotalFrameNum = 1;
}
if( m_bIsInput && m_uiTotalFrameNum <= 0 )
@@ -512,6 +535,11 @@ Void PlaYUVerStream::readFrame()
return;
}
if( m_uiStreamHandler == OPENCV_HANDLER )
{
return;
}
#ifdef USE_FFMPEG
if( m_uiStreamHandler == FFMPEG )
{
@@ -676,6 +704,10 @@ Bool PlaYUVerStream::seekInput( UInt64 new_frame_num )
setNextFrame();
return true;
}
if( m_uiStreamHandler == OPENCV_HANDLER )
{
return true;
}
#ifdef USE_FFMPEG
if( m_uiStreamHandler == FFMPEG )
{