Пример #1
0
def update_camera_matrix(params: CameraParams) -> CameraParams:
    """"Treat the source as already undistorted. Thus, the new camera matrix becomes the matrix and the distortion
    coefficients are zeroed."""
    if params.newcameramtx is None:
        params.newcameramtx, _ = Calibration.get_optimal_camera_matrix(params)
    params.camera_matrix = params.newcameramtx
    params.newcameramtx = None
    params.distortion_coefficients = None
    return params
Пример #2
0
    def initUndistort(self):
        self.params.newcameramtx, self.params.roi = (
            Calibration.get_optimal_camera_matrix(self.params))

        self.mapx, self.mapy = Calibration.get_undistort_maps(self.params)
Пример #3
0
    params = calibrate(alpha=res.alpha, flags=flags, nooutliers=res.nooutliers)
    ll.info(f'Calibration took {time.time() - start}s')

if res.nodisplay and not res.write:
    ll.info('Done.')
    exit(0)

ll.info(f'Reading calibration from file {res.file}')
params = CameraParams.read_from_file(res.file)

# newcameramtx, roi = cv2.getOptimalNewCameraMatrix(
#     params.camera_matrix, params.distortion_coefficients,
#     imageSize=(params.image_width, params.image_height),
#     newImgSize=(res.width, res.height), alpha=res.alpha)

newcameramtx, roi = Calibration.get_optimal_camera_matrix(
    params, new_image_size=(res.width, res.height), alpha=res.alpha)
params.newcameramtx = newcameramtx

# mapx, mapy = cv2.initUndistortRectifyMap(
#     params.camera_matrix, params.distortion_coefficients,
#     newCameraMatrix=newcameramtx, size=(res.width, res.height),
#     m1type=cv2.CV_32FC2, R=None)

mapx, mapy = Calibration.get_undistort_maps(params)

# Convert Region of interest to int for Rectangle.
roi_x, roi_y, roi_w, roi_h = tuple(map(int, roi))

matrix_lines = str(newcameramtx).split('\n')

for line in matrix_lines: