Increase support for opencv
Add support for read and write streams Include device support
This commit is contained in:
1 parent
85d93780b6
commit
f3590dff48
8 files changed
+123
-36
No files matched your search
@@ -436,6 +436,11 @@ Bool VideoSubWindow::guessFormat( QString filename, UInt& rWidth, UInt& rHeight,
|
||||
Bool bGuessedByFilesize = false;
|
||||
QString FilenameShort = QFileInfo( filename ).fileName();
|
||||
QString fileExtension = QFileInfo( filename ).suffix();
|
||||
|
||||
if( filename.startsWith( "/dev/" ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !fileExtension.compare( "yuv" ) )
|
||||
{
|
||||
bGuessed = false;
|
||||
|
||||
+29
-18
@@ -71,6 +71,16 @@ std::vector<std::string> PlaYUVerFrame::supportedPixelFormatListNames( Int color
|
||||
return formatsList;
|
||||
}
|
||||
|
||||
Int PlaYUVerFrame::findPixelFormat( std::string name )
|
||||
{
|
||||
for( Int i = 0; i < PLAYUVER_NUMBER_FORMATS; i++ )
|
||||
{
|
||||
if( g_PlaYUVerPixFmtDescriptorsList[i].name == name )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pelFormat, Int bitsPixel, Int endianness )
|
||||
{
|
||||
init( width, height, pelFormat, bitsPixel, endianness );
|
||||
@@ -967,23 +977,22 @@ cv::Mat* PlaYUVerFrame::getCvMat( Bool convertToGray )
|
||||
Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame )
|
||||
{
|
||||
#ifdef USE_OPENCV
|
||||
if( m_iPixelFormat == NO_FMT )
|
||||
{
|
||||
switch( pcCvFrame->channels() )
|
||||
{
|
||||
case 1:
|
||||
m_iPixelFormat = GRAY;
|
||||
break;
|
||||
case 3:
|
||||
m_iPixelFormat = RGB24;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( !m_bInit )
|
||||
{
|
||||
if( m_iPixelFormat == NO_FMT )
|
||||
{
|
||||
switch( pcCvFrame->channels() )
|
||||
{
|
||||
case 1:
|
||||
m_iPixelFormat = findPixelFormat( "GRAY" );
|
||||
break;
|
||||
case 3:
|
||||
m_iPixelFormat = findPixelFormat( "BGR24" );
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
init( pcCvFrame->cols, pcCvFrame->rows, m_iPixelFormat, 8, -1 );
|
||||
}
|
||||
|
||||
@@ -998,9 +1007,11 @@ Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame )
|
||||
Pel* pInputPelB = m_pppcInputPel[COLOR_B][0];
|
||||
for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ )
|
||||
{
|
||||
*pInputPelR++ = pelRed( *pCvPel++ );
|
||||
*pInputPelG++ = pelGreen( *pCvPel++ );
|
||||
*pInputPelB++ = pelBlue( *pCvPel++ );
|
||||
*pInputPelB++ = *pCvPel++;
|
||||
*pInputPelG++ = *pCvPel++;
|
||||
*pInputPelR++ = *pCvPel++;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
*/
|
||||
static std::vector<std::string> supportedPixelFormatListNames();
|
||||
static std::vector<std::string> supportedPixelFormatListNames( Int colorSpace );
|
||||
static Int findPixelFormat( std::string name );
|
||||
|
||||
/**
|
||||
* Get number of bytes per frame of a specific
|
||||
|
||||
@@ -295,7 +295,7 @@ PlaYUVerPixFmtDescriptor RGB24 =
|
||||
|
||||
PlaYUVerPixFmtDescriptor BGR24 =
|
||||
{
|
||||
"BRG24",
|
||||
"BGR24",
|
||||
PlaYUVerPixel::COLOR_RGB,
|
||||
3,
|
||||
1,
|
||||
|
||||
@@ -53,9 +53,9 @@ std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedReadFormats()
|
||||
#ifdef USE_FFMPEG
|
||||
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Read );
|
||||
#endif
|
||||
//#ifdef USE_OPENCV
|
||||
// APPEND_PLAYUVER_SUPPORTED_FMT( LibOpenCVHandler );
|
||||
//#endif
|
||||
#ifdef USE_OPENCV
|
||||
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Read );
|
||||
#endif
|
||||
END_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedWriteFormats()
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &PlaYUVerRawHandler::Create, "Raw Video", "yuv" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable BitMap ", "pbm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable GrayMap ", "pgm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable PixMap ", "ppm" );
|
||||
#ifdef USE_FFMPEG
|
||||
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Write );
|
||||
#endif
|
||||
@@ -118,7 +117,11 @@ CreateStreamHandlerFn PlaYUVerStream::findStreamHandler( std::string strFilename
|
||||
}
|
||||
for( UInt i = 0; i < supportedFmts.size(); i++ )
|
||||
{
|
||||
if( supportedFmts[i].formatExt == currExt )
|
||||
if( currExt != "" && supportedFmts[i].formatExt == currExt )
|
||||
{
|
||||
return supportedFmts[i].formatFct;
|
||||
}
|
||||
else if( strFilename.find( supportedFmts[i].formatExt ) != std::string::npos )
|
||||
{
|
||||
return supportedFmts[i].formatFct;
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ namespace plaYUVer
|
||||
std::vector<PlaYUVerSupportedFormat> StreamHandlerLibav::supportedReadFormats()
|
||||
{
|
||||
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Portable Grayscale Map", "pgm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Portable Network Graphics", "png" );
|
||||
// REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Portable Network Graphics", "png" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Joint Photographic Experts Group", "jpg" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Windows Bitmap", "bmp" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Audio video interleaved", "avi" );
|
||||
|
||||
@@ -29,15 +29,16 @@
|
||||
#include "PlaYUVerFramePixelFormats.h"
|
||||
#include "LibMemory.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
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, "Joint Photographic Experts Group", "jpg" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Windows Bitmap", "bmp" );
|
||||
// REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Portable Network Graphics", "png" );
|
||||
// REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Device", "/dev/" );
|
||||
END_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
}
|
||||
|
||||
@@ -45,19 +46,64 @@ 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, "Joint Photographic Experts Group", "jpg" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Windows Bitmap", "bmp" );
|
||||
END_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
}
|
||||
|
||||
StreamHandlerOpenCV::StreamHandlerOpenCV()
|
||||
{
|
||||
pcMat = NULL;
|
||||
pcVideoCapture = NULL;
|
||||
}
|
||||
|
||||
Bool StreamHandlerOpenCV::openHandler( std::string strFilename, Bool bInput )
|
||||
{
|
||||
m_cFilename = strFilename;
|
||||
m_dFrameRate = 1;
|
||||
if( bInput )
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* Special filename to handle webcam input
|
||||
*/
|
||||
if( m_cFilename.find( "/dev/video" ) != std::string::npos )
|
||||
{
|
||||
m_strFormatName = "DEV";
|
||||
m_strCodecName = "Raw Video";
|
||||
pcVideoCapture = new VideoCapture( 0 );
|
||||
m_uiWidth = pcVideoCapture->get( CV_CAP_PROP_FRAME_WIDTH );
|
||||
m_uiHeight = pcVideoCapture->get( CV_CAP_PROP_FRAME_HEIGHT );
|
||||
m_dFrameRate = 25;
|
||||
}
|
||||
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;
|
||||
m_dFrameRate = 1;
|
||||
}
|
||||
m_uiBitsPerPixel = 8;
|
||||
m_iPixelFormat = PlaYUVerFrame::findPixelFormat( "BGR24" );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Void StreamHandlerOpenCV::closeHandler()
|
||||
{
|
||||
|
||||
if( pcVideoCapture )
|
||||
{
|
||||
pcVideoCapture->release();
|
||||
delete pcVideoCapture;
|
||||
pcVideoCapture = NULL;
|
||||
}
|
||||
if( pcMat )
|
||||
{
|
||||
delete pcMat;
|
||||
}
|
||||
}
|
||||
|
||||
Bool StreamHandlerOpenCV::configureBuffer( PlaYUVerFrame* pcFrame )
|
||||
@@ -67,6 +113,10 @@ Bool StreamHandlerOpenCV::configureBuffer( PlaYUVerFrame* pcFrame )
|
||||
|
||||
UInt64 StreamHandlerOpenCV::calculateFrameNumber()
|
||||
{
|
||||
if( pcVideoCapture )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -77,7 +127,20 @@ Bool StreamHandlerOpenCV::seek( UInt64 iFrameNum )
|
||||
|
||||
Bool StreamHandlerOpenCV::read( PlaYUVerFrame* pcFrame )
|
||||
{
|
||||
return false;
|
||||
Bool bRet = false;
|
||||
if( pcVideoCapture )
|
||||
{
|
||||
Mat cvMat;
|
||||
bRet = pcVideoCapture->read( cvMat );
|
||||
if( bRet )
|
||||
pcFrame->fromCvMat( &cvMat );
|
||||
}
|
||||
if( pcMat )
|
||||
{
|
||||
pcFrame->fromCvMat( pcMat );
|
||||
bRet = true;
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
Bool StreamHandlerOpenCV::write( PlaYUVerFrame* pcFrame )
|
||||
|
||||
@@ -31,9 +31,13 @@
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "PlaYUVerDefs.h"
|
||||
#include "PlaYUVerStream.h"
|
||||
#include "PlaYUVerStreamHandlerIf.h"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
class VideoCapture;
|
||||
}
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
@@ -48,9 +52,7 @@ public:
|
||||
static std::vector<PlaYUVerSupportedFormat> supportedReadFormats();
|
||||
static std::vector<PlaYUVerSupportedFormat> supportedWriteFormats();
|
||||
|
||||
StreamHandlerOpenCV()
|
||||
{
|
||||
}
|
||||
StreamHandlerOpenCV();
|
||||
~StreamHandlerOpenCV()
|
||||
{
|
||||
}
|
||||
@@ -63,6 +65,9 @@ public:
|
||||
Bool read( PlaYUVerFrame* pcFrame );
|
||||
Bool write( PlaYUVerFrame* pcFrame );
|
||||
|
||||
private:
|
||||
cv::VideoCapture* pcVideoCapture;
|
||||
cv::Mat* pcMat;
|
||||
};
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
Reference in new issue
Block a user