ITK  4.6.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 namespace itk
27 {
28 
40 template <typename TVideoStream>
41 class OpenCVVideoCapture : public cv::VideoCapture
42 {
43 public:
44 
48  typedef TVideoStream VideoStreamType;
50  typedef typename VideoStreamType::FrameType FrameType;
51  typedef typename FrameType::PixelType PixelType;
52  static const unsigned int Dimensions = FrameType::ImageDimension;
53 
56 
58  OpenCVVideoCapture(VideoStreamType* videoStream);
59 
63  {
64  }
65 
67  itkTypeMacro(OpenCVVideoCapture, cv::VideoCapture);
68 
72  virtual bool open(const std::string &)
73  {
74  itkExceptionMacro("itk::OpenCVVideoCapture::open(filename) -> If you just want "
75  "to read from a file, use cv::VideoCapture since there is nothing to be "
76  "gained using itk's version.");
77  }
78 
79  virtual bool open(int)
80  {
81  itkExceptionMacro("itk::OpenCVVideoCapture::open(device) -> If you just want "
82  "to read from a device, use cv::VideoCapture since there is nothing to be "
83  "gained using itk's version.");
84  }
85 
88  virtual bool open(VideoStreamType* videoStream);
89 
91  virtual bool isOpened() const
92  {
93  return m_VideoStream == 0;
94  }
95 
98  virtual void release();
99 
103  virtual bool grab();
104 
106  virtual bool retrieve(cv::Mat & image, int channel = 0);
107 
110  virtual Self & operator >>(cv::Mat& image);
111 
113  virtual bool read(cv::Mat& image);
114 
118  virtual bool set(int propId, double value);
119 
121  virtual double get(int propId);
122 
123 protected:
124 
127 
129  double m_FpS;
130  int m_FourCC;
131 
132 }; // end class VideoCapture
133 
134 } // end namespace itk
135 
136 #ifndef ITK_MANUAL_INSTANTIATION
137 #include "itkOpenCVVideoCapture.hxx"
138 #endif
139 
140 #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