ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkOpenCVVideoIO.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 itkOpenCVVideoIO_h
19 #define itkOpenCVVideoIO_h
20 
21 #include "itkVideoIOBase.h"
22 
23 #include "opencv2/core/version.hpp"
24 #if !defined(CV_VERSION_EPOCH)
25 // OpenCV 3.x
26 #include "opencv2/videoio/videoio.hpp"
27 #include "opencv2/videoio/videoio_c.h"
28 #include "opencv2/imgproc/imgproc_c.h"
29 #else
30 // OpenCV 2.4.x
31 #include "cv.h"
32 #include "highgui.h"
33 #endif
34 
35 #include "ITKVideoBridgeOpenCVExport.h"
36 
37 
38 namespace itk
39 {
46 class ITKVideoBridgeOpenCV_EXPORT OpenCVVideoIO : public VideoIOBase
47 {
48 public:
49  ITK_DISALLOW_COPY_AND_ASSIGN(OpenCVVideoIO);
50 
55 
56  using TemporalOffsetType = Superclass::TemporalOffsetType;
57  using FrameOffsetType = Superclass::FrameOffsetType;
58  using TemporalRatioType = Superclass::TemporalRatioType;
59  using CameraIDType = Superclass::CameraIDType;
60 
62  itkNewMacro(Self);
63 
65  itkTypeMacro(OpenCVVideoIO, Superclass);
66 
68  virtual void FinishReadingOrWriting();
69 
70  //
71  // Data reading-related methods
72  //
73 
75  virtual void SetReadFromFile();
76 
78  virtual void SetReadFromCamera();
79 
82  virtual bool CanReadFile(const char *);
83 
85  virtual bool CanReadCamera( CameraIDType cameraID ) const;
86 
88  virtual void ReadImageInformation();
89 
91  virtual void Read(void *buffer);
92 
95  virtual bool SetNextFrameToRead( FrameOffsetType frameNumber );
96 
98  virtual TemporalOffsetType GetPositionInMSec() const;
99  virtual TemporalRatioType GetRatio() const;
100  virtual FrameOffsetType GetFrameTotal() const;
101  virtual TemporalRatioType GetFramesPerSecond() const;
102  virtual FrameOffsetType GetCurrentFrame() const;
103  virtual FrameOffsetType GetIFrameInterval() const;
104  virtual FrameOffsetType GetLastIFrame() const;
106 
107  //
108  // Data writing-related methods
109  //
110 
112  virtual void SetCameraIndex(CameraIDType idx);
113  virtual CameraIDType GetCameraIndex() const;
115 
118  virtual double GetSpacing(unsigned int itkNotUsed(i)) const
119  { return 1.0; }
120  virtual double GetOrigin(unsigned int itkNotUsed(i)) const
121  { return 0.0; }
122  virtual std::vector< double > GetDirection(unsigned int i) const
123  { return this->GetDefaultDirection(i); }
125 
128  virtual bool CanWriteFile(const char *);
129 
132  virtual void WriteImageInformation();
133 
136  virtual void Write(const void *buffer);
137 
139  virtual void SetWriterParameters( TemporalRatioType fps,
140  const std::vector<SizeValueType>& dim,
141  const char* fourCC,
142  unsigned int nChannels,
143  IOComponentType componentType );
144 
145 protected:
146  OpenCVVideoIO();
147  ~OpenCVVideoIO();
148 
149  void PrintSelf(std::ostream & os, Indent indent) const override;
150 
152  void UpdateReaderProperties();
153 
155  void ResetMembers();
156 
158  void OpenReader();
159 
161  void OpenWriter();
162 
163 private:
164 private:
165  IplImage* m_CVImage;
166  IplImage* m_TempImage;
167  CvCapture* m_Capture;
168  CvVideoWriter* m_Writer;
169  int m_FourCC;
170 
172 
173 };
174 } // end namespace itk
175 
176 #endif // itkOpenCVVideoIO_h
double TemporalOffsetType
Light weight base class for most itk classes.
Abstract superclass defines video IO interface.
virtual double GetSpacing(unsigned int) const
SizeValueType FrameOffsetType
double TemporalRatioType
virtual double GetOrigin(unsigned int) const
CvVideoWriter * m_Writer
VideoIO object for reading and writing videos using OpenCV.
SizeValueType CameraIDType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual std::vector< double > GetDirection(unsigned int i) const
Base class for most ITK classes.
Definition: itkObject.h:60