Skip to content

Commit 35e1daf

Browse files
authored
Merge pull request #24 from JuliaRobotics/23Q3/enh/undistortpoint
separate undist util
2 parents 883c395 + ecb91e0 commit 35e1daf

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/ExportAPI.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export CameraCalibration, CameraCalibrationMutable
88
export toNonhomogeneous
99
export CameraSkewDistortion
1010

11+
export undistortPoint
1112
export Ray, PixelIndex
1213
export pixel2ray, point2pixel, canreproject, sensorsize #, origin, direction,
1314
export project, projectHomogeneous

src/services/CameraServices.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ canreproject(camera::AbstractCameraModel) = true
4444
## =========================================================================================
4545

4646

47+
function undistortPoint(cam::CameraCalibration, xy, iter_num=1) #3)
48+
k1, k2, p1, p2, k3 = cam.kc[1:5]
49+
fx, fy = f_w(cam), f_h(cam) # cam.K[1, 1], cam.K[2, 2]
50+
cx, cy = pp_w(cam), pp_h(cam) # cam.K[1:2, 3]
51+
x, y = xy[1], xy[2]
52+
x = (x - cx) / fx
53+
x0 = x
54+
y = (y - cy) / fy
55+
y0 = y
56+
for _ in 1:iter_num
57+
r2 = x^2 + y^2
58+
k_inv = 1 / (1 + k1*r2 + k2*r2^2 + k3*r2^3)
59+
delta_x = 2*p1*x*y + p2 * (r2 + 2*x^2)
60+
delta_y = p1*(r2 + 2*y^2) + 2*p2*x*y
61+
x = (x0 - delta_x) * k_inv
62+
y = (y0 - delta_y) * k_inv
63+
end
64+
return SA[x*fx+cx; y*fy+cy]
65+
end
66+
67+
68+
## =========================================================================================
69+
## FROM SCENE IN FRONT OF CAMERA TO IMAGE -- I.E. PROJECT
70+
## =========================================================================================
71+
72+
4773
## From JuliaRobotics/SensorFeatureTracking.jl
4874
function project!(
4975
ret::AbstractVector{<:Real},

src/services/Utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ end
2121
"""
2222
$SIGNATURES
2323
24-
Slightly general Radial Distortion type, currently limited to StaticArrays.jl on CPU, but can later be extended to utilize GPUs -- see notes.
24+
Slightly general Radial Distortion type, currently limited to StaticArrays.jl on CPU,
2525
2626
Notes
2727
- Make sure `dest` image is large enough to encapsulate the resulting image after un-distortion
28+
- TODO extended to utilize GPUs.
2829
2930
Example
3031
```julia

0 commit comments

Comments
 (0)