Skip to content

Commit 69ae4ab

Browse files
AntonioMacaroniobrentyijb-ye
authored
Updating camera intrinsics (principal points) when the undistorted image is cropped (#3382)
* added notes and a possible bugfix when region of interest crops image during undistortion to update intrinsics * fixing index error, principal points are on the 3rd column of 3x3 matrix K --------- Co-authored-by: Brent Yi <[email protected]> Co-authored-by: J.Y. <[email protected]>
1 parent 1f2344a commit 69ae4ab

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

nerfstudio/data/datamanagers/full_images_datamanager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ def _undistort_image(
395395
"We doesn't support the 4th Brown parameter for image undistortion, "
396396
"Only k1, k2, k3, p1, p2 can be non-zero."
397397
)
398+
# because OpenCV expects the order of distortion parameters to be (k1, k2, p1, p2, k3), we need to reorder them
399+
# see https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html
398400
distortion_params = np.array(
399401
[
400402
distortion_params[0],
@@ -420,6 +422,9 @@ def _undistort_image(
420422
# crop the image and update the intrinsics accordingly
421423
x, y, w, h = roi
422424
image = image[y : y + h, x : x + w]
425+
# update the principal point based on our cropped region of interest (ROI)
426+
newK[0, 2] -= x
427+
newK[1, 2] -= y
423428
if "depth_image" in data:
424429
data["depth_image"] = data["depth_image"][y : y + h, x : x + w]
425430
if "mask" in data:

0 commit comments

Comments
 (0)