Undistortion.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: Undistortion.cpp
37 // Author: Pedram Azad
38 // Date: 04.10.2008
39 // ****************************************************************************
40 
41 
42 // ****************************************************************************
43 // Includes
44 // ****************************************************************************
45 
46 #include <new> // for explicitly using correct new/delete operators on VC DSPs
47 
48 #include "Undistortion.h"
49 
50 #include "Image/ByteImage.h"
53 
54 #include <stdio.h>
55 
56 
57 
58 // ****************************************************************************
59 // class CUndistortion::CUndistortionMapper
60 // ****************************************************************************
61 
63 {
64  m_pCalibration = pCalibration;
66 }
67 
68 void CUndistortion::CUndistortionMapper::ComputeOriginalCoordinates(const Vec2d &newCoordinates, Vec2d &originalCoordinates)
69 {
70  m_pCalibration->DistortImageCoordinates(newCoordinates, originalCoordinates);
71 }
72 
73 
74 
75 // ****************************************************************************
76 // Constructor / Destructor
77 // ****************************************************************************
78 
79 CUndistortion::CUndistortion(bool bInterpolate)
80 {
83 
86 }
87 
89 {
90  delete m_pStereoCalibration;
91  delete m_pCalibration;
92 
95 }
96 
97 
98 // ****************************************************************************
99 // Methods
100 // ****************************************************************************
101 
102 int CUndistortion::Init(const char *pCameraParameterFileName)
103 {
104  if (m_pStereoCalibration->LoadCameraParameters(pCameraParameterFileName))
105  {
106  // stereo calibration
109 
110  UpdateMaps();
111 
112  return 2;
113  }
114  else
115  {
116  // not a stereo calibration
117  if (m_pCalibration->LoadCameraParameters(pCameraParameterFileName))
118  {
121 
122  UpdateMaps();
123 
124  return 1;
125  }
126  }
127 
128  return 0;
129 }
130 
131 void CUndistortion::Init(const CCalibration *pCalibration)
132 {
133  m_pCalibrationLeft = pCalibration;
135 
136  UpdateMaps();
137 }
138 
139 void CUndistortion::Init(const CStereoCalibration *pStereoCalibration)
140 {
141  m_pCalibrationLeft = pStereoCalibration->GetLeftCalibration();
142  m_pCalibrationRight = pStereoCalibration->GetRightCalibration();
143 
144  UpdateMaps();
145 }
146 
148 {
150  {
151  printf("error: CUndistortion object has not been initialized for CUndistortion::UpdateMaps\n");
152  return;
153  }
154 
155  if (m_pCalibrationLeft)
157 
160 }
161 
162 
163 void CUndistortion::Undistort(const CByteImage *pInputImage, CByteImage *pOutputImage)
164 {
165  m_pUndistortionMapperLeft->PerformMapping(pInputImage, pOutputImage);
166 }
167 
168 
169 void CUndistortion::Undistort(const CByteImage * const *ppInputImages, CByteImage **ppOutputImages)
170 {
171  m_pUndistortionMapperLeft->PerformMapping(ppInputImages[0], ppOutputImages[0]);
172  m_pUndistortionMapperRight->PerformMapping(ppInputImages[1], ppOutputImages[1]);
173 }
void ComputeMap(int width, int height)
This method initializes the instance for mapping of images of a specific size.
Definition: ImageMapper.cpp:90
CUndistortionMapper * m_pUndistortionMapperLeft
Definition: Undistortion.h:118
bool LoadCameraParameters(const char *pCameraParameterFileName, bool bTransformLeftCameraToIdentity=true)
Initializes the stereo camera model, given a file path to a stereo camera parameter file...
bool LoadCameraParameters(const char *pCameraParameterFileName, int nCamera=0, bool bSetExtrinsicToIdentity=false)
Initializes the camera model, given a file path to a camera parameter file.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
void DistortImageCoordinates(const Vec2d &undistortedImagePoint, Vec2d &distortedImagePoint) const
Transforms 2D undistorted image coordinates to 2D distorted image coordinates.
const CCalibration * m_pCalibrationLeft
Definition: Undistortion.h:115
void ComputeOriginalCoordinates(const Vec2d &newCoordinates, Vec2d &originalCoordinates)
void Init(const CCalibration *pCalibration)
const CCalibration * GetLeftCalibration() const
Access to the instance of CCalibration for the camera model of the left camera.
const CCameraParameters & GetCameraParameters() const
Gives access to the camera parameters.
Definition: Calibration.h:268
CUndistortion(bool bInterpolate=true)
CStereoCalibration * m_pStereoCalibration
Definition: Undistortion.h:113
const CCalibration * m_pCalibrationRight
Definition: Undistortion.h:116
void Undistort(const CByteImage *pInputImage, CByteImage *pOutputImage)
Camera model and functions for a stereo camera system.
int Init(const char *pCameraParameterFileName)
void PerformMapping(const CByteImage *pInputImage, CByteImage *pOutputImage)
This method performs the mapping.
CUndistortionMapper(bool bInterpolate)
Definition: Undistortion.h:101
Data structure for the representation of a 2D vector.
Definition: Math2d.h:82
CUndistortionMapper * m_pUndistortionMapperRight
Definition: Undistortion.h:119
Camera model parameters and functions for a single camera.
Definition: Calibration.h:125
const CCalibration * m_pCalibration
Definition: Undistortion.h:108
const CCalibration * GetRightCalibration() const
Access to the instance of CCalibration for the camera model of the right camera.


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28