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