Skip to content

Commit 792b387

Browse files
committed
Save mappings to subpixel precision
1 parent 1750fb2 commit 792b387

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

opensfm/undistort.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,25 @@ def cast_to_max(arr):
143143
return arr.astype(np.uint32)
144144

145145
# Dump the camera mappings information for each camera
146-
# compressing the numbers by rounding to nearest int
146+
# compressing the numbers by rounding to nearest int * mul
147147
# and then by attempting to offset the values
148148
# the original value of the map can then be computed with:
149-
# map1[px_y, px_x] <--> compressed_map1[px_y,px_x] + offset[0] + px_x
150-
# map2[px_y, px_x] <--> compressed_map2[px_y,px_x] + offset[1] + px_y
151-
# (note our values are rounded to the closest pixel, though)
149+
# map1[px_y, px_x] <--> ((compressed_map1[px_y,px_x] + offset[0]) / 10.0) + px_x
150+
# map2[px_y, px_x] <--> ((compressed_map2[px_y,px_x] + offset[1]) / 10.0) + px_y
151+
# (note our values are rounded to 1/10th of a pixel)
152152
idx = 0
153153
for key, v in _camera_mapping_cache.items():
154154
ids.append(v['id'])
155155
map1, map2 = v['map']
156-
map1 = np.round(map1)
157-
map2 = np.round(map2)
156+
mul = 10.0 # keep precision up to 1/10th of a pixel
158157

159158
i = np.arange(map1.shape[0]).reshape(-1, 1)
160159
j = np.arange(map1.shape[1])
161160
map1 -= j
162161
map2 -= i
162+
map1 = np.round(map1 * mul)
163+
map2 = np.round(map2 * mul)
164+
163165
offset = np.array([np.min(map1), np.min(map2)])
164166
map1 -= offset[0]
165167
map2 -= offset[1]
@@ -170,6 +172,7 @@ def cast_to_max(arr):
170172
outs['%s_x' % idx] = map1
171173
outs['%s_y' % idx] = map2
172174
outs['%s_offset' % idx] = offset
175+
outs['%s_mul' % idx] = np.array([mul])
173176

174177
idx += 1
175178

0 commit comments

Comments
 (0)