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