Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkOpenCVVideoSource.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef _mitk_OpenCVVideo_Source_h_
18 #define _mitk_OpenCVVideo_Source_h_
19 
20 #include "mitkConfig.h"
21 
22 #include "mitkVideoSource.h"
24 
25 // HighGui camera interface: a convenient way for grabbing from a video capture (on windows VfW is used)
26 #include "highgui.h"
27 
28 // For Providing ITK Image Interface
29 #include "itkRGBPixel.h"
30 #include "itkImage.h"
31 #include "itkImageRegionIterator.h"
32 #include "mitkOpenCVImageSource.h"
33 
34 namespace mitk
35 {
43  class MITKOPENCVVIDEOSUPPORT_EXPORT OpenCVVideoSource :
44  virtual public VideoSource, virtual public OpenCVImageSource
45  {
46  public:
47  typedef itk::RGBPixel< unsigned char > CharPixelType;
48  typedef itk::FixedArray <float,3> HSVPixelType;
49  typedef itk::Image< CharPixelType , 2 > RGBPixelImageType;
50  typedef itk::Image<HSVPixelType,2> HSVPixelImageType;
51  typedef itk::ImageRegionIterator< RGBPixelImageType > RGBConstIteratorType;
52  typedef itk::ImageRegionIterator< HSVPixelImageType > HSVConstIteratorType;
53 
55  itkFactorylessNewMacro(Self)
56  itkCloneMacro(Self)
57 
62  virtual void SetVideoFileInput(const char * filename, bool repeatVideo, bool useCVCAMLib = false);
67  virtual void SetVideoCameraInput(int cameraindex, bool useCVCAMLib = false);
81  virtual double GetVideoCaptureProperty(int property_id);
86  virtual int SetVideoCaptureProperty(int property_id, double value);
87 
88  virtual void GetCurrentFrameAsOpenCVImage(IplImage * image);
92  virtual cv::Mat GetImage() override;
93  virtual const IplImage * GetCurrentFrame();
96  virtual void GetCurrentFrameAsItkHSVPixelImage(HSVPixelImageType::Pointer &Image);
99  virtual void FetchFrame() override;
102  virtual unsigned char * GetVideoTexture() override;
105  virtual void StartCapturing() override;
108  virtual void StopCapturing() override;
111  virtual IplImage* FlipImage(IplImage* input);
116  virtual void EnableOnlineImageUndistortion(mitk::Point3D focal, mitk::Point3D principal, mitk::Point4D distortion);
119  virtual void DisableOnlineImageUndistortion();
123  virtual bool OnlineImageUndistortionEnabled() const;
124 
125  virtual void PauseCapturing() override;
129  itkGetConstMacro( VideoFileName, std::string );
130 
131  virtual void SetEnableXAxisFlip(bool enable);
132  virtual void SetEnableYAxisFlip(bool enable);
133 
137  itkGetConstMacro( GrabbingDeviceNumber, short );
138 
139  itkGetMacro( RepeatVideo, bool );
140  itkSetMacro( RepeatVideo, bool );
141 
142 
143  protected:
145  virtual ~OpenCVVideoSource();
146 
150  void Reset();
151 
155  void UpdateVideoTexture();
156 
157  // Helper functions
158  void sleep(unsigned int ms);
159  void RGBtoHSV(float r, float g, float b, float &h, float &s, float &v);
160 
161  // HighGUI Library capture device
162  CvCapture * m_VideoCapture;
163 
164  // current Video image
165  IplImage * m_CurrentImage;
166  unsigned char* m_CurrentVideoTexture;
167 
168  IplImage * m_PauseImage;
169 
172  std::string m_VideoFileName;
173 
176  short m_GrabbingDeviceNumber;
177 
178  // Repeat a video file
179  bool m_RepeatVideo;
180 
181  // Switch between CVCAM Lib and HighGui Lib
182  bool m_UseCVCAMLib;
183 
184  // On-the-fly undistortion of the captured video image
185  bool m_UndistortImage;
186  mitk::UndistortCameraImage::Pointer m_UndistortCameraImage;
187 
191  bool m_FlipXAxisEnabled;
192 
196  bool m_FlipYAxisEnabled;
197  };
198 }
199 #endif // Header
200 
201 
itk::ImageRegionIterator< HSVPixelImageType > HSVConstIteratorType
itk::Image< HSVPixelType, 2 > HSVPixelImageType
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
itk::RGBPixel< unsigned char > CharPixelType
static const std::string filename
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Image class for storing images.
Definition: mitkImage.h:76
itk::ImageRegionIterator< RGBPixelImageType > RGBConstIteratorType
itk::Image< CharPixelType, 2 > RGBPixelImageType
itk::FixedArray< float, 3 > HSVPixelType