![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b5b7151234d3540d7c769883d4320247.jpeg)
`newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx,dist,(w,h),0,(w,h))
dst = cv2.undistort(img,mtx,dist,None,newcameramtx)
x, y, w, h = roi
dst1 = dst[y:y + h, x:x + w]
cv2.imwrite('afterconimg.jpg', dst1)`
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c8b9f92927eadea86e3166c212fff9a3.jpeg)
`newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx,dist,(w,h),0,(w,h))
dst = cv2.undistort(img,mtx,dist,None,newcameramtx)
x, y, w, h = roi
dst1 = dst[y:y + h, x:x + w]
cv2.imwrite('afterconimg.jpg', dst)`
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5b298ccbeade0567ce76fb438ace84dd.jpeg)
`newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx,dist,(w,h),1,(w,h))
dst = cv2.undistort(img,mtx,dist,None,newcameramtx)
x, y, w, h = roi
dst1 = dst[y:y + h, x:x + w]
cv2.imwrite('afterconimg.jpg', dst)`
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/443d4fc9f3b03893c5c545200ecb176a.jpeg)
newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx,dist,(w,h),1,(w,h))
dst = cv2.undistort(img,mtx,dist,None,newcameramtx)
x, y, w, h = roi
dst1 = dst[y:y + h, x:x + w]
cv2.imwrite('afterconimg3.jpg', dst1)