【发布时间】:2020-07-24 14:58:17
【问题描述】:
我尝试校准我的相机,我已经生成了校准矩阵和不失真参数
array([[449.23763332, 0. , 288.9949981 ],
[ 0. , 509.88847329, 195.85872177],
[ 0. , 0. , 1. ]])
array([-0.38496184, 0.21366652, -0.00107046, 0.00090068, -0.07853835])
以下代码用于不失真
file = 'snapshot_640_480_1.jpg'
img = cv2.imread(file)
h, w = img.shape[:2]
newcameramtx, roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))
mapx, mapy = cv.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w,h), 5)
dst = cv.remap(img, mapx, mapy, cv.INTER_LINEAR)
# crop the image
x, y, w, h = roi
dst1 = dst[y:y+h, x:x+w]
cv.imwrite('calibresult.png', dst1)
display.Image(filename='calibresult.png')
生成的图像尺寸缩小为 (95, 115, 3)
有什么方法可以使相同大小的图像不失真(调整大小会使图像失真)?
【问题讨论】:
-
在 initUndist... 你正在设置输出大小(任何你喜欢的),但之后你正在裁剪图像。您的问题是: dst1 = dst[y:y+h, x:x+w] 只需删除该行
-
实际上未失真的图像仅在特定边界内 @Micka ,外部边界仅包含空信息
-
好的,抱歉。您的输出图像的大小应为 w 和 h。你能检查所有的值吗? x,y,w,h 和原始图像的大小?
-
您可以根据需要调整cameraMatrix
-
请自行回答解决方案。我要上传它
标签: python image opencv image-processing