Python 校正不失真减小图像大小
我试着校准我的相机,我已经生成了校准矩阵和不失真参数Python 校正不失真减小图像大小,python,image,opencv,image-processing,Python,Image,Opencv,Image Processing,我试着校准我的相机,我已经生成了校准矩阵和不失真参数 array([[449.23763332, 0. , 288.9949981 ], [ 0. , 509.88847329, 195.85872177], [ 0. , 0. , 1. ]]) array([-0.38496184, 0.21366652, -0.00107046, 0.00090068, -0.078538
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')
结果图像的大小减小为(95115,3)
是否有任何方法可以使相同大小的图像不失真(调整大小会扭曲图像)
允许通过提及输入图像大小(w,h)和预期图像大小(w1,h1),通过更改预期图像大小来更改生成的不失真图像大小
通过改变预期的图像大小,我们将获得参考答案。感谢@Mika的投入
file = r'snapshot_640_480_1.jpg'
img = cv2.imread(file)
h, w = img.shape[:2]
# New Image shape to generate
w1,h1 = 5*w,5*h
newcameramtx, roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w1,h1))
mapx, mapy = cv.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w1,h1), 5)
dst = cv.remap(img, mapx, mapy, cv.INTER_LINEAR)
最初。。。您正在设置输出大小(任何您喜欢的),但之后您将剪切图像。您的问题是:dst1=dst[y:y+h,x:x+w]只需删除线性未失真图像仅在特定边界内@mika,外部边界保持空信息OK抱歉。输出图像的大小应为w和h。你能检查所有的值吗?x、 y、w、h和原始图像的大小?您可以根据需要调整cameraMatrix,请自行回答解决方案。我想上传它