ITK  5.4.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  * 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 
35 namespace itk
36 {
37 
50 template <typename TVideoStream>
51 class ITK_TEMPLATE_EXPORT OpenCVVideoCapture : public cv::VideoCapture
52 {
53 public:
54  using VideoStreamType = TVideoStream;
56  using FrameType = typename VideoStreamType::FrameType;
57  using PixelType = typename FrameType::PixelType;
58  static constexpr unsigned int Dimensions = FrameType::ImageDimension;
59 
62 
64  OpenCVVideoCapture(VideoStreamType * videoStream);
65 
68  virtual ~OpenCVVideoCapture() {}
69 
71  itkVirtualGetNameOfClassMacro(OpenCVVideoCapture);
72 
73  // Open, close functionality
74 
76  virtual bool
77  open(const std::string &)
78  {
79  itkExceptionMacro("itk::OpenCVVideoCapture::open(filename) -> If you just want "
80  "to read from a file, use cv::VideoCapture since there is nothing to be "
81  "gained using itk's version.");
82  }
83 
84  virtual bool
85  open(int)
86  {
87  itkExceptionMacro("itk::OpenCVVideoCapture::open(device) -> If you just want "
88  "to read from a device, use cv::VideoCapture since there is nothing to be "
89  "gained using itk's version.");
90  }
91 
94  virtual bool
95  open(VideoStreamType * videoStream);
96 
98  virtual bool
99  isOpened() const
100  {
101  return m_VideoStream == 0;
102  }
103 
106  virtual void
107  release();
108 
109  // Frame access
110 
112  virtual bool
113  grab();
114 
116  virtual bool
117  retrieve(cv::Mat & image, int channel = 0);
118 
121  virtual Self &
122  operator>>(cv::Mat & image);
123 
125  virtual bool
126  read(cv::Mat & image);
127 
128  // Properties
129 
131  virtual bool
132  set(int propId, double value);
133 
135  virtual double
136  get(int propId);
137 
138 protected:
140  VideoStreamType * m_VideoStream{};
141 
143  double m_FpS{};
144  int m_FourCC{};
145 
146 }; // end class VideoCapture
147 
148 } // end namespace itk
149 
150 #ifndef ITK_MANUAL_INSTANTIATION
151 # include "itkOpenCVVideoCapture.hxx"
152 #endif
153 
154 #endif
itk::OpenCVVideoCapture::VideoStreamType
TVideoStream VideoStreamType
Definition: itkOpenCVVideoCapture.h:54
itkVideoStream.h
itk::OpenCVVideoCapture::open
virtual bool open(const std::string &)
Definition: itkOpenCVVideoCapture.h:77
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:56
itk::OpenCVVideoCapture::~OpenCVVideoCapture
virtual ~OpenCVVideoCapture()
Definition: itkOpenCVVideoCapture.h:68
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:85
itk::OpenCVVideoCapture::PixelType
typename FrameType::PixelType PixelType
Definition: itkOpenCVVideoCapture.h:57
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, VPointDimension > &vct)
itk::OpenCVVideoCapture::isOpened
virtual bool isOpened() const
Definition: itkOpenCVVideoCapture.h:99