Hi,
I’ve performed calibration and have the camera matrix and distortion parameters. I apply them as:
img = cv2.imread(filename)
h,w = img.shape[:2]mtx = np.matrix([[fx, 0, cx],[0, fy, cy],[0, 0, 1]])
dist = np.array([k1, k2, p1, p2, k3])
newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))dest = cv2.undistort(img, mtx, dist, None, newcameramtx)
x,y,w,h = roi
dest = dest[y:y+h, x:x+w]
cv2.imwrite(outfilename, dest)
However, when capturing images, we will be applying rotations automatically, based on the camera orientation. For example, some will be rotated 90 degrees clockwise. I’m trying to figure out how to continue to make use of this undistort process. Of course I can rotate back into the standard orientation, undistort as above, and then re-rotate. But I thought I might be able to manipulate the parameters to apply directly. I think the fx, fy can simply be swapped, and the cx_new = w_new-cy_old, cy_new = cx_old. But I’m not sure about the k1,k2,k3,p1,p2 parameters, and the newcameramtx, roi. I’ve experimented a bunch, but haven’t yet got it to output a correctly undistorted image. Any insights? Thanks,