因此,基本上,我想找出什么,倒置失真参数,将是一个校准,我做的,如显示的这里。
注意:我知道我们可以执行非失真操作,然后使用重映射来完成下面所做的工作,但我的目标是能够找到实际的反向失真参数,并使用它们来扭曲其他图像,而不仅仅是能够恢复cv2.
概述:
我曾尝试过否定失真参数:
# _, mat, distortion, _, _ = cv2.calibrateCamera(...)
# undistorted_image = cv2.undistort(with distortion)
# redistorted_image = cv2.undistort(with np.negative(distortion))理论上,我认为如果redistorted_image与原始图像相似,那么np.negative(distortion)参数就是我要找的,但结果却是假的。
我使用的实际方法:
def save_undistorted_images(image, matrix, distortion):
test_image_su = cv.imread(image)
height, width = test_image_su.shape[:2]
new_camera_mtx, roi = cv.getOptimalNewCameraMatrix(matrix, distortion, (width, height), 1, (width, height))
distortion_u = np.negative(distortion)
# unsure if this line helps
new_camera_mtx_inv, roi = cv.getOptimalNewCameraMatrix(matrix, distortion_u, (width, height), 1, (width, height))
# undistort the image
undistorted_image = cv.undistort(test_image_su, matrix, distortion, None, new_camera_mtx)
cv.imwrite('undistorted_frame.png', undistorted_image)
# redistort trying to get something like original image (image_test_su)
distorted_image = cv.undistort(undistorted_image, matrix, distortion_u, None, new_camera_mtx_inv)
cv.imwrite('redistorted_frame.png', distorted_image)结果:
(左a:原件)(右b:不失真)


(左c:使用np.negative(distortion)失真)(右d:未失真图像re使用np.negative(distortion)失真)


这里的图像d基本上是在b上执行的,我希望它与a类似。
为什么b在这里压倒了c的作用
我尝试的另一种计算逆的方法:
下面是这个纸的python实现
distortion_u = distortion
k1 = distortion_u[0][0]
k2 = distortion_u[0][1]
k3 = distortion_u[0][4]
b1 = -1 * k1
b2 = 3 * (k1 * k1) - k2
b3 = (8 * k1 * k2) + (-1 * (12 * (k1 * k1 * k1))) - k3
# radial:
distortion_u[0][0] = b1
distortion_u[0][1] = b2
distortion_u[0][4] = b3
# tangential:
#distortion_u[0][2] = -1 * distortion_u[0][2]
#distortion_u[0][3] = -1 * distortion_u[0][3]利用上述失真参数对未失真图像施加失真的效果也不是很好,看起来与上面的结果非常相似。
因此,我们现在要谈的是:
为什么正常失真的影响总是压倒np.negative(失真)或其他任何东西?
所有的扭曲都是这样运作的吗?(负值不等于相反的效果)
如何得到实际相反的失真参数?
发布于 2021-04-09 15:40:17
恐怕你做错了。您所校准的opencv失真模型从失真的图像坐标中计算不失真和归一化的图像坐标。它是一个非线性模型,因此它的反演涉及到一个非线性(多项式)方程组的求解。
仅在单参数纯径向畸变情况下,即当唯一非零畸变参数为k1时,r^2的系数为r ^2。在这种情况下,模型反演方程简化为r中的三次方程,然后用Cardano的三次方程公式表示逆模型。
在所有其他情况下,采用各种算法求解非线性方程组,对模型进行数值反演。OpenCV使用一种迭代的“假位置”方法。
由于您想要使用逆模型来不扭曲一组图像(这是正常的用例),您应该使用initUndistortRectifyMap来一劳永逸地计算图像的非失真解,然后将它传递给重映射,以真正地消除图像的失真。
如果你真的需要一个反模型的参数模型,我的建议是用一个高阶多项式或薄板样条来逼近由返回的映射。
https://stackoverflow.com/questions/67008814
复制相似问题