code: def check_calibration(self, calibration):
          
          sides = "left", "right"
          which_image = {sides[0]: 1, sides[1]: 2}
          undistorted, lines = {}, {}
          for side in sides:
              undistorted[side] = cv2.undistortPoints(
                           np.concatenate(self.image_points[side]).reshape(-1,
                                                                           1, 2),
                           calibration.cam_mats[side],
                           calibration.dist_coefs[side],
                           P=calibration.cam_mats[side])
              lines[side] = cv2.computeCorrespondEpilines(undistorted[side],
                                                which_image[side],
                                                calibration.f_mat)
          total_error = 0
          this_side, other_side = sides
          for side in sides:
              for i in range(len(undistorted[side])):
                  total_error += abs(undistorted[this_side][i][0][0] *
                                     lines[other_side][i][0][0] +
                                     undistorted[this_side][i][0][1] *
                                     lines[other_side][i][0][1] +
                                     lines[other_side][i][0][2])
              other_side, this_side = sides
          total_points = self.image_count * len(self.object_points)
          return total_error / total_points
docs: Check calibration quality by computing average reprojection error.
  
          First, undistort detected points and compute epilines for each side.
          Then compute the error between the computed epipolar lines and the
          position of the points detected on the other side for each point and
          return the average error.