Medical Imaging Interaction Toolkit  2023.04.00
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 mitkOpenCVVideoSource_h
14 #define mitkOpenCVVideoSource_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 {
39  class MITKOPENCVVIDEOSUPPORT_EXPORT OpenCVVideoSource :
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 
58  virtual void SetVideoFileInput(const char * filename, bool repeatVideo, bool useCVCAMLib = false);
63  virtual void SetVideoCameraInput(int cameraindex, bool useCVCAMLib = false);
76  virtual double GetVideoCaptureProperty(int property_id);
80  virtual int SetVideoCaptureProperty(int property_id, double value);
81 
82  virtual void GetCurrentFrameAsOpenCVImage(IplImage * image);
86  cv::Mat GetImage() override;
87  virtual const IplImage * GetCurrentFrame();
90  virtual void GetCurrentFrameAsItkHSVPixelImage(HSVPixelImageType::Pointer &Image);
93  void FetchFrame() override;
96  unsigned char * GetVideoTexture() override;
99  void StartCapturing() override;
102  void StopCapturing() override;
105  virtual IplImage* FlipImage(IplImage* input);
110  virtual void EnableOnlineImageUndistortion(mitk::Point3D focal, mitk::Point3D principal, mitk::Point4D distortion);
113  virtual void DisableOnlineImageUndistortion();
117  virtual bool OnlineImageUndistortionEnabled() const;
118 
119  void PauseCapturing() override;
123  itkGetConstMacro( VideoFileName, std::string );
124 
125  virtual void SetEnableXAxisFlip(bool enable);
126  virtual void SetEnableYAxisFlip(bool enable);
127 
131  itkGetConstMacro( GrabbingDeviceNumber, short );
132 
133  itkGetMacro( RepeatVideo, bool );
134  itkSetMacro( RepeatVideo, bool );
135 
136 
137  protected:
139  ~OpenCVVideoSource() override;
140 
144  void Reset();
145 
149  void UpdateVideoTexture();
150 
151  // Helper functions
152  void sleep(unsigned int ms);
153  void RGBtoHSV(float r, float g, float b, float &h, float &s, float &v);
154 
155  // HighGUI Library capture device
156  CvCapture * m_VideoCapture;
157 
158  // current Video image
159  IplImage * m_CurrentImage;
160  unsigned char* m_CurrentVideoTexture;
161 
162  IplImage * m_PauseImage;
163 
166  std::string m_VideoFileName;
167 
171 
172  // Repeat a video file
174 
175  // Switch between CVCAM Lib and HighGui Lib
177 
178  // On-the-fly undistortion of the captured video image
180  mitk::UndistortCameraImage::Pointer m_UndistortCameraImage;
181 
186 
191  };
192 }
193 #endif
mitk::OpenCVVideoSource::m_UseCVCAMLib
bool m_UseCVCAMLib
Definition: mitkOpenCVVideoSource.h:176
mitk::OpenCVVideoSource::RGBPixelImageType
itk::Image< CharPixelType, 2 > RGBPixelImageType
Definition: mitkOpenCVVideoSource.h:45
mitk::OpenCVVideoSource::m_VideoFileName
std::string m_VideoFileName
saves the video file name (is empty if a grabbing device is used or if this is not initialized)
Definition: mitkOpenCVVideoSource.h:166
mitk::OpenCVVideoSource::m_RepeatVideo
bool m_RepeatVideo
Definition: mitkOpenCVVideoSource.h:173
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
mitk::OpenCVVideoSource::m_UndistortImage
bool m_UndistortImage
Definition: mitkOpenCVVideoSource.h:179
mitk::OpenCVVideoSource::m_VideoCapture
CvCapture * m_VideoCapture
Definition: mitkOpenCVVideoSource.h:156
mitk::OpenCVVideoSource::HSVPixelType
itk::FixedArray< float, 3 > HSVPixelType
Definition: mitkOpenCVVideoSource.h:44
mitk::OpenCVVideoSource::m_PauseImage
IplImage * m_PauseImage
Definition: mitkOpenCVVideoSource.h:162
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::OpenCVVideoSource::m_FlipYAxisEnabled
bool m_FlipYAxisEnabled
Definition: mitkOpenCVVideoSource.h:190
mitk::OpenCVImageSource
Definition: mitkOpenCVImageSource.h:24
mitk::OpenCVVideoSource::HSVPixelImageType
itk::Image< HSVPixelType, 2 > HSVPixelImageType
Definition: mitkOpenCVVideoSource.h:46
mitk::OpenCVVideoSource::m_CurrentVideoTexture
unsigned char * m_CurrentVideoTexture
Definition: mitkOpenCVVideoSource.h:160
mitk::Point< ScalarType, 3 >
mitk::OpenCVVideoSource::CharPixelType
itk::RGBPixel< unsigned char > CharPixelType
Definition: mitkOpenCVVideoSource.h:43
mitk::OpenCVVideoSource::m_FlipXAxisEnabled
bool m_FlipXAxisEnabled
Definition: mitkOpenCVVideoSource.h:185
mitk::OpenCVVideoSource::m_GrabbingDeviceNumber
short m_GrabbingDeviceNumber
saves the grabbing device number (is -1 if a videofilename is used or if this is not initialized)
Definition: mitkOpenCVVideoSource.h:170
mitk::OpenCVVideoSource
Definition: mitkOpenCVVideoSource.h:39
mitkConfig.h
mitk::VideoSource
Definition: mitkVideoSource.h:27
mitk::OpenCVVideoSource::m_UndistortCameraImage
mitk::UndistortCameraImage::Pointer m_UndistortCameraImage
Definition: mitkOpenCVVideoSource.h:180
mitkVideoSource.h
mitk::OpenCVVideoSource::RGBConstIteratorType
itk::ImageRegionIterator< RGBPixelImageType > RGBConstIteratorType
Definition: mitkOpenCVVideoSource.h:47
mitkUndistortCameraImage.h
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::OpenCVVideoSource::HSVConstIteratorType
itk::ImageRegionIterator< HSVPixelImageType > HSVConstIteratorType
Definition: mitkOpenCVVideoSource.h:48
mitk::OpenCVVideoSource::m_CurrentImage
IplImage * m_CurrentImage
Definition: mitkOpenCVVideoSource.h:159
mitkOpenCVImageSource.h