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();
122 else if(_frame.kind() == _InputArray::GPU_MAT)
125 arrCopy(frame_, _frame);
127 else if(_frame.kind() == _InputArray::OCL_MAT)
132 arrCopy(frame_, _frame);
137 //should never get here
141 class VideoFrameSource : public CaptureFrameSource
144 VideoFrameSource(const string& fileName);
152 VideoFrameSource::VideoFrameSource(const string& fileName) : fileName_(fileName)
157 void VideoFrameSource::reset()
161 CV_Assert( vc_.isOpened() );
164 class CameraFrameSource : public CaptureFrameSource
167 CameraFrameSource(int deviceId);
175 CameraFrameSource::CameraFrameSource(int deviceId) : deviceId_(deviceId)
180 void CameraFrameSource::reset()
184 CV_Assert( vc_.isOpened() );
188 Ptr<FrameSource> cv::superres::createFrameSource_Video(const string& fileName)
190 return new VideoFrameSource(fileName);
193 Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
195 return new CameraFrameSource(deviceId);
198 #endif // HAVE_OPENCV_HIGHGUI
200 //////////////////////////////////////////////////////
201 // VideoFrameSource_GPU
203 #ifndef HAVE_OPENCV_GPU
205 Ptr<FrameSource> cv::superres::createFrameSource_Video_GPU(const string& fileName)
208 CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");
209 return Ptr<FrameSource>();
212 #else // HAVE_OPENCV_GPU
216 class VideoFrameSource_GPU : public FrameSource
219 VideoFrameSource_GPU(const string& fileName);
221 void nextFrame(OutputArray frame);
226 VideoReader_GPU reader_;
230 VideoFrameSource_GPU::VideoFrameSource_GPU(const string& fileName) : fileName_(fileName)
235 void VideoFrameSource_GPU::nextFrame(OutputArray _frame)
237 if (_frame.kind() == _InputArray::GPU_MAT)
239 bool res = reader_.read(_frame.getGpuMatRef());
245 bool res = reader_.read(frame_);
249 arrCopy(frame_, _frame);
253 void VideoFrameSource_GPU::reset()
256 reader_.open(fileName_);
257 CV_Assert( reader_.isOpened() );
261 Ptr<FrameSource> cv::superres::createFrameSource_Video_GPU(const string& fileName)
263 return new VideoFrameSource(fileName);
266 #endif // HAVE_OPENCV_GPU