1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
42 #include "precomp.hpp"
46 using namespace cv::gpu;
47 using namespace cv::superres;
48 using namespace cv::superres::detail;
50 cv::superres::FrameSource::~FrameSource()
54 //////////////////////////////////////////////////////
59 class EmptyFrameSource : public FrameSource
62 void nextFrame(OutputArray frame);
66 void EmptyFrameSource::nextFrame(OutputArray frame)
71 void EmptyFrameSource::reset()
76 Ptr<FrameSource> cv::superres::createFrameSource_Empty()
78 return new EmptyFrameSource;
81 //////////////////////////////////////////////////////
82 // VideoFrameSource & CameraFrameSource
84 #ifndef HAVE_OPENCV_HIGHGUI
86 Ptr<FrameSource> cv::superres::createFrameSource_Video(const string& fileName)
89 CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");
90 return Ptr<FrameSource>();
93 Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
96 CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");
97 return Ptr<FrameSource>();
100 #else // HAVE_OPENCV_HIGHGUI
104 class CaptureFrameSource : public FrameSource
107 void nextFrame(OutputArray frame);
116 void CaptureFrameSource::nextFrame(OutputArray _frame)
118 if (_frame.kind() == _InputArray::MAT)
120 vc_ >> _frame.getMatRef();
125 arrCopy(frame_, _frame);
129 class VideoFrameSource : public CaptureFrameSource
132 VideoFrameSource(const string& fileName);
140 VideoFrameSource::VideoFrameSource(const string& fileName) : fileName_(fileName)
145 void VideoFrameSource::reset()
149 CV_Assert( vc_.isOpened() );
152 class CameraFrameSource : public CaptureFrameSource
155 CameraFrameSource(int deviceId);
163 CameraFrameSource::CameraFrameSource(int deviceId) : deviceId_(deviceId)
168 void CameraFrameSource::reset()
172 CV_Assert( vc_.isOpened() );
176 Ptr<FrameSource> cv::superres::createFrameSource_Video(const string& fileName)
178 return new VideoFrameSource(fileName);
181 Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
183 return new CameraFrameSource(deviceId);
186 #endif // HAVE_OPENCV_HIGHGUI
188 //////////////////////////////////////////////////////
189 // VideoFrameSource_GPU
191 #ifndef HAVE_OPENCV_GPU
193 Ptr<FrameSource> cv::superres::createFrameSource_Video_GPU(const string& fileName)
196 CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");
197 return Ptr<FrameSource>();
200 #else // HAVE_OPENCV_GPU
204 class VideoFrameSource_GPU : public FrameSource
207 VideoFrameSource_GPU(const string& fileName);
209 void nextFrame(OutputArray frame);
214 VideoReader_GPU reader_;
218 VideoFrameSource_GPU::VideoFrameSource_GPU(const string& fileName) : fileName_(fileName)
223 void VideoFrameSource_GPU::nextFrame(OutputArray _frame)
225 if (_frame.kind() == _InputArray::GPU_MAT)
227 bool res = reader_.read(_frame.getGpuMatRef());
233 bool res = reader_.read(frame_);
237 arrCopy(frame_, _frame);
241 void VideoFrameSource_GPU::reset()
244 reader_.open(fileName_);
245 CV_Assert( reader_.isOpened() );
249 Ptr<FrameSource> cv::superres::createFrameSource_Video_GPU(const string& fileName)
251 return new VideoFrameSource(fileName);
254 #endif // HAVE_OPENCV_GPU