示例#1
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)
示例#2
0
# 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:
    ll.debug(f"New camera matrix: {line}")

ll.debug(f"ROI: {(roi_x, roi_y, roi_w, roi_h)}")

ll.info(f'Reading video from {res.read_video}')
cap = cv2.VideoCapture(res.read_video)
if not cap.isOpened():
    ll.error(f'Could not open source {res.read_video}')