Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef _mitk_OpenCVVideo_Source_h_
14 #define _mitk_OpenCVVideo_Source_h_
15 
16 #include "mitkConfig.h"
17 
18 #include "mitkVideoSource.h"
20 
21 // HighGui camera interface: a convenient way for grabbing from a video capture (on windows VfW is used)
22 #include <opencv2/highgui.hpp>
23 
24 // For Providing ITK Image Interface
25 #include "itkRGBPixel.h"
26 #include "itkImage.h"
27 #include "itkImageRegionIterator.h"
28 #include "mitkOpenCVImageSource.h"
29 
30 namespace mitk
31 {
40  virtual public VideoSource, virtual public OpenCVImageSource
41  {
42  public:
43  typedef itk::RGBPixel< unsigned char > CharPixelType;
44  typedef itk::FixedArray <float,3> HSVPixelType;
45  typedef itk::Image< CharPixelType , 2 > RGBPixelImageType;
46  typedef itk::Image<HSVPixelType,2> HSVPixelImageType;
47  typedef itk::ImageRegionIterator< RGBPixelImageType > RGBConstIteratorType;
48  typedef itk::ImageRegionIterator< HSVPixelImageType > HSVConstIteratorType;
49 
51  itkFactorylessNewMacro(Self)
52  itkCloneMacro(Self)
53 
54 
55  virtual void SetVideoFileInput(const char * filename, bool repeatVideo, bool useCVCAMLib = false);
63  virtual void SetVideoCameraInput(int cameraindex, bool useCVCAMLib = false);
77  virtual double GetVideoCaptureProperty(int property_id);
82  virtual int SetVideoCaptureProperty(int property_id, double value);
83 
84  virtual void GetCurrentFrameAsOpenCVImage(IplImage * image);
88  cv::Mat GetImage() override;
89  virtual const IplImage * GetCurrentFrame();
92  virtual void GetCurrentFrameAsItkHSVPixelImage(HSVPixelImageType::Pointer &Image);
95  void FetchFrame() override;
98  unsigned char * GetVideoTexture() override;
101  void StartCapturing() override;
104  void StopCapturing() override;
107  virtual IplImage* FlipImage(IplImage* input);
112  virtual void EnableOnlineImageUndistortion(mitk::Point3D focal, mitk::Point3D principal, mitk::Point4D distortion);
115  virtual void DisableOnlineImageUndistortion();
119  virtual bool OnlineImageUndistortionEnabled() const;
120 
121  void PauseCapturing() override;
125  itkGetConstMacro( VideoFileName, std::string );
126 
127  virtual void SetEnableXAxisFlip(bool enable);
128  virtual void SetEnableYAxisFlip(bool enable);
129 
133  itkGetConstMacro( GrabbingDeviceNumber, short );
134 
135  itkGetMacro( RepeatVideo, bool );
136  itkSetMacro( RepeatVideo, bool );
137 
138 
139  protected:
141  ~OpenCVVideoSource() override;
142 
146  void Reset();
147 
151  void UpdateVideoTexture();
152 
153  // Helper functions
154  void sleep(unsigned int ms);
155  void RGBtoHSV(float r, float g, float b, float &h, float &s, float &v);
156 
157  // HighGUI Library capture device
158  CvCapture * m_VideoCapture;
159 
160  // current Video image
161  IplImage * m_CurrentImage;
162  unsigned char* m_CurrentVideoTexture;
163 
164  IplImage * m_PauseImage;
165 
168  std::string m_VideoFileName;
169 
173 
174  // Repeat a video file
176 
177  // Switch between CVCAM Lib and HighGui Lib
179 
180  // On-the-fly undistortion of the captured video image
182  mitk::UndistortCameraImage::Pointer m_UndistortCameraImage;
183 
188 
193  };
194 }
195 #endif // Header
196 
197 
mitk::UndistortCameraImage::Pointer m_UndistortCameraImage
itk::ImageRegionIterator< HSVPixelImageType > HSVConstIteratorType
std::string m_VideoFileName
saves the video file name (is empty if a grabbing device is used or if this is not initialized) ...
itk::Image< HSVPixelType, 2 > HSVPixelImageType
DataCollection - Class to facilitate loading/accessing structured data.
itk::RGBPixel< unsigned char > CharPixelType
#define MITKOPENCVVIDEOSUPPORT_EXPORT
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
Image class for storing images.
Definition: mitkImage.h:72
itk::ImageRegionIterator< RGBPixelImageType > RGBConstIteratorType
itk::Image< CharPixelType, 2 > RGBPixelImageType
mitk::Image::Pointer image
unsigned char * m_CurrentVideoTexture
itk::FixedArray< float, 3 > HSVPixelType
short m_GrabbingDeviceNumber
saves the grabbing device number (is -1 if a videofilename is used or if this is not initialized) ...