【发布时间】:2021-07-19 06:45:33
【问题描述】:
我有一台带鱼眼镜头的相机。我成功地不扭曲我的图像,但我想不扭曲点坐标。我知道地图包含 dst 中每个像素的 src 图像坐标,所以我不能直接使用没有一些迭代算法的那些。我认为 undistortPoints() 会这样做,但它错误地转换了第一点并且它不会改变第二点。使用 undistortPointsIter() 并设置更高的标准也不起作用。
之前有人问过类似的问题,this answer 也对我不起作用。我使用 undistortPoints() 得到完全相同的结果。
那么如何从失真图像中的像素点获取未失真图像的像素点?
我的相机参数:
print(K)
print(D)
print(Dims)
[[338.37324094 0. 319.5 ]
[ 0. 339.059099 239.5 ]
[ 0. 0. 1. ]]
[[ 0.01794191]
[-0.12190366]
[ 0.14111533]
[-0.09602948]]
(640, 480)
我的代码:
img = cv2.imread('Chessboards\img_021.jpg')
img_undistorted = cv2.remap(img, unfishmap1, unfishmap2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
points1=[]
points1.append((165,260))
points1.append((175,410))
print(points1)
img2= img.copy()
for p in points1:
cv2.circle(img2,p,6,(0,0,255),2)
imgshow(img2)
point_matrix = np.zeros(shape=(len(points1),1,2),dtype=np.float32)
for i in range(0, len(points1)):
point_matrix[i][0][0] = points1[i][0]
point_matrix[i][0][1] = points1[i][1]
print(point_matrix)
points_undistorted = cv2.undistortPoints(point_matrix,K,D,R=None,P=K)
points2=[]
for p in points_undistorted:
points2.append( (int(p[0][0]),int(p[0][1])) )
print(points2)
img2= img_undistorted.copy()
for p in points2:
cv2.circle(img2,p,6,(0,0,255),2)
imgshow(img2)
#expected
points3=[]
points3.append((155,265))
points3.append((150,443))
print(points3)
img2= img_undistorted.copy()
for p in points3:
cv2.circle(img2,p,6,(0,0,255),2)
imgshow(img2)
结果:
【问题讨论】:
-
如果 yoz 使用正确的 K 矩阵(来自未失真图像的那个?)如果你在 initUndistRectifyMap 函数中使用它,那么你正在使用 undistortPoints 函数的鱼眼变体。 cv2.fisheye.undistortPoints?:
-
@Micka 我使用了错误的功能。我仍然得到错误的结果。我正在更新我的帖子。
-
你能分享你如何初始化地图的代码吗?我可以告诉你它是如何为我工作的(确保在任何地方都使用鱼眼版本):
cv::fisheye::estimateNewCameraMatrixForUndistortRectify来计算新的相机矩阵K_undist。然后cv::fisheye::initUndistortRectifyMap与K_dist和K_undist。之后使用cv::fisheye::undistortPoints和K_distANDK_undistint 他同一个电话。 -
@Micka 我正要分享该代码,但现在它可以工作了!谢谢!我将在答案中分享对我有用的方法。
标签: python opencv camera-calibration opencv-python fisheye