Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/videostab/src/frame_source.cpp
16354 views
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-2011, 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
#include "precomp.hpp"
44
#include "opencv2/videostab/frame_source.hpp"
45
#include "opencv2/videostab/ring_buffer.hpp"
46
47
#include "opencv2/opencv_modules.hpp"
48
#ifdef HAVE_OPENCV_VIDEOIO
49
# include "opencv2/videoio.hpp"
50
#endif
51
52
namespace cv
53
{
54
namespace videostab
55
{
56
57
namespace {
58
59
class VideoFileSourceImpl : public IFrameSource
60
{
61
public:
62
VideoFileSourceImpl(const String &path, bool volatileFrame)
63
: path_(path), volatileFrame_(volatileFrame) { reset(); }
64
65
virtual void reset() CV_OVERRIDE
66
{
67
#ifdef HAVE_OPENCV_VIDEOIO
68
vc.release();
69
vc.open(path_);
70
if (!vc.isOpened())
71
CV_Error(0, "can't open file: " + path_);
72
#else
73
CV_Error(Error::StsNotImplemented, "OpenCV has been compiled without video I/O support");
74
#endif
75
}
76
77
virtual Mat nextFrame() CV_OVERRIDE
78
{
79
Mat frame;
80
#ifdef HAVE_OPENCV_VIDEOIO
81
vc >> frame;
82
#endif
83
return volatileFrame_ ? frame : frame.clone();
84
}
85
86
#ifdef HAVE_OPENCV_VIDEOIO
87
int width() {return static_cast<int>(vc.get(CAP_PROP_FRAME_WIDTH));}
88
int height() {return static_cast<int>(vc.get(CAP_PROP_FRAME_HEIGHT));}
89
int count() {return static_cast<int>(vc.get(CAP_PROP_FRAME_COUNT));}
90
double fps() {return vc.get(CAP_PROP_FPS);}
91
#else
92
int width() {return 0;}
93
int height() {return 0;}
94
int count() {return 0;}
95
double fps() {return 0;}
96
#endif
97
98
private:
99
String path_;
100
bool volatileFrame_;
101
#ifdef HAVE_OPENCV_VIDEOIO
102
VideoCapture vc;
103
#endif
104
};
105
106
}//namespace
107
108
VideoFileSource::VideoFileSource(const String &path, bool volatileFrame)
109
: impl(new VideoFileSourceImpl(path, volatileFrame)) {}
110
111
void VideoFileSource::reset() { impl->reset(); }
112
Mat VideoFileSource::nextFrame() { return impl->nextFrame(); }
113
114
int VideoFileSource::width() { return ((VideoFileSourceImpl*)impl.get())->width(); }
115
int VideoFileSource::height() { return ((VideoFileSourceImpl*)impl.get())->height(); }
116
int VideoFileSource::count() { return ((VideoFileSourceImpl*)impl.get())->count(); }
117
double VideoFileSource::fps() { return ((VideoFileSourceImpl*)impl.get())->fps(); }
118
119
} // namespace videostab
120
} // namespace cv
121
122