Change interface with opencv in PlaYUVerFrame
Replace pointers with references
This commit is contained in:
1 parent
1804a78523
commit
8e48120057
6 files changed
+49
-54
No files matched your search
+18
-17
@@ -1039,16 +1039,17 @@ Double PlaYUVerFrame::getMaximum( Int channel )
|
||||
**************************************************************
|
||||
*/
|
||||
|
||||
cv::Mat* PlaYUVerFrame::getCvMat( Bool convertToGray )
|
||||
Bool PlaYUVerFrame::toMat( cv::Mat& cvMat, Bool convertToGray )
|
||||
{
|
||||
Bool bRet = false;
|
||||
#ifdef USE_OPENCV
|
||||
if( convertToGray && !( d->m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_YUV || d->m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_GRAY ) )
|
||||
{
|
||||
return NULL;
|
||||
return bRet;
|
||||
}
|
||||
Int cvType = CV_MAKETYPE( CV_8U, convertToGray ? 1 : d->m_pcPelFormat->numberChannels );
|
||||
cv::Mat *pcCvFrame = new cv::Mat( d->m_uiHeight, d->m_uiWidth, cvType );
|
||||
UChar* pCvPel = pcCvFrame->data;
|
||||
cvMat.create( d->m_uiHeight, d->m_uiWidth, cvType );
|
||||
UChar* pCvPel = cvMat.data;
|
||||
if( !convertToGray && ( d->m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_YUV || d->m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_RGB ) )
|
||||
{
|
||||
fillRGBBuffer();
|
||||
@@ -1060,6 +1061,7 @@ cv::Mat* PlaYUVerFrame::getCvMat( Bool convertToGray )
|
||||
*pCvPel++ = *pARGB++;
|
||||
pARGB++;
|
||||
}
|
||||
bRet = true;
|
||||
}
|
||||
else if( convertToGray || d->m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_GRAY )
|
||||
{
|
||||
@@ -1068,27 +1070,25 @@ cv::Mat* PlaYUVerFrame::getCvMat( Bool convertToGray )
|
||||
{
|
||||
*pCvPel++ = *pPel++;
|
||||
}
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( pcCvFrame )
|
||||
delete pcCvFrame;
|
||||
pcCvFrame = NULL;
|
||||
return false;
|
||||
}
|
||||
return pcCvFrame;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
return bRet;
|
||||
}
|
||||
|
||||
Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame )
|
||||
Bool PlaYUVerFrame::fromMat( cv::Mat& cvMat )
|
||||
{
|
||||
Bool bRet = false;
|
||||
#ifdef USE_OPENCV
|
||||
if( !d->m_bInit )
|
||||
{
|
||||
if( d->m_iPixelFormat == NO_FMT )
|
||||
{
|
||||
switch( pcCvFrame->channels() )
|
||||
switch( cvMat.channels() )
|
||||
{
|
||||
case 1:
|
||||
d->m_iPixelFormat = findPixelFormat( "GRAY" );
|
||||
@@ -1097,16 +1097,16 @@ Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame )
|
||||
d->m_iPixelFormat = findPixelFormat( "BGR24" );
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
d->init( pcCvFrame->cols, pcCvFrame->rows, d->m_iPixelFormat, 8, -1 );
|
||||
d->init( cvMat.cols, cvMat.rows, d->m_iPixelFormat, 8, -1 );
|
||||
}
|
||||
|
||||
d->m_bHasRGBPel = false;
|
||||
d->m_bHasHistogram = false;
|
||||
|
||||
UChar* pCvPel = pcCvFrame->data;
|
||||
UChar* pCvPel = cvMat.data;
|
||||
if( d->m_iPixelFormat != GRAY )
|
||||
{
|
||||
Pel* pInputPelR = d->m_pppcInputPel[COLOR_R][0];
|
||||
@@ -1117,9 +1117,8 @@ Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame )
|
||||
*pInputPelB++ = *pCvPel++;
|
||||
*pInputPelG++ = *pCvPel++;
|
||||
*pInputPelR++ = *pCvPel++;
|
||||
|
||||
|
||||
}
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1128,8 +1127,10 @@ Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame )
|
||||
{
|
||||
*pPel++ = *pCvPel++;
|
||||
}
|
||||
bRet = true;
|
||||
}
|
||||
#endif
|
||||
return bRet;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+2
-2
@@ -232,8 +232,8 @@ public:
|
||||
/**
|
||||
* Interface with OpenCV lib
|
||||
*/
|
||||
cv::Mat* getCvMat( Bool convertToGray = false );
|
||||
Void fromCvMat( cv::Mat* );
|
||||
Bool toMat( cv::Mat& cvMat, Bool convertToGray = false );
|
||||
Bool fromMat( cv::Mat& cvMat );
|
||||
|
||||
/**
|
||||
* @defgroup PlaYUVerLib_QualityMetrics Quality Metrics Interface
|
||||
|
||||
+13
-20
@@ -36,7 +36,7 @@ using cv::VideoCapture;
|
||||
std::vector<PlaYUVerSupportedFormat> StreamHandlerOpenCV::supportedReadFormats()
|
||||
{
|
||||
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
// REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Portable Network Graphics", "png" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Portable Network Graphics", "png" );
|
||||
// REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Device", "/dev/" );
|
||||
END_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
}
|
||||
@@ -44,8 +44,8 @@ std::vector<PlaYUVerSupportedFormat> StreamHandlerOpenCV::supportedReadFormats()
|
||||
std::vector<PlaYUVerSupportedFormat> StreamHandlerOpenCV::supportedWriteFormats()
|
||||
{
|
||||
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Read );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Portable PixMap ", "ppm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Portable Network Graphics", "png" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Joint Photographic Experts Group", "jpg" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Windows Bitmap", "bmp" );
|
||||
END_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
@@ -53,7 +53,6 @@ std::vector<PlaYUVerSupportedFormat> StreamHandlerOpenCV::supportedWriteFormats(
|
||||
|
||||
StreamHandlerOpenCV::StreamHandlerOpenCV()
|
||||
{
|
||||
pcMat = NULL;
|
||||
pcVideoCapture = NULL;
|
||||
}
|
||||
|
||||
@@ -62,8 +61,6 @@ Bool StreamHandlerOpenCV::openHandler( String strFilename, Bool bInput )
|
||||
m_cFilename = strFilename;
|
||||
if( bInput )
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* Special filename to handle webcam input
|
||||
*/
|
||||
@@ -79,9 +76,9 @@ Bool StreamHandlerOpenCV::openHandler( String strFilename, Bool bInput )
|
||||
else
|
||||
{
|
||||
m_strCodecName = m_strFormatName = uppercase (strFilename.substr( strFilename.find_last_of( "." ) + 1 ) );
|
||||
pcMat = new Mat( cv::imread( m_cFilename ) );
|
||||
m_uiWidth = pcMat->cols;
|
||||
m_uiHeight = pcMat->rows;
|
||||
Mat cvMat = cv::imread( m_cFilename );
|
||||
m_uiWidth = cvMat.cols;
|
||||
m_uiHeight = cvMat.rows;
|
||||
m_dFrameRate = 1;
|
||||
}
|
||||
m_uiBitsPerPixel = 8;
|
||||
@@ -99,10 +96,6 @@ Void StreamHandlerOpenCV::closeHandler()
|
||||
delete pcVideoCapture;
|
||||
pcVideoCapture = NULL;
|
||||
}
|
||||
if( pcMat )
|
||||
{
|
||||
delete pcMat;
|
||||
}
|
||||
}
|
||||
|
||||
Bool StreamHandlerOpenCV::configureBuffer( PlaYUVerFrame* pcFrame )
|
||||
@@ -132,12 +125,12 @@ Bool StreamHandlerOpenCV::read( PlaYUVerFrame* pcFrame )
|
||||
Mat cvMat;
|
||||
bRet = pcVideoCapture->read( cvMat );
|
||||
if( bRet )
|
||||
pcFrame->fromCvMat( &cvMat );
|
||||
bRet = pcFrame->fromMat( cvMat );
|
||||
}
|
||||
if( pcMat )
|
||||
else
|
||||
{
|
||||
pcFrame->fromCvMat( pcMat );
|
||||
bRet = true;
|
||||
Mat cvMat = cv::imread( m_cFilename );
|
||||
bRet = pcFrame->fromMat( cvMat );
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
@@ -145,11 +138,11 @@ Bool StreamHandlerOpenCV::read( PlaYUVerFrame* pcFrame )
|
||||
Bool StreamHandlerOpenCV::write( PlaYUVerFrame* pcFrame )
|
||||
{
|
||||
Bool bRet = false;
|
||||
cv::Mat* pcCvFrame = pcFrame->getCvMat();
|
||||
if( pcCvFrame )
|
||||
Mat cvFrame;
|
||||
bRet = pcFrame->toMat( cvFrame );
|
||||
if( bRet )
|
||||
{
|
||||
bRet = cv::imwrite( m_cFilename, *pcCvFrame );
|
||||
delete pcCvFrame;
|
||||
bRet = cv::imwrite( m_cFilename, cvFrame );
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ public:
|
||||
|
||||
private:
|
||||
cv::VideoCapture* pcVideoCapture;
|
||||
cv::Mat* pcMat;
|
||||
};
|
||||
|
||||
#endif // __STREAMHANDLEROPENCV_H__
|
||||
Reference in new issue
Block a user