ITK  4.9.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 "highgui.h"
24 #include "itkVideoStream.h"
25 
26 // Include the required header with OpenCV > 2.X
27 #if !defined( CV_VERSION_EPOCH )
28 #include "opencv2/videoio.hpp"
29 #endif
30 
31 namespace itk
32 {
33 
45 template <typename TVideoStream>
46 class OpenCVVideoCapture : public cv::VideoCapture
47 {
48 public:
49 
53  typedef TVideoStream VideoStreamType;
55  typedef typename VideoStreamType::FrameType FrameType;
56  typedef typename FrameType::PixelType PixelType;
57  static const unsigned int Dimensions = FrameType::ImageDimension;
58 
61 
63  OpenCVVideoCapture(VideoStreamType* videoStream);
64 
68  {
69  }
70 
72  itkTypeMacro(OpenCVVideoCapture, cv::VideoCapture);
73 
77  virtual bool 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 open(int)
85  {
86  itkExceptionMacro("itk::OpenCVVideoCapture::open(device) -> If you just want "
87  "to read from a device, use cv::VideoCapture since there is nothing to be "
88  "gained using itk's version.");
89  }
90 
93  virtual bool open(VideoStreamType* videoStream);
94 
96  virtual bool isOpened() const
97  {
98  return m_VideoStream == 0;
99  }
100 
103  virtual void release();
104 
108  virtual bool grab();
109 
111  virtual bool retrieve(cv::Mat & image, int channel = 0);
112 
115  virtual Self & operator >>(cv::Mat& image);
116 
118  virtual bool read(cv::Mat& image);
119 
123  virtual bool set(int propId, double value);
124 
126  virtual double get(int propId);
127 
128 protected:
129 
132 
134  double m_FpS;
135  int m_FourCC;
136 
137 }; // end class VideoCapture
138 
139 } // end namespace itk
140 
141 #ifndef ITK_MANUAL_INSTANTIATION
142 #include "itkOpenCVVideoCapture.hxx"
143 #endif
144 
145 #endif
FrameType::PixelType PixelType
virtual Self & operator>>(cv::Mat &image)
virtual void release()
static const unsigned int Dimensions
virtual bool set(int propId, double value)
virtual bool isOpened() const
virtual bool retrieve(cv::Mat &image, int channel=0)
This class implements OpenCV&#39;s VideoCapture API and takes an itk VideoStream as input.
OpenCVVideoCapture< VideoStreamType > Self
virtual bool read(cv::Mat &image)
virtual bool open(const std::string &)
VideoStreamType::FrameType FrameType