opencv_undistort.cpp
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this
6 license.
7 // If you do not agree to this license, do not download, install,
8 // copy or use the software.
9 //
10 //
11 // License Agreement
12 // For Open Source Computer Vision Library
13 //
14 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
15 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
16 // Third party copyrights are property of their respective owners.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 modification,
20 // are permitted provided that the following conditions are met:
21 //
22 // * Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // * Redistribution's in binary form must reproduce the above copyright
26 notice,
27 // this list of conditions and the following disclaimer in the documentation
28 // and/or other materials provided with the distribution.
29 //
30 // * The name of the copyright holders may not be used to endorse or promote
31 products
32 // derived from this software without specific prior written permission.
33 //
34 // This software is provided by the copyright holders and contributors "as is"
35 and
36 // any express or implied warranties, including, but not limited to, the implied
37 // warranties of merchantability and fitness for a particular purpose are
38 disclaimed.
39 // In no event shall the Intel Corporation or contributors be liable for any
40 direct,
41 // indirect, incidental, special, exemplary, or consequential damages
42 // (including, but not limited to, procurement of substitute goods or services;
43 // loss of use, data, or profits; or business interruption) however caused
44 // and on any theory of liability, whether in contract, strict liability,
45 // or tort (including negligence or otherwise) arising in any way out of
46 // the use of this software, even if advised of the possibility of such damage.
47 //
48 //M*/
49 
50 #include "opencv_undistort.h"
51 
52 void UndistortPoints(float *_srcx, float *_srcy, float *_dstx, float *_dsty,
53  CameraIntrinsics *_cameraMatrix, int maxcount, int rows,
54  int cols, uint8_t row_bin_factor, uint8_t col_bin_factor) {
55  double k1 = _cameraMatrix->k1;
56  double k2 = _cameraMatrix->k2;
57  double k3 = _cameraMatrix->k3;
58  double k4 = _cameraMatrix->k4;
59  double k5 = _cameraMatrix->k5;
60  double k6 = _cameraMatrix->k6;
61 
62  double p2 = _cameraMatrix->p2;
63  double p1 = _cameraMatrix->p1;
64 
65  double k[14] = {k1, k2, p1, p2, k3, k4, k5, k6, 0, 0, 0, 0, 0, 0};
66 
67  double fx = _cameraMatrix->fx / row_bin_factor;
68  double fy = _cameraMatrix->fy / col_bin_factor;
69 
70  double ifx = 1. / fx;
71  double ify = 1. / fy;
72  double cx = _cameraMatrix->cx / row_bin_factor;
73  double cy = _cameraMatrix->cy / col_bin_factor;
74 
75  int n = rows * cols;
76  for (int i = 0; i < n; i++) {
77  double x, y, x0 = 0, y0 = 0, u, v;
78 
79  x = _srcx[i];
80  y = _srcy[i];
81 
82  u = x;
83  v = y;
84  x = (x - cx) * ifx;
85  y = (y - cy) * ify;
86 
87  // if (_distCoeffs) {
88  // compensate tilt distortion
89 
90  x0 = x;
91  y0 = y;
92 
93  // compensate distortion iteratively
94 
95  for (int j = 0; j < maxcount; j++) {
96  double r2 = x * x + y * y;
97  double icdist = (1 + ((k[7] * r2 + k[6]) * r2 + k[5]) * r2) /
98  (1 + ((k[4] * r2 + k[1]) * r2 + k[0]) * r2);
99  if (icdist < 0) // test: undistortPoints.regression_14583
100  {
101  x = (u - cx) * ifx;
102  y = (v - cy) * ify;
103  break;
104  }
105  double deltaX = 2 * k[2] * x * y + k[3] * (r2 + 2 * x * x) +
106  k[8] * r2 + k[9] * r2 * r2;
107  double deltaY = k[2] * (r2 + 2 * y * y) + 2 * k[3] * x * y +
108  k[10] * r2 + k[11] * r2 * r2;
109  x = (x0 - deltaX) * icdist;
110  y = (y0 - deltaY) * icdist;
111  }
112  _dstx[i] = (float)x;
113  _dsty[i] = (float)y;
114  }
115 }
CameraIntrinsics::cx
float cx
Definition: tofi_camera_intrinsics.h:19
CameraIntrinsics::p1
float p1
Definition: tofi_camera_intrinsics.h:30
google::protobuf.internal::k2
static int k2
Definition: src/google/protobuf/map_test.cc:327
CameraIntrinsics::k5
float k5
Definition: tofi_camera_intrinsics.h:27
CameraIntrinsics::k1
float k1
Definition: tofi_camera_intrinsics.h:23
y
GLint y
Definition: glcorearb.h:2768
x
GLint GLenum GLint x
Definition: glcorearb.h:2834
UndistortPoints
void UndistortPoints(float *_srcx, float *_srcy, float *_dstx, float *_dsty, CameraIntrinsics *_cameraMatrix, int maxcount, int rows, int cols, uint8_t row_bin_factor, uint8_t col_bin_factor)
Definition: opencv_undistort.cpp:52
CameraIntrinsics::k4
float k4
Definition: tofi_camera_intrinsics.h:26
CameraIntrinsics::k6
float k6
Definition: tofi_camera_intrinsics.h:28
CameraIntrinsics::k3
float k3
Definition: tofi_camera_intrinsics.h:25
n
GLdouble n
Definition: glcorearb.h:4153
i
int i
Definition: gmock-matchers_test.cc:764
google::protobuf.internal::k1
static int k1
Definition: src/google/protobuf/map_test.cc:326
v
const GLdouble * v
Definition: glcorearb.h:3106
CameraIntrinsics
Definition: tofi_camera_intrinsics.h:16
CameraIntrinsics::fy
float fy
Definition: tofi_camera_intrinsics.h:18
CameraIntrinsics::fx
float fx
Definition: tofi_camera_intrinsics.h:17
CameraIntrinsics::p2
float p2
Definition: tofi_camera_intrinsics.h:29
CameraIntrinsics::k2
float k2
Definition: tofi_camera_intrinsics.h:24
CameraIntrinsics::cy
float cy
Definition: tofi_camera_intrinsics.h:20
opencv_undistort.h


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:57