2013-02-25 18:33:00 +08:00
|
|
|
/*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) 2000-2008, Intel Corporation, all rights reserved.
|
2013-03-21 17:31:51 +08:00
|
|
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
2013-02-25 18:33:00 +08:00
|
|
|
// 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 the copyright holders 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"
|
|
|
|
|
|
|
|
using namespace cv;
|
2013-08-28 19:45:13 +08:00
|
|
|
using namespace cv::cuda;
|
2013-02-25 18:33:00 +08:00
|
|
|
using namespace cv::superres;
|
|
|
|
using namespace cv::superres::detail;
|
|
|
|
|
|
|
|
cv::superres::FrameSource::~FrameSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// EmptyFrameSource
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2013-09-06 19:44:44 +08:00
|
|
|
return makePtr<EmptyFrameSource>();
|
2013-02-25 18:33:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// VideoFrameSource & CameraFrameSource
|
|
|
|
|
|
|
|
#ifndef HAVE_OPENCV_HIGHGUI
|
|
|
|
|
2013-03-22 23:31:36 +08:00
|
|
|
Ptr<FrameSource> cv::superres::createFrameSource_Video(const String& fileName)
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
|
|
|
(void) fileName;
|
2013-04-17 19:24:53 +08:00
|
|
|
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
|
2013-02-25 18:33:00 +08:00
|
|
|
return Ptr<FrameSource>();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
|
|
|
|
{
|
|
|
|
(void) deviceId;
|
2013-04-17 19:24:53 +08:00
|
|
|
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
|
2013-02-25 18:33:00 +08:00
|
|
|
return Ptr<FrameSource>();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // HAVE_OPENCV_HIGHGUI
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2013-06-26 08:43:23 +08:00
|
|
|
else if(_frame.kind() == _InputArray::GPU_MAT)
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
|
|
|
vc_ >> frame_;
|
|
|
|
arrCopy(frame_, _frame);
|
|
|
|
}
|
2013-06-26 08:43:23 +08:00
|
|
|
else if(_frame.kind() == _InputArray::OCL_MAT)
|
|
|
|
{
|
|
|
|
vc_ >> frame_;
|
|
|
|
if(!frame_.empty())
|
|
|
|
{
|
|
|
|
arrCopy(frame_, _frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//should never get here
|
|
|
|
}
|
2013-02-25 18:33:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class VideoFrameSource : public CaptureFrameSource
|
|
|
|
{
|
|
|
|
public:
|
2013-03-23 00:37:49 +08:00
|
|
|
VideoFrameSource(const String& fileName);
|
2013-02-25 18:33:00 +08:00
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
private:
|
2013-03-23 00:37:49 +08:00
|
|
|
String fileName_;
|
2013-02-25 18:33:00 +08:00
|
|
|
};
|
|
|
|
|
2013-03-23 00:37:49 +08:00
|
|
|
VideoFrameSource::VideoFrameSource(const String& fileName) : fileName_(fileName)
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
|
|
|
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() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-23 00:37:49 +08:00
|
|
|
Ptr<FrameSource> cv::superres::createFrameSource_Video(const String& fileName)
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
2013-09-06 19:44:44 +08:00
|
|
|
return makePtr<VideoFrameSource>(fileName);
|
2013-02-25 18:33:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
|
|
|
|
{
|
2013-09-06 19:44:44 +08:00
|
|
|
return makePtr<CameraFrameSource>(deviceId);
|
2013-02-25 18:33:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAVE_OPENCV_HIGHGUI
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
2013-07-24 17:55:18 +08:00
|
|
|
// VideoFrameSource_CUDA
|
2013-02-25 18:33:00 +08:00
|
|
|
|
2013-07-23 18:29:21 +08:00
|
|
|
#ifndef HAVE_OPENCV_CUDACODEC
|
2013-02-25 18:33:00 +08:00
|
|
|
|
2013-07-24 17:55:18 +08:00
|
|
|
Ptr<FrameSource> cv::superres::createFrameSource_Video_CUDA(const String& fileName)
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
|
|
|
(void) fileName;
|
2013-04-17 19:24:53 +08:00
|
|
|
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
|
2013-02-25 18:33:00 +08:00
|
|
|
return Ptr<FrameSource>();
|
|
|
|
}
|
|
|
|
|
2013-07-23 18:29:21 +08:00
|
|
|
#else // HAVE_OPENCV_CUDACODEC
|
2013-02-25 18:33:00 +08:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2013-07-24 17:55:18 +08:00
|
|
|
class VideoFrameSource_CUDA : public FrameSource
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-24 17:55:18 +08:00
|
|
|
VideoFrameSource_CUDA(const String& fileName);
|
2013-02-25 18:33:00 +08:00
|
|
|
|
|
|
|
void nextFrame(OutputArray frame);
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
private:
|
2013-03-23 00:37:49 +08:00
|
|
|
String fileName_;
|
2013-07-23 16:33:11 +08:00
|
|
|
Ptr<cudacodec::VideoReader> reader_;
|
2013-02-25 18:33:00 +08:00
|
|
|
GpuMat frame_;
|
|
|
|
};
|
|
|
|
|
2013-07-24 17:55:18 +08:00
|
|
|
VideoFrameSource_CUDA::VideoFrameSource_CUDA(const String& fileName) : fileName_(fileName)
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
2013-07-24 17:55:18 +08:00
|
|
|
void VideoFrameSource_CUDA::nextFrame(OutputArray _frame)
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
|
|
|
if (_frame.kind() == _InputArray::GPU_MAT)
|
|
|
|
{
|
2013-06-11 17:05:02 +08:00
|
|
|
bool res = reader_->nextFrame(_frame.getGpuMatRef());
|
2013-02-25 18:33:00 +08:00
|
|
|
if (!res)
|
|
|
|
_frame.release();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-11 17:05:02 +08:00
|
|
|
bool res = reader_->nextFrame(frame_);
|
2013-02-25 18:33:00 +08:00
|
|
|
if (!res)
|
|
|
|
_frame.release();
|
|
|
|
else
|
|
|
|
arrCopy(frame_, _frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 17:55:18 +08:00
|
|
|
void VideoFrameSource_CUDA::reset()
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
2013-07-23 16:33:11 +08:00
|
|
|
reader_ = cudacodec::createVideoReader(fileName_);
|
2013-02-25 18:33:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 17:55:18 +08:00
|
|
|
Ptr<FrameSource> cv::superres::createFrameSource_Video_CUDA(const String& fileName)
|
2013-02-25 18:33:00 +08:00
|
|
|
{
|
2013-09-06 19:44:44 +08:00
|
|
|
return makePtr<VideoFrameSource>(fileName);
|
2013-02-25 18:33:00 +08:00
|
|
|
}
|
|
|
|
|
2013-07-23 18:29:21 +08:00
|
|
|
#endif // HAVE_OPENCV_CUDACODEC
|