Fix opencv conversion problems in PlaYUVerFrame
This commit is contained in:
1 parent
e271fe5022
commit
76a216bd3a
7 files changed
+69
-116
No files matched your search
@@ -76,79 +76,13 @@ std::vector<std::string> LibOpenCVHandler::supportedSaveFormatsName()
|
||||
|
||||
PlaYUVerFrame* LibOpenCVHandler::loadFrame( std::string filename )
|
||||
{
|
||||
cv::Mat pcCvFrame = cv::imread( filename );
|
||||
Int cvChannels = pcCvFrame.channels();
|
||||
std::string pelFormatName;
|
||||
Int iPelFormat = -1;
|
||||
switch( cvChannels )
|
||||
{
|
||||
case 1:
|
||||
pelFormatName = "GRAY";
|
||||
break;
|
||||
case 3:
|
||||
pelFormatName = "BRG24";
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ )
|
||||
{
|
||||
if( PlaYUVerFrame::supportedPixelFormatListNames()[i] == pelFormatName )
|
||||
{
|
||||
iPelFormat = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( iPelFormat >= 0 )
|
||||
{
|
||||
PlaYUVerFrame* pcFrame = new PlaYUVerFrame( pcCvFrame.cols, pcCvFrame.rows, iPelFormat );
|
||||
pcFrame->frameFromBuffer( pcCvFrame.ptr(), pcFrame->getBytesPerFrame() );
|
||||
return pcFrame;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Bool LibOpenCVHandler::saveFrame( PlaYUVerFrame* pcFrame, std::string filename )
|
||||
{
|
||||
Int cvType = CV_8UC3;
|
||||
switch( pcFrame->getNumberChannels() )
|
||||
{
|
||||
case 3:
|
||||
cvType = CV_8UC3;
|
||||
break;
|
||||
case 1:
|
||||
cvType = CV_8UC1;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
cv::Mat pcCvFrame( pcFrame->getHeight(), pcFrame->getWidth(), cvType );
|
||||
UChar* pCvPel = pcCvFrame.data;
|
||||
if( pcFrame->getColorSpace() != PlaYUVerFrame::COLOR_GRAY )
|
||||
{
|
||||
UChar* pARGB = pcFrame->getRGBBuffer();
|
||||
for( UInt i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ )
|
||||
{
|
||||
*pCvPel++ = *pARGB++;
|
||||
*pCvPel++ = *pARGB++;
|
||||
*pCvPel++ = *pARGB++;
|
||||
pARGB++;
|
||||
}
|
||||
}
|
||||
if( pcFrame->getColorSpace() == PlaYUVerFrame::COLOR_GRAY )
|
||||
{
|
||||
|
||||
Pel* pPel = pcFrame->getPelBufferYUV()[LUMA][0];
|
||||
for( UInt i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ )
|
||||
{
|
||||
*pCvPel++ = *pPel++;
|
||||
}
|
||||
}
|
||||
return cv::imwrite( filename, pcCvFrame );
|
||||
cv::Mat* pcCvFrame = pcFrame->getCvMat();
|
||||
return cv::imwrite( filename, *pcCvFrame );
|
||||
}
|
||||
|
||||
} // NAMESPACE
|
||||
Reference in new issue
Block a user