Merge branch 'master' into devel
This commit is contained in:
@@ -21,6 +21,11 @@ IF( USE_FFMPEG )
|
||||
LIST( APPEND plaYUver_Lib_SRCS LibAvContextHandle.cpp )
|
||||
ENDIF()
|
||||
|
||||
IF( USE_OPENCV )
|
||||
LIST( APPEND plaYUver_Lib_SRCS LibOpenCVHandler.cpp )
|
||||
ENDIF()
|
||||
|
||||
|
||||
set(plaYUver_Lib_HEADERS
|
||||
PlaYUVerFrame.h
|
||||
PlaYUVerStream.h
|
||||
|
||||
@@ -220,12 +220,12 @@ Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt&
|
||||
m_uiSecs = duration / AV_TIME_BASE;
|
||||
num_frames = m_uiSecs * frame_rate;
|
||||
m_uiMicroSec = duration % AV_TIME_BASE;
|
||||
num_frames = num_frames == 0 ? 1 : num_frames;
|
||||
}
|
||||
else
|
||||
{
|
||||
num_frames = 0;
|
||||
}
|
||||
num_frames = num_frames == 0 ? 1 : num_frames;
|
||||
|
||||
Int pix_fmt = video_dec_ctx->pix_fmt;
|
||||
switch( pix_fmt )
|
||||
@@ -255,6 +255,7 @@ Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt&
|
||||
}
|
||||
if( pixel_format == PlaYUVerFrame::NO_FMT )
|
||||
{
|
||||
throw "Cannot open file using FFmpeg libs - unsupported pixel format";
|
||||
closeAvFormat();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/* This file is a part of plaYUVer project
|
||||
* Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com)
|
||||
* Joao Carreira (jfmcarreira@gmail.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file LibOpenCVHandler.cpp
|
||||
* \brief Interface with opencv lib
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include "LibOpenCVHandler.h"
|
||||
#include "PlaYUVerFrame.h"
|
||||
#include "PlaYUVerFramePixelFormats.h"
|
||||
#include "LibMemory.h"
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
std::vector<std::string> LibOpenCVHandler::supportedReadFormatsExt()
|
||||
{
|
||||
std::vector<std::string> formatsExt;
|
||||
formatsExt.push_back( "pgm" );
|
||||
formatsExt.push_back( "png" );
|
||||
formatsExt.push_back( "bmp" );
|
||||
formatsExt.push_back( "jpg" );
|
||||
return formatsExt;
|
||||
}
|
||||
|
||||
std::vector<std::string> LibOpenCVHandler::supportedReadFormatsName()
|
||||
{
|
||||
std::vector<std::string> formatsName;
|
||||
formatsName.push_back( "Portable Grayscale Map" );
|
||||
formatsName.push_back( "Portable Network Graphics" );
|
||||
formatsName.push_back( "Windows Bitmap" );
|
||||
formatsName.push_back( "Joint Photographic Experts Group" );
|
||||
return formatsName;
|
||||
}
|
||||
|
||||
std::vector<std::string> LibOpenCVHandler::supportedWriteFormatsExt()
|
||||
{
|
||||
std::vector<std::string> formatsExt;
|
||||
return formatsExt;
|
||||
}
|
||||
|
||||
std::vector<std::string> LibOpenCVHandler::supportedWriteFormatsName()
|
||||
{
|
||||
std::vector<std::string> formatsName;
|
||||
return formatsName;
|
||||
}
|
||||
|
||||
std::vector<std::string> LibOpenCVHandler::supportedSaveFormatsExt()
|
||||
{
|
||||
std::vector<std::string> formatsExt;
|
||||
formatsExt.push_back( "bmp" );
|
||||
formatsExt.push_back( "bmp" );
|
||||
formatsExt.push_back( "jpg" );
|
||||
formatsExt.push_back( "png" );
|
||||
return formatsExt;
|
||||
}
|
||||
|
||||
std::vector<std::string> LibOpenCVHandler::supportedSaveFormatsName()
|
||||
{
|
||||
std::vector<std::string> formatsName;
|
||||
formatsName.push_back( "Windows Bitmap" );
|
||||
formatsName.push_back( "Windows Bitmap" );
|
||||
formatsName.push_back( "Joint Photographic Experts Group" );
|
||||
formatsName.push_back( "Portable Network Graphics" );
|
||||
return formatsName;
|
||||
}
|
||||
|
||||
Bool LibOpenCVHandler::loadFrame( PlaYUVerFrame* pcFrame, std::string filename )
|
||||
{
|
||||
cv::Mat pcCvFrame = cv::imread( filename );
|
||||
|
||||
std::string pelFormatName;
|
||||
Int iPelFormat;
|
||||
switch( pcCvFrame.channels() )
|
||||
{
|
||||
case 1:
|
||||
pelFormatName = "GRAY";
|
||||
break;
|
||||
case 4:
|
||||
pelFormatName = "RGB8";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ )
|
||||
{
|
||||
if( PlaYUVerFrame::supportedPixelFormatListNames()[i] == pelFormatName )
|
||||
{
|
||||
iPelFormat = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool LibOpenCVHandler::saveFrame( const PlaYUVerFrame* pcFrame, std::string filename )
|
||||
{
|
||||
|
||||
Int cvType = CV_8UC3;
|
||||
switch( pcFrame->getNumberChannels() )
|
||||
{
|
||||
case 3:
|
||||
cvType = CV_8UC4;
|
||||
break;
|
||||
case 1:
|
||||
cvType = CV_8UC1;
|
||||
break;
|
||||
default:
|
||||
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) );
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy( pcCvFrame.data, pcFrame->getPelBufferYUV()[LUMA][0], pcFrame->getHeight() * pcFrame->getWidth() * sizeof(Pel) );
|
||||
}
|
||||
return cv::imwrite( filename, pcCvFrame );
|
||||
}
|
||||
|
||||
} // NAMESPACE
|
||||
@@ -0,0 +1,63 @@
|
||||
/* This file is a part of plaYUVer project
|
||||
* Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com)
|
||||
* Joao Carreira (jfmcarreira@gmail.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file LibOpenCVHandler.h
|
||||
* \brief Interface with opencv lib
|
||||
*/
|
||||
|
||||
#ifndef __LIBOPENCVHANDLER_H__
|
||||
#define __LIBOPENCVHANDLER_H__
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "PlaYUVerDefs.h"
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
class PlaYUVerFrame;
|
||||
|
||||
class LibOpenCVHandler
|
||||
{
|
||||
public:
|
||||
|
||||
static std::vector<std::string> supportedReadFormatsExt();
|
||||
static std::vector<std::string> supportedReadFormatsName();
|
||||
static std::vector<std::string> supportedWriteFormatsExt();
|
||||
static std::vector<std::string> supportedWriteFormatsName();
|
||||
static std::vector<std::string> supportedSaveFormatsExt();
|
||||
static std::vector<std::string> supportedSaveFormatsName();
|
||||
|
||||
LibOpenCVHandler()
|
||||
{
|
||||
}
|
||||
|
||||
static Bool loadFrame( PlaYUVerFrame* pcFrame, std::string filename );
|
||||
static Bool saveFrame( const PlaYUVerFrame* pcFrame, std::string filename );
|
||||
|
||||
private:
|
||||
std::string m_cFilename;
|
||||
};
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
#endif // __LIBOPENCVHANDLER_H__
|
||||
+7
-13
@@ -32,7 +32,7 @@
|
||||
#include "LibAvContextHandle.h"
|
||||
#endif
|
||||
#ifdef USE_OPENCV
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "LibOpenCVHandler.h"
|
||||
#endif
|
||||
#ifdef USE_PIXFC
|
||||
#include "pixfc-sse.h"
|
||||
@@ -324,25 +324,19 @@ Void PlaYUVerFrame::getCvMat( Void** ppCvFrame )
|
||||
{
|
||||
#ifdef USE_OPENCV
|
||||
Int cvType = CV_8UC3;
|
||||
switch( m_iPixelFormat )
|
||||
switch( m_pcPelFormat->numberChannels )
|
||||
{
|
||||
case YUV420p:
|
||||
case YUV444p:
|
||||
case YUV422p:
|
||||
case YUYV422:
|
||||
cvType = CV_8UC4;
|
||||
break;
|
||||
case GRAY:
|
||||
cvType = CV_8UC1;
|
||||
break;
|
||||
case RGB8:
|
||||
case 3:
|
||||
cvType = CV_8UC3;
|
||||
break;
|
||||
case 1:
|
||||
cvType = CV_8UC1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cv::Mat *pcCvFrame = new cv::Mat( m_uiHeight, m_uiWidth, cvType );
|
||||
if( m_iPixelFormat != GRAY )
|
||||
if( m_pcPelFormat->colorSpace != PlaYUVerFrame::COLOR_GRAY )
|
||||
{
|
||||
fillRGBBuffer();
|
||||
memcpy( pcCvFrame->data, m_pcRGB32, m_uiWidth * m_uiHeight * 4 * sizeof(UChar) );
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public:
|
||||
}
|
||||
Pixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 )
|
||||
{
|
||||
m_iColorSpace = ColorSpace == PlaYUVerFrame::GRAY ? PlaYUVerFrame::COLOR_YUV : ColorSpace;
|
||||
m_iColorSpace = ColorSpace == PlaYUVerFrame::COLOR_GRAY ? PlaYUVerFrame::COLOR_YUV : ColorSpace;
|
||||
PixelComponents[0] = c0;
|
||||
PixelComponents[1] = c1;
|
||||
PixelComponents[2] = c2;
|
||||
|
||||
+28
-13
@@ -31,7 +31,7 @@
|
||||
#include "LibAvContextHandle.h"
|
||||
#endif
|
||||
#ifdef USE_OPENCV
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "LibOpenCVHandler.h"
|
||||
#endif
|
||||
|
||||
namespace plaYUVer
|
||||
@@ -41,8 +41,14 @@ std::vector<std::string> PlaYUVerStream::supportedReadFormatsExt()
|
||||
{
|
||||
std::vector<std::string> formatsExt;
|
||||
formatsExt.push_back( "yuv" );
|
||||
#ifdef USE_FFMPEG
|
||||
std::vector<std::string> libAvFmt = LibAvContextHandle::supportedReadFormatsExt();
|
||||
formatsExt.insert( formatsExt.end(), libAvFmt.begin(), libAvFmt.end() );
|
||||
#endif
|
||||
#ifdef USE_OPENCV
|
||||
std::vector<std::string> opencvFmt = LibOpenCVHandler::supportedReadFormatsExt();
|
||||
formatsExt.insert( formatsExt.end(), opencvFmt.begin(), opencvFmt.end() );
|
||||
#endif
|
||||
return formatsExt;
|
||||
}
|
||||
|
||||
@@ -50,8 +56,14 @@ std::vector<std::string> PlaYUVerStream::supportedReadFormatsName()
|
||||
{
|
||||
std::vector<std::string> formatsName;
|
||||
formatsName.push_back( "Raw video" );
|
||||
#ifdef USE_FFMPEG
|
||||
std::vector<std::string> libAvFmt = LibAvContextHandle::supportedReadFormatsName();
|
||||
formatsName.insert( formatsName.end(), libAvFmt.begin(), libAvFmt.end() );
|
||||
#endif
|
||||
#ifdef USE_OPENCV
|
||||
std::vector<std::string> opencvFmt = LibOpenCVHandler::supportedReadFormatsName();
|
||||
formatsName.insert( formatsName.end(), opencvFmt.begin(), opencvFmt.end() );
|
||||
#endif
|
||||
return formatsName;
|
||||
}
|
||||
|
||||
@@ -74,10 +86,10 @@ std::vector<std::string> PlaYUVerStream::supportedSaveFormatsExt()
|
||||
std::vector<std::string> formatsExt;
|
||||
std::vector<std::string> writeExt = supportedWriteFormatsExt();
|
||||
formatsExt.insert( formatsExt.begin(), writeExt.begin(), writeExt.end() );
|
||||
formatsExt.push_back( "bmp" );
|
||||
formatsExt.push_back( "bmp" );
|
||||
formatsExt.push_back( "jpeg" );
|
||||
formatsExt.push_back( "png" );
|
||||
#ifdef USE_OPENCV
|
||||
std::vector<std::string> opencvFmt = LibOpenCVHandler::supportedSaveFormatsExt();
|
||||
formatsExt.insert( formatsExt.end(), opencvFmt.begin(), opencvFmt.end() );
|
||||
#endif
|
||||
sort( formatsExt.begin(), formatsExt.end() );
|
||||
formatsExt.erase( unique( formatsExt.begin(), formatsExt.end() ), formatsExt.end() );
|
||||
return formatsExt;
|
||||
@@ -88,10 +100,10 @@ std::vector<std::string> PlaYUVerStream::supportedSaveFormatsName()
|
||||
std::vector<std::string> formatsName;
|
||||
std::vector<std::string> writeName = supportedWriteFormatsName();
|
||||
formatsName.insert( formatsName.begin(), writeName.begin(), writeName.end() );
|
||||
formatsName.push_back( "Windows Bitmap" );
|
||||
formatsName.push_back( "Windows Bitmap" );
|
||||
formatsName.push_back( "Joint Photographic Experts Group" );
|
||||
formatsName.push_back( "Portable Network Graphics" );
|
||||
#ifdef USE_OPENCV
|
||||
std::vector<std::string> opencvFmt = LibOpenCVHandler::supportedSaveFormatsName();
|
||||
formatsName.insert( formatsName.end(), opencvFmt.begin(), opencvFmt.end() );
|
||||
#endif
|
||||
sort( formatsName.begin(), formatsName.end() );
|
||||
formatsName.erase( unique( formatsName.begin(), formatsName.end() ), formatsName.end() );
|
||||
return formatsName;
|
||||
@@ -224,6 +236,12 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
{
|
||||
m_uiStreamHandler = YUV_IO;
|
||||
}
|
||||
//#ifdef USE_OPENCV
|
||||
// else if ( m_cFormatName == "png" )
|
||||
// {
|
||||
// m_uiStreamHandler = OPENCV_HANDLER;
|
||||
// }
|
||||
//#endif
|
||||
#ifdef USE_FFMPEG
|
||||
else
|
||||
{
|
||||
@@ -597,11 +615,8 @@ Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *save
|
||||
#ifdef USE_OPENCV
|
||||
else
|
||||
{
|
||||
cv::Mat* image;
|
||||
saveFrame->getCvMat( ( Void** )&image );
|
||||
return cv::imwrite( filename, *image );
|
||||
return LibOpenCVHandler::saveFrame( saveFrame, filename );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace plaYUVer
|
||||
{
|
||||
|
||||
class LibAvContextHandle;
|
||||
class LibOpenCVHandler;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -57,6 +58,7 @@ private:
|
||||
{
|
||||
INVALID_HANDLER = -1,
|
||||
YUV_IO,
|
||||
OPENCV_HANDLER,
|
||||
FFMPEG,
|
||||
TOTAL_HANDLERR
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user