import cv2 import numpy as np import os # 相机内参矩阵,假设为K K = np.array([[1451.7946523730436, 0, 960], [ 0, 1438.2609968095967, 540], [ 0, 0, 1]]) # 畸变系数,假设为D D = np.array([-0.0042837100252329525, -0.0016247045538291293, -0.0023595319957707256, 0.00036597253136795013]) # 去畸变函数 # 注意:cv2.undistort()函数的参数顺序是:src, K, D, newCameraMatrix=None, roi=None # 其中newCameraMatrix是可选的,用于指定新的相机内参矩阵,如果设置为None,则使用原始的K # roi是可选的,用于指定输出图像的感兴趣区域 image_dir = '/home/dongdong/2project/0data/house3/120/distort_images' undistort_image_dir = '/home/dongdong/2project/0data/house3/120/undistort_images' os.makedirs(undistort_image_dir,exist_ok=True) for i in range(1,194): image = cv2.imread(os.path.join(image_dir,'{:>04}.jpg'.format(i))) undistorted_image = cv2.undistort(image, K, D, None, None) cv2.imwrite(os.path.join(undistort_image_dir,'{:>04}.jpg'.format(i)),undistorted_image)
标签:None,image,cv2,undistort,照片,畸变,图像,os,dir From: https://www.cnblogs.com/gooutlook/p/18276838