ITK  5.2.0
Insight Toolkit
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  * http://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 
35 namespace itk
36 {
37 
50 template <typename TVideoStream>
51 class ITK_TEMPLATE_EXPORT OpenCVVideoCapture : public cv::VideoCapture
52 {
53 public:
54 
58  using VideoStreamType = TVideoStream;
60  using FrameType = typename VideoStreamType::FrameType;
61  using PixelType = typename FrameType::PixelType;
62  static constexpr unsigned int Dimensions = FrameType::ImageDimension;
63 
66 
68  OpenCVVideoCapture(VideoStreamType * videoStream);
69 
72  virtual ~OpenCVVideoCapture() {}
73 
75  itkTypeMacroNoParent(OpenCVVideoCapture);
76 
80  virtual bool
81  open(const std::string &)
82  {
83  itkExceptionMacro("itk::OpenCVVideoCapture::open(filename) -> If you just want "
84  "to read from a file, use cv::VideoCapture since there is nothing to be "
85  "gained using itk's version.");
86  }
87 
88  virtual bool
89  open(int)
90  {
91  itkExceptionMacro("itk::OpenCVVideoCapture::open(device) -> If you just want "
92  "to read from a device, use cv::VideoCapture since there is nothing to be "
93  "gained using itk's version.");
94  }
95 
98  virtual bool
99  open(VideoStreamType * videoStream);
100 
102  virtual bool
103  isOpened() const
104  {
105  return m_VideoStream == 0;
106  }
107 
110  virtual void
111  release();
112 
116  virtual bool
117  grab();
118 
120  virtual bool
121  retrieve(cv::Mat & image, int channel = 0);
122 
125  virtual Self &
126  operator>>(cv::Mat & image);
127 
129  virtual bool
130  read(cv::Mat & image);
131 
135  virtual bool
136  set(int propId, double value);
137 
139  virtual double
140  get(int propId);
141 
142 protected:
145 
147  double m_FpS;
148  int m_FourCC;
149 
150 }; // end class VideoCapture
151 
152 } // end namespace itk
153 
154 #ifndef ITK_MANUAL_INSTANTIATION
155 # include "itkOpenCVVideoCapture.hxx"
156 #endif
157 
158 #endif
itk::OpenCVVideoCapture::VideoStreamType
TVideoStream VideoStreamType
Definition: itkOpenCVVideoCapture.h:58
itkVideoStream.h
itk::OpenCVVideoCapture::open
virtual bool open(const std::string &)
Definition: itkOpenCVVideoCapture.h:81
itk::OpenCVVideoCapture::m_VideoStream
VideoStreamType * m_VideoStream
Definition: itkOpenCVVideoCapture.h:144
itk::OpenCVVideoCapture::m_FourCC
int m_FourCC
Definition: itkOpenCVVideoCapture.h:148
itk::OpenCVVideoCapture::m_FpS
double m_FpS
Definition: itkOpenCVVideoCapture.h:147
itk::OpenCVVideoCapture
This class implements OpenCV's VideoCapture API and takes an itk VideoStream as input.
Definition: itkOpenCVVideoCapture.h:51
itk::OpenCVVideoCapture::FrameType
typename VideoStreamType::FrameType FrameType
Definition: itkOpenCVVideoCapture.h:60
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &vct)
itk::OpenCVVideoCapture::~OpenCVVideoCapture
virtual ~OpenCVVideoCapture()
Definition: itkOpenCVVideoCapture.h:72
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::OpenCVVideoCapture::open
virtual bool open(int)
Definition: itkOpenCVVideoCapture.h:89
itk::OpenCVVideoCapture::PixelType
typename FrameType::PixelType PixelType
Definition: itkOpenCVVideoCapture.h:61
itk::OpenCVVideoCapture::isOpened
virtual bool isOpened() const
Definition: itkOpenCVVideoCapture.h:103