mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 11:40:44 +08:00
added self-contained motion jpeg encoder (filename should end with .avi; fourcc should be "MJPG"
This commit is contained in:
parent
0545aeb11b
commit
3df6b6fdcf
@ -27,6 +27,8 @@ set(videoio_hdrs
|
||||
set(videoio_srcs
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/cap.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/cap_images.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/cap_mjpeg_encoder.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/cap_mjpeg_decoder.cpp
|
||||
)
|
||||
|
||||
file(GLOB videoio_ext_hdrs
|
||||
|
@ -586,10 +586,10 @@ public:
|
||||
protected:
|
||||
Ptr<CvCapture> cap;
|
||||
Ptr<IVideoCapture> icap;
|
||||
private:
|
||||
static Ptr<IVideoCapture> createCameraCapture(int index);
|
||||
};
|
||||
|
||||
class IVideoWriter;
|
||||
|
||||
/** @brief Video writer class.
|
||||
*/
|
||||
class CV_EXPORTS_W VideoWriter
|
||||
@ -651,6 +651,10 @@ public:
|
||||
|
||||
protected:
|
||||
Ptr<CvVideoWriter> writer;
|
||||
Ptr<IVideoWriter> iwriter;
|
||||
|
||||
static Ptr<IVideoWriter> create(const String& filename, int fourcc, double fps,
|
||||
Size frameSize, bool isColor = true);
|
||||
};
|
||||
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const;
|
||||
|
@ -499,6 +499,67 @@ CV_IMPL void cvReleaseVideoWriter( CvVideoWriter** pwriter )
|
||||
namespace cv
|
||||
{
|
||||
|
||||
static Ptr<IVideoCapture> IVideoCapture_create(int index)
|
||||
{
|
||||
int domains[] =
|
||||
{
|
||||
#ifdef HAVE_DSHOW
|
||||
CV_CAP_DSHOW,
|
||||
#endif
|
||||
#ifdef HAVE_INTELPERC
|
||||
CV_CAP_INTELPERC,
|
||||
#endif
|
||||
-1, -1
|
||||
};
|
||||
|
||||
// interpret preferred interface (0 = autodetect)
|
||||
int pref = (index / 100) * 100;
|
||||
if (pref)
|
||||
{
|
||||
domains[0]=pref;
|
||||
index %= 100;
|
||||
domains[1]=-1;
|
||||
}
|
||||
|
||||
// try every possibly installed camera API
|
||||
for (int i = 0; domains[i] >= 0; i++)
|
||||
{
|
||||
#if defined(HAVE_DSHOW) || \
|
||||
defined(HAVE_INTELPERC) || \
|
||||
(0)
|
||||
Ptr<IVideoCapture> capture;
|
||||
|
||||
switch (domains[i])
|
||||
{
|
||||
#ifdef HAVE_DSHOW
|
||||
case CV_CAP_DSHOW:
|
||||
capture = makePtr<VideoCapture_DShow>(index);
|
||||
break; // CV_CAP_DSHOW
|
||||
#endif
|
||||
#ifdef HAVE_INTELPERC
|
||||
case CV_CAP_INTELPERC:
|
||||
capture = makePtr<VideoCapture_IntelPerC>();
|
||||
break; // CV_CAP_INTEL_PERC
|
||||
#endif
|
||||
}
|
||||
if (capture && capture->isOpened())
|
||||
return capture;
|
||||
#endif
|
||||
}
|
||||
|
||||
// failed open a camera
|
||||
return Ptr<IVideoCapture>();
|
||||
}
|
||||
|
||||
|
||||
static Ptr<IVideoWriter> IVideoWriter_create(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
|
||||
{
|
||||
Ptr<IVideoWriter> iwriter;
|
||||
if( _fourcc == CV_FOURCC('M', 'J', 'P', 'G') )
|
||||
iwriter = createMotionJpegWriter(filename, fps, frameSize, isColor);
|
||||
return iwriter;
|
||||
}
|
||||
|
||||
VideoCapture::VideoCapture()
|
||||
{}
|
||||
|
||||
@ -528,7 +589,7 @@ bool VideoCapture::open(const String& filename)
|
||||
bool VideoCapture::open(int device)
|
||||
{
|
||||
if (isOpened()) release();
|
||||
icap = createCameraCapture(device);
|
||||
icap = IVideoCapture_create(device);
|
||||
if (!icap.empty())
|
||||
return true;
|
||||
cap.reset(cvCreateCameraCapture(device));
|
||||
@ -609,59 +670,6 @@ double VideoCapture::get(int propId) const
|
||||
return icvGetCaptureProperty(cap, propId);
|
||||
}
|
||||
|
||||
Ptr<IVideoCapture> VideoCapture::createCameraCapture(int index)
|
||||
{
|
||||
int domains[] =
|
||||
{
|
||||
#ifdef HAVE_DSHOW
|
||||
CV_CAP_DSHOW,
|
||||
#endif
|
||||
#ifdef HAVE_INTELPERC
|
||||
CV_CAP_INTELPERC,
|
||||
#endif
|
||||
-1, -1
|
||||
};
|
||||
|
||||
// interpret preferred interface (0 = autodetect)
|
||||
int pref = (index / 100) * 100;
|
||||
if (pref)
|
||||
{
|
||||
domains[0]=pref;
|
||||
index %= 100;
|
||||
domains[1]=-1;
|
||||
}
|
||||
|
||||
// try every possibly installed camera API
|
||||
for (int i = 0; domains[i] >= 0; i++)
|
||||
{
|
||||
#if defined(HAVE_DSHOW) || \
|
||||
defined(HAVE_INTELPERC) || \
|
||||
(0)
|
||||
Ptr<IVideoCapture> capture;
|
||||
|
||||
switch (domains[i])
|
||||
{
|
||||
#ifdef HAVE_DSHOW
|
||||
case CV_CAP_DSHOW:
|
||||
capture = makePtr<VideoCapture_DShow>(index);
|
||||
if (capture && capture.dynamicCast<VideoCapture_DShow>()->isOpened())
|
||||
return capture;
|
||||
break; // CV_CAP_DSHOW
|
||||
#endif
|
||||
#ifdef HAVE_INTELPERC
|
||||
case CV_CAP_INTELPERC:
|
||||
capture = makePtr<VideoCapture_IntelPerC>();
|
||||
if (capture && capture.dynamicCast<VideoCapture_IntelPerC>()->isOpened())
|
||||
return capture;
|
||||
break; // CV_CAP_INTEL_PERC
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// failed open a camera
|
||||
return Ptr<IVideoCapture>();
|
||||
}
|
||||
|
||||
VideoWriter::VideoWriter()
|
||||
{}
|
||||
@ -673,6 +681,7 @@ VideoWriter::VideoWriter(const String& filename, int _fourcc, double fps, Size f
|
||||
|
||||
void VideoWriter::release()
|
||||
{
|
||||
iwriter.release();
|
||||
writer.release();
|
||||
}
|
||||
|
||||
@ -683,19 +692,28 @@ VideoWriter::~VideoWriter()
|
||||
|
||||
bool VideoWriter::open(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
|
||||
{
|
||||
if (isOpened()) release();
|
||||
iwriter = IVideoWriter_create(filename, _fourcc, fps, frameSize, isColor);
|
||||
if (!iwriter.empty())
|
||||
return true;
|
||||
writer.reset(cvCreateVideoWriter(filename.c_str(), _fourcc, fps, frameSize, isColor));
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
bool VideoWriter::isOpened() const
|
||||
{
|
||||
return !writer.empty();
|
||||
return !iwriter.empty() || !writer.empty();
|
||||
}
|
||||
|
||||
void VideoWriter::write(const Mat& image)
|
||||
{
|
||||
IplImage _img = image;
|
||||
cvWriteFrame(writer, &_img);
|
||||
if( iwriter )
|
||||
iwriter->write(image);
|
||||
else
|
||||
{
|
||||
IplImage _img = image;
|
||||
cvWriteFrame(writer, &_img);
|
||||
}
|
||||
}
|
||||
|
||||
VideoWriter& VideoWriter::operator << (const Mat& image)
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
virtual bool grabFrame();
|
||||
virtual bool retrieveFrame(int outputType, OutputArray frame);
|
||||
virtual int getCaptureDomain();
|
||||
bool isOpened() const;
|
||||
virtual bool isOpened() const;
|
||||
protected:
|
||||
void open(int index);
|
||||
void close();
|
||||
|
@ -100,7 +100,7 @@ public:
|
||||
virtual bool grabFrame();
|
||||
virtual bool retrieveFrame(int outputType, OutputArray frame);
|
||||
virtual int getCaptureDomain();
|
||||
bool isOpened() const;
|
||||
virtual bool isOpened() const;
|
||||
protected:
|
||||
bool m_contextOpened;
|
||||
|
||||
|
52
modules/videoio/src/cap_mjpeg_decoder.cpp
Normal file
52
modules/videoio/src/cap_mjpeg_decoder.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2015, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
Ptr<IVideoCapture> createMotionJpegCapture(const String& filename)
|
||||
{
|
||||
return Ptr<IVideoCapture>();
|
||||
}
|
||||
|
||||
}
|
1443
modules/videoio/src/cap_mjpeg_encoder.cpp
Normal file
1443
modules/videoio/src/cap_mjpeg_encoder.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -168,9 +168,24 @@ namespace cv
|
||||
virtual double getProperty(int) const { return 0; }
|
||||
virtual bool setProperty(int, double) { return 0; }
|
||||
virtual bool grabFrame() = 0;
|
||||
virtual bool retrieveFrame(int, cv::OutputArray) = 0;
|
||||
virtual bool retrieveFrame(int, OutputArray) = 0;
|
||||
virtual bool isOpened() const = 0;
|
||||
virtual int getCaptureDomain() { return CAP_ANY; } // Return the type of the capture object: CAP_VFW, etc...
|
||||
};
|
||||
|
||||
class IVideoWriter
|
||||
{
|
||||
public:
|
||||
virtual ~IVideoWriter() {}
|
||||
virtual double getProperty(int) const { return 0; }
|
||||
virtual bool setProperty(int, double) { return 0; }
|
||||
|
||||
virtual bool isOpened() const = 0;
|
||||
virtual void write(InputArray) = 0;
|
||||
};
|
||||
|
||||
Ptr<IVideoCapture> createMotionJpegCapture(const String& filename);
|
||||
Ptr<IVideoWriter> createMotionJpegWriter( const String& filename, double fps, Size frameSize, bool iscolor );
|
||||
};
|
||||
|
||||
#endif /* __VIDEOIO_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user