ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkOpenCVVideoCapture.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkOpenCVVideoCapture_h
19#define itkOpenCVVideoCapture_h
20
21#include <string>
22
23// Include the required header with OpenCV > 2.X
24#include "opencv2/core/version.hpp"
25#if !defined(CV_VERSION_EPOCH)
26// OpenCV 3.x
27# include "opencv2/videoio.hpp"
28#else
29// OpenCV 2.4.x
30# include "highgui.h"
31#endif
32
33#include "itkVideoStream.h"
34
35namespace itk
36{
37
50template <typename TVideoStream>
51class ITK_TEMPLATE_EXPORT OpenCVVideoCapture : public cv::VideoCapture
52{
53public:
54 using VideoStreamType = TVideoStream;
56 using FrameType = typename VideoStreamType::FrameType;
57 using PixelType = typename FrameType::PixelType;
58 static constexpr unsigned int Dimensions = FrameType::ImageDimension;
61
64
68
70 itkVirtualGetNameOfClassMacro(OpenCVVideoCapture);
71
72 // Open, close functionality
73
75 virtual bool
76 open(const std::string &)
77 {
78 itkExceptionStringMacro("itk::OpenCVVideoCapture::open(filename) -> If you just want to read from a file, use "
79 "cv::VideoCapture since there is nothing to be gained using itk's version.");
80 }
81
82 virtual bool
83 open(int)
84 {
85 itkExceptionStringMacro("itk::OpenCVVideoCapture::open(device) -> If you just want to read from a device, use "
86 "cv::VideoCapture since there is nothing to be gained using itk's version.");
87 }
88
91 virtual bool
92 open(VideoStreamType * videoStream);
93
95 virtual bool
96 isOpened() const
97 {
98 return m_VideoStream == 0;
99 }
100
103 virtual void
105
106 // Frame access
107
109 virtual bool
111
113 virtual bool
114 retrieve(cv::Mat & image, int channel = 0);
115
118 virtual Self &
119 operator>>(cv::Mat & image);
120
122 virtual bool
123 read(cv::Mat & image);
124
125 // Properties
126
128 virtual bool
129 set(int propId, double value);
130
132 virtual double
133 get(int propId);
134
135protected:
138
140 double m_FpS{};
141 int m_FourCC{};
142
143}; // end class VideoCapture
144
145} // end namespace itk
146
147#ifndef ITK_MANUAL_INSTANTIATION
148# include "itkOpenCVVideoCapture.hxx"
149#endif
150
151#endif
virtual bool isOpened() const
virtual bool retrieve(cv::Mat &image, int channel=0)
virtual bool open(VideoStreamType *videoStream)
OpenCVVideoCapture(VideoStreamType *videoStream)
virtual bool read(cv::Mat &image)
virtual double get(int propId)
virtual bool open(const std::string &)
virtual void release()
virtual bool set(int propId, double value)
typename VideoStreamType::FrameType FrameType
virtual Self & operator>>(cv::Mat &image)
OpenCVVideoCapture< VideoStreamType > Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....