ITK  4.9.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 #include "cv.h"
23 #include "highgui.h"
24 #include "ITKVideoBridgeOpenCVExport.h"
25 
26 
27 namespace itk
28 {
35 class ITKVideoBridgeOpenCV_EXPORT OpenCVVideoIO : public VideoIOBase
36 {
37 public:
42 
43  typedef Superclass::TemporalOffsetType TemporalOffsetType;
44  typedef Superclass::FrameOffsetType FrameOffsetType;
45  typedef Superclass::TemporalRatioType TemporalRatioType;
46  typedef Superclass::CameraIDType CameraIDType;
47 
49  itkNewMacro(Self);
50 
52  itkTypeMacro(OpenCVVideoIO, Superclass);
53 
55  virtual void FinishReadingOrWriting();
56 
57  /*-------- This part of the interface deals with reading data. ------ */
58 
60  virtual void SetReadFromFile();
61 
63  virtual void SetReadFromCamera();
64 
67  virtual bool CanReadFile(const char *);
68 
70  virtual bool CanReadCamera( CameraIDType cameraID ) const;
71 
73  virtual void ReadImageInformation();
74 
76  virtual void Read(void *buffer);
77 
80  virtual bool SetNextFrameToRead( FrameOffsetType frameNumber );
81 
83  virtual TemporalOffsetType GetPositionInMSec() const;
84  virtual TemporalRatioType GetRatio() const;
85  virtual FrameOffsetType GetFrameTotal() const;
86  virtual TemporalRatioType GetFramesPerSecond() const;
87  virtual FrameOffsetType GetCurrentFrame() const;
88  virtual FrameOffsetType GetIFrameInterval() const;
89  virtual FrameOffsetType GetLastIFrame() const;
91 
92  /*-------- This part of the interfaces deals with writing data. ----- */
93 
95  virtual void SetCameraIndex(CameraIDType idx);
96  virtual CameraIDType GetCameraIndex() const;
98 
101  virtual double GetSpacing(unsigned int itkNotUsed(i)) const
102  { return 1.0; }
103  virtual double GetOrigin(unsigned int itkNotUsed(i)) const
104  { return 0.0; }
105  virtual std::vector< double > GetDirection(unsigned int i) const
106  { return this->GetDefaultDirection(i); }
108 
111  virtual bool CanWriteFile(const char *);
112 
115  virtual void WriteImageInformation();
116 
119  virtual void Write(const void *buffer);
120 
122  virtual void SetWriterParameters( TemporalRatioType fps,
123  const std::vector<SizeValueType>& dim,
124  const char* fourCC,
125  unsigned int nChannels,
126  IOComponentType componentType );
127 
128 protected:
129  OpenCVVideoIO();
130  ~OpenCVVideoIO();
131 
132  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
133 
135  void UpdateReaderProperties();
136 
138  void ResetMembers();
139 
141  void OpenReader();
142 
144  void OpenWriter();
145 
146 private:
147  OpenCVVideoIO(const Self &) ITK_DELETE_FUNCTION;
148  void operator=(const Self &) ITK_DELETE_FUNCTION;
149 
151  IplImage* m_CVImage;
152  IplImage* m_TempImage;
153  CvCapture* m_Capture;
154  CvVideoWriter* m_Writer;
155  int m_FourCC;
156 
158  int m_CameraIndex;
159 
160 
161 };
162 } // end namespace itk
163 
164 #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
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:57
double TemporalRatioType
double TemporalOffsetType
Superclass::FrameOffsetType FrameOffsetType