This source file includes following definitions.
- nextFrame
- reset
- createFrameSource_Empty
- createFrameSource_Video
- createFrameSource_Camera
- nextFrame
- reset
- reset
- createFrameSource_Video
- createFrameSource_Camera
- createFrameSource_Video_CUDA
- nextFrame
- reset
- createFrameSource_Video_CUDA
#include "precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::superres;
using namespace cv::superres::detail;
cv::superres::FrameSource::~FrameSource()
{
}
namespace
{
class EmptyFrameSource : public FrameSource
{
public:
void nextFrame(OutputArray frame);
void reset();
};
void EmptyFrameSource::nextFrame(OutputArray frame)
{
frame.release();
}
void EmptyFrameSource::reset()
{
}
}
Ptr<FrameSource> cv::superres::createFrameSource_Empty()
{
return makePtr<EmptyFrameSource>();
}
#ifndef HAVE_OPENCV_VIDEOIO
Ptr<FrameSource> cv::superres::createFrameSource_Video(const String& fileName)
{
(void) fileName;
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<FrameSource>();
}
Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
{
(void) deviceId;
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<FrameSource>();
}
#else
namespace
{
class CaptureFrameSource : public FrameSource
{
public:
void nextFrame(OutputArray frame);
protected:
VideoCapture vc_;
private:
Mat frame_;
};
void CaptureFrameSource::nextFrame(OutputArray _frame)
{
if (_frame.kind() == _InputArray::MAT)
vc_ >> _frame.getMatRef();
else if(_frame.kind() == _InputArray::CUDA_GPU_MAT)
{
vc_ >> frame_;
arrCopy(frame_, _frame);
}
else if (_frame.isUMat())
vc_ >> *(UMat *)_frame.getObj();
else
{
CV_Error(Error::StsBadArg, "Failed to detect input frame kind" );
}
}
class VideoFrameSource : public CaptureFrameSource
{
public:
VideoFrameSource(const String& fileName);
void reset();
private:
String fileName_;
};
VideoFrameSource::VideoFrameSource(const String& fileName) : fileName_(fileName)
{
reset();
}
void VideoFrameSource::reset()
{
vc_.release();
vc_.open(fileName_);
CV_Assert( vc_.isOpened() );
}
class CameraFrameSource : public CaptureFrameSource
{
public:
CameraFrameSource(int deviceId);
void reset();
private:
int deviceId_;
};
CameraFrameSource::CameraFrameSource(int deviceId) : deviceId_(deviceId)
{
reset();
}
void CameraFrameSource::reset()
{
vc_.release();
vc_.open(deviceId_);
CV_Assert( vc_.isOpened() );
}
}
Ptr<FrameSource> cv::superres::createFrameSource_Video(const String& fileName)
{
return makePtr<VideoFrameSource>(fileName);
}
Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
{
return makePtr<CameraFrameSource>(deviceId);
}
#endif
#ifndef HAVE_OPENCV_CUDACODEC
Ptr<FrameSource> cv::superres::createFrameSource_Video_CUDA(const String& fileName)
{
(void) fileName;
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<FrameSource>();
}
#else
namespace
{
class VideoFrameSource_CUDA : public FrameSource
{
public:
VideoFrameSource_CUDA(const String& fileName);
void nextFrame(OutputArray frame);
void reset();
private:
String fileName_;
Ptr<cudacodec::VideoReader> reader_;
GpuMat frame_;
};
VideoFrameSource_CUDA::VideoFrameSource_CUDA(const String& fileName) : fileName_(fileName)
{
reset();
}
void VideoFrameSource_CUDA::nextFrame(OutputArray _frame)
{
if (_frame.kind() == _InputArray::CUDA_GPU_MAT)
{
bool res = reader_->nextFrame(_frame.getGpuMatRef());
if (!res)
_frame.release();
}
else
{
bool res = reader_->nextFrame(frame_);
if (!res)
_frame.release();
else
arrCopy(frame_, _frame);
}
}
void VideoFrameSource_CUDA::reset()
{
reader_ = cudacodec::createVideoReader(fileName_);
}
}
Ptr<FrameSource> cv::superres::createFrameSource_Video_CUDA(const String& fileName)
{
return makePtr<VideoFrameSource_CUDA>(fileName);
}
#endif