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
mitkUndistortCameraImage.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 __mitkUndistortCameraImage_h
18 #define __mitkUndistortCameraImage_h
19 
20 #include "mitkCommon.h"
21 #include <MitkOpenCVVideoSupportExports.h>
22 #include "itkObject.h"
23 
24 #include "mitkPoint.h"
25 #include "cv.h"
26 
42 namespace mitk
43 {
44 
45 class MITKOPENCVVIDEOSUPPORT_EXPORT UndistortCameraImage : public itk::Object
46 {
47  public:
48 
50  itkFactorylessNewMacro(Self)
51  itkCloneMacro(Self)
52 
53 
54  /*
55  * Set the camera's intrinsic focal length
56  */
57  void SetFocalLength(float fc_x, float fc_y)
58  {
59  m_fcX = fc_x; m_fcY = fc_y;
60  }
61  /*
62  * Set the camera's intrinsic principal point
63  */
64  void SetPrincipalPoint(float cc_x, float cc_y)
65  {
66  m_ccX = cc_x; m_ccY = cc_y;
67  }
68  /*
69  * Set the camera's intrinsic distortion parameters
70  */
71  void SetCameraDistortion(float kc1, float kc2, float kc3, float kc4)
72  {
73  m_distortionMatrixData[0] = kc1; m_distortionMatrixData[1] = kc2;
74  m_distortionMatrixData[2] = kc3; m_distortionMatrixData[3] = kc4;
75  }
76  /*
77  * Pre-Calculates matrices for the later use of UndistortImageFast()
78  */
79  void InitRemapUndistortion(int sizeX, int sizeY);
80 
82  /*
83  * Undistort a single pixel, returns undistorted pixel
84  */
85  mitk::Point2D UndistortPixel(const mitk::Point2D& src);
86  /*
87  * Complete undistortion of an OpenCV image, including all calculations
88  */
89  void UndistortImage(IplImage* src, IplImage* dst);
90 
91 
92  /*
93  * Complete undistortion of an OpenCV image, using pre-calculated matrices from SetUndistortImageFastInfo()
94  * The use of only a source parameter will cause the source to be overwritten.
95  * NOTE: Using the Fast undistortion methods does not require a initialization via the Set... methods.
96  */
97  void UndistortImageFast( IplImage * src, IplImage* dst = nullptr );
98  void SetUndistortImageFastInfo(float in_dF1, float in_dF2,
99  float in_dPrincipalX, float in_dPrincipalY,
100  float in_Dist[4], float ImageSizeX, float ImageSizeY);
101 
103  virtual ~UndistortCameraImage();
104 
105  protected:
106 
107  // principal point and focal length parameters
108  float m_ccX, m_ccY, m_fcX, m_fcY;
109  // undistortion parameters
110  float m_distortionMatrixData[4];
111  // intrinsic camera parameters
112  float m_intrinsicMatrixData[9];
113  // precalculated matrices for fast image undistortion with UndistortImageFast()
114  CvMat * m_mapX, * m_mapY;
115  // intrinsic and undistortion camera matrices
116  CvMat m_intrinsicMatrix, m_distortionMatrix;
117  // temp image
118  IplImage * m_tempImage;
119 
120 
121 
124 };
125 
126 }
127 
128 #endif
void SetCameraDistortion(float kc1, float kc2, float kc3, float kc4)
void SetPrincipalPoint(float cc_x, float cc_y)
DataCollection - Class to facilitate loading/accessing structured data.
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53