ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkOpenCVVideoCapture.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 
49 template <typename TVideoStream>
50 class ITK_TEMPLATE_EXPORT OpenCVVideoCapture : public cv::VideoCapture
51 {
52 public:
53 
57  using VideoStreamType = TVideoStream;
59  using FrameType = typename VideoStreamType::FrameType;
60  using PixelType = typename FrameType::PixelType;
61  static constexpr unsigned int Dimensions = FrameType::ImageDimension;
62 
65 
67  OpenCVVideoCapture(VideoStreamType* videoStream);
68 
72  {
73  }
74 
76  itkTypeMacroNoParent(OpenCVVideoCapture);
77 
81  virtual bool 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 open(int)
89  {
90  itkExceptionMacro("itk::OpenCVVideoCapture::open(device) -> If you just want "
91  "to read from a device, use cv::VideoCapture since there is nothing to be "
92  "gained using itk's version.");
93  }
94 
97  virtual bool open(VideoStreamType* videoStream);
98 
100  virtual bool isOpened() const
101  {
102  return m_VideoStream == 0;
103  }
104 
107  virtual void release();
108 
112  virtual bool grab();
113 
115  virtual bool retrieve(cv::Mat & image, int channel = 0);
116 
119  virtual Self & operator >>(cv::Mat& image);
120 
122  virtual bool read(cv::Mat& image);
123 
127  virtual bool set(int propId, double value);
128 
130  virtual double get(int propId);
131 
132 protected:
133 
136 
138  double m_FpS;
139  int m_FourCC;
140 
141 }; // end class VideoCapture
142 
143 } // end namespace itk
144 
145 #ifndef ITK_MANUAL_INSTANTIATION
146 #include "itkOpenCVVideoCapture.hxx"
147 #endif
148 
149 #endif
typename FrameType::PixelType PixelType
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
virtual bool isOpened() const
This class implements OpenCV&#39;s VideoCapture API and takes an itk VideoStream as input.
typename VideoStreamType::FrameType FrameType
virtual bool open(const std::string &)