ITK  4.13.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:
53 
54  typedef Superclass::TemporalOffsetType TemporalOffsetType;
55  typedef Superclass::FrameOffsetType FrameOffsetType;
56  typedef Superclass::TemporalRatioType TemporalRatioType;
57  typedef Superclass::CameraIDType CameraIDType;
58 
60  itkNewMacro(Self);
61 
63  itkTypeMacro(OpenCVVideoIO, Superclass);
64 
66  virtual void FinishReadingOrWriting();
67 
68  //
69  // Data reading-related methods
70  //
71 
73  virtual void SetReadFromFile();
74 
76  virtual void SetReadFromCamera();
77 
80  virtual bool CanReadFile(const char *);
81 
83  virtual bool CanReadCamera( CameraIDType cameraID ) const;
84 
86  virtual void ReadImageInformation();
87 
89  virtual void Read(void *buffer);
90 
93  virtual bool SetNextFrameToRead( FrameOffsetType frameNumber );
94 
96  virtual TemporalOffsetType GetPositionInMSec() const;
97  virtual TemporalRatioType GetRatio() const;
98  virtual FrameOffsetType GetFrameTotal() const;
99  virtual TemporalRatioType GetFramesPerSecond() const;
100  virtual FrameOffsetType GetCurrentFrame() const;
101  virtual FrameOffsetType GetIFrameInterval() const;
102  virtual FrameOffsetType GetLastIFrame() const;
104 
105  //
106  // Data writing-related methods
107  //
108 
110  virtual void SetCameraIndex(CameraIDType idx);
111  virtual CameraIDType GetCameraIndex() const;
113 
116  virtual double GetSpacing(unsigned int itkNotUsed(i)) const
117  { return 1.0; }
118  virtual double GetOrigin(unsigned int itkNotUsed(i)) const
119  { return 0.0; }
120  virtual std::vector< double > GetDirection(unsigned int i) const
121  { return this->GetDefaultDirection(i); }
123 
126  virtual bool CanWriteFile(const char *);
127 
130  virtual void WriteImageInformation();
131 
134  virtual void Write(const void *buffer);
135 
137  virtual void SetWriterParameters( TemporalRatioType fps,
138  const std::vector<SizeValueType>& dim,
139  const char* fourCC,
140  unsigned int nChannels,
141  IOComponentType componentType );
142 
143 protected:
144  OpenCVVideoIO();
145  ~OpenCVVideoIO();
146 
147  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
148 
150  void UpdateReaderProperties();
151 
153  void ResetMembers();
154 
156  void OpenReader();
157 
159  void OpenWriter();
160 
161 private:
162  ITK_DISALLOW_COPY_AND_ASSIGN(OpenCVVideoIO);
163 
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
Light weight base class for most itk classes.
Abstract superclass defines video IO interface.
virtual double GetSpacing(unsigned int) const
OpenCVVideoIO Self
virtual double GetOrigin(unsigned int) const
SizeValueType FrameOffsetType
CvVideoWriter * m_Writer
Superclass::TemporalOffsetType TemporalOffsetType
Superclass::CameraIDType CameraIDType
Superclass::TemporalRatioType TemporalRatioType
SizeValueType CameraIDType
SmartPointer< Self > Pointer
VideoIOBase Superclass
VideoIO object for reading and writing videos using OpenCV.
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:59
double TemporalRatioType
double TemporalOffsetType
Superclass::FrameOffsetType FrameOffsetType