From 2bd2e2ce957faa5a5579ad46e820b3e4e10cc941 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 6 Mar 2015 00:52:30 +0000 Subject: [PATCH] Fix save image with opencv problems --- lib/LibOpenCVHandler.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/LibOpenCVHandler.cpp b/lib/LibOpenCVHandler.cpp index 7d2aa6e..18256b4 100644 --- a/lib/LibOpenCVHandler.cpp +++ b/lib/LibOpenCVHandler.cpp @@ -125,7 +125,7 @@ Bool LibOpenCVHandler::saveFrame( PlaYUVerFrame* pcFrame, std::string filename ) switch( pcFrame->getNumberChannels() ) { case 3: - cvType = CV_8UC4; + cvType = CV_8UC3; break; case 1: cvType = CV_8UC1; @@ -134,10 +134,20 @@ Bool LibOpenCVHandler::saveFrame( PlaYUVerFrame* pcFrame, std::string filename ) return false; break; } + cv::Mat pcCvFrame( pcFrame->getHeight(), pcFrame->getWidth(), cvType ); + if( pcFrame->getColorSpace() != PlaYUVerFrame::COLOR_GRAY ) { - memcpy( pcCvFrame.data, pcFrame->getRGBBuffer(), pcFrame->getHeight() * pcFrame->getWidth() * 4 * sizeof(UChar) ); + UChar* pCvPel = pcCvFrame.data; + UChar* pARGB = pcFrame->getRGBBuffer(); + for( UInt i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ ) + { + *pCvPel++ = *pARGB++; + *pCvPel++ = *pARGB++; + *pCvPel++ = *pARGB++; + pARGB++; + } } else {