1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
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.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
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.
26 //
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.
29 //
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.
40 //
41 //M*/
42 
43 #ifndef __OPENCV_SUPERRES_HPP__
44 #define __OPENCV_SUPERRES_HPP__
45 
46 #include "opencv2/core.hpp"
47 #include "opencv2/superres/optical_flow.hpp"
48 
49 /**
50   @defgroup superres Super Resolution
51 
52 The Super Resolution module contains a set of functions and classes that can be used to solve the
53 problem of resolution enhancement. There are a few methods implemented, most of them are descibed in
54 the papers @cite Farsiu03 and @cite Mitzel09 .
55 
56  */
57 
58 namespace cv
59 {
60     namespace superres
61     {
62 
63 //! @addtogroup superres
64 //! @{
65 
66         class CV_EXPORTS FrameSource
67         {
68         public:
69             virtual ~FrameSource();
70 
71             virtual void nextFrame(OutputArray frame) = 0;
72             virtual void reset() = 0;
73         };
74 
75         CV_EXPORTS Ptr<FrameSource> createFrameSource_Empty();
76 
77         CV_EXPORTS Ptr<FrameSource> createFrameSource_Video(const String& fileName);
78         CV_EXPORTS Ptr<FrameSource> createFrameSource_Video_CUDA(const String& fileName);
79 
80         CV_EXPORTS Ptr<FrameSource> createFrameSource_Camera(int deviceId = 0);
81 
82         /** @brief Base class for Super Resolution algorithms.
83 
84         The class is only used to define the common interface for the whole family of Super Resolution
85         algorithms.
86          */
87         class CV_EXPORTS SuperResolution : public cv::Algorithm, public FrameSource
88         {
89         public:
90             /** @brief Set input frame source for Super Resolution algorithm.
91 
92             @param frameSource Input frame source
93              */
94             void setInput(const Ptr<FrameSource>& frameSource);
95 
96             /** @brief Process next frame from input and return output result.
97 
98             @param frame Output result
99              */
100             void nextFrame(OutputArray frame);
101             void reset();
102 
103             /** @brief Clear all inner buffers.
104             */
105             virtual void collectGarbage();
106 
107             //! @brief Scale factor
108             /** @see setScale */
109             virtual int getScale() const = 0;
110             /** @copybrief getScale @see getScale */
111             virtual void setScale(int val) = 0;
112 
113             //! @brief Iterations count
114             /** @see setIterations */
115             virtual int getIterations() const = 0;
116             /** @copybrief getIterations @see getIterations */
117             virtual void setIterations(int val) = 0;
118 
119             //! @brief Asymptotic value of steepest descent method
120             /** @see setTau */
121             virtual double getTau() const = 0;
122             /** @copybrief getTau @see getTau */
123             virtual void setTau(double val) = 0;
124 
125             //! @brief Weight parameter to balance data term and smoothness term
126             /** @see setLabmda */
127             virtual double getLabmda() const = 0;
128             /** @copybrief getLabmda @see getLabmda */
129             virtual void setLabmda(double val) = 0;
130 
131             //! @brief Parameter of spacial distribution in Bilateral-TV
132             /** @see setAlpha */
133             virtual double getAlpha() const = 0;
134             /** @copybrief getAlpha @see getAlpha */
135             virtual void setAlpha(double val) = 0;
136 
137             //! @brief Kernel size of Bilateral-TV filter
138             /** @see setKernelSize */
139             virtual int getKernelSize() const = 0;
140             /** @copybrief getKernelSize @see getKernelSize */
141             virtual void setKernelSize(int val) = 0;
142 
143             //! @brief Gaussian blur kernel size
144             /** @see setBlurKernelSize */
145             virtual int getBlurKernelSize() const = 0;
146             /** @copybrief getBlurKernelSize @see getBlurKernelSize */
147             virtual void setBlurKernelSize(int val) = 0;
148 
149             //! @brief Gaussian blur sigma
150             /** @see setBlurSigma */
151             virtual double getBlurSigma() const = 0;
152             /** @copybrief getBlurSigma @see getBlurSigma */
153             virtual void setBlurSigma(double val) = 0;
154 
155             //! @brief Radius of the temporal search area
156             /** @see setTemporalAreaRadius */
157             virtual int getTemporalAreaRadius() const = 0;
158             /** @copybrief getTemporalAreaRadius @see getTemporalAreaRadius */
159             virtual void setTemporalAreaRadius(int val) = 0;
160 
161             //! @brief Dense optical flow algorithm
162             /** @see setOpticalFlow */
163             virtual Ptr<cv::superres::DenseOpticalFlowExt> getOpticalFlow() const = 0;
164             /** @copybrief getOpticalFlow @see getOpticalFlow */
165             virtual void setOpticalFlow(const Ptr<cv::superres::DenseOpticalFlowExt> &val) = 0;
166 
167         protected:
168             SuperResolution();
169 
170             virtual void initImpl(Ptr<FrameSource>& frameSource) = 0;
171             virtual void processImpl(Ptr<FrameSource>& frameSource, OutputArray output) = 0;
172 
173             bool isUmat_;
174 
175         private:
176             Ptr<FrameSource> frameSource_;
177             bool firstCall_;
178         };
179 
180         /** @brief Create Bilateral TV-L1 Super Resolution.
181 
182         This class implements Super Resolution algorithm described in the papers @cite Farsiu03 and
183         @cite Mitzel09 .
184 
185         Here are important members of the class that control the algorithm, which you can set after
186         constructing the class instance:
187 
188         -   **int scale** Scale factor.
189         -   **int iterations** Iteration count.
190         -   **double tau** Asymptotic value of steepest descent method.
191         -   **double lambda** Weight parameter to balance data term and smoothness term.
192         -   **double alpha** Parameter of spacial distribution in Bilateral-TV.
193         -   **int btvKernelSize** Kernel size of Bilateral-TV filter.
194         -   **int blurKernelSize** Gaussian blur kernel size.
195         -   **double blurSigma** Gaussian blur sigma.
196         -   **int temporalAreaRadius** Radius of the temporal search area.
197         -   **Ptr\<DenseOpticalFlowExt\> opticalFlow** Dense optical flow algorithm.
198          */
199         CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1();
200         CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1_CUDA();
201 
202 //! @} superres
203 
204     }
205 }
206 
207 #endif // __OPENCV_SUPERRES_HPP__
208