def __init__(self, camera_model, intrinsics, dist_model, dist_coeff, resolution): #setup the aslam camera if camera_model == 'pinhole': focalLength = intrinsics[0:2] principalPoint = intrinsics[2:4] if dist_model == 'radtan': dist = cv.RadialTangentialDistortion(dist_coeff[0], dist_coeff[1], dist_coeff[2], dist_coeff[3]) proj = cv.DistortedPinholeProjection( focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.DistortedPinholeCameraGeometry(proj) self.frameType = cv.DistortedPinholeFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.DistortedPinholeReprojectionErrorSimple self.undistorterType = cv.PinholeUndistorterNoMask elif dist_model == 'equidistant': dist = cv.EquidistantDistortion(dist_coeff[0], dist_coeff[1], dist_coeff[2], dist_coeff[3]) proj = cv.EquidistantPinholeProjection( focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.EquidistantDistortedPinholeCameraGeometry( proj) self.frameType = cv.EquidistantDistortedPinholeFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.EquidistantDistortedPinholeReprojectionErrorSimple self.undistorterType = cv.EquidistantPinholeUndistorterNoMask elif dist_model == 'fov': dist = cv.FovDistortion(dist_coeff[0]) proj = cv.FovPinholeProjection(focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.FovDistortedPinholeCameraGeometry(proj) self.frameType = cv.FovDistortedPinholeFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.FovDistortedPinholeReprojectionErrorSimple self.undistorterType = cv.FovPinholeUndistorterNoMask elif dist_model == 'none': proj = cv.PinholeProjection(focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1]) self.camera = cv.PinholeCameraGeometry(proj) self.frameType = cv.PinholeFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.PinholeReprojectionErrorSimple else: self.raiseError( "pinhole camera model does not support distortion model '{}'" .format(dist_model)) elif camera_model == 'omni': xi_omni = intrinsics[0] focalLength = intrinsics[1:3] principalPoint = intrinsics[3:5] if dist_model == 'radtan': dist = cv.RadialTangentialDistortion(dist_coeff[0], dist_coeff[1], dist_coeff[2], dist_coeff[3]) proj = cv.DistortedOmniProjection( xi_omni, focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.DistortedOmniCameraGeometry(proj) self.frameType = cv.DistortedOmniFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.DistortedOmniReprojectionErrorSimple self.undistorterType = cv.OmniUndistorterNoMask elif dist_model == 'equidistant': raise RuntimeError( "Omni with equidistant model not yet supported!") dist = cv.EquidistantPinholeProjection(dist_coeff[0], dist_coeff[1], dist_coeff[2], dist_coeff[3]) proj = cv.EquidistantOmniProjection( xi_omni, focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.EquidistantDistortedOmniCameraGeometry(proj) self.frameType = cv.DistortedOmniFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.EquidistantDistortedOmniReprojectionErrorSimple elif dist_model == 'none': proj = cv.OmniProjection(xi_omni, focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1]) self.geometry = cv.OmniCameraGeometry(proj) self.frameType = cv.OmniFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.OmniReprojectionErrorSimple else: raise RuntimeError( "omni camera model does not support distortion model '{}'". format(dist_model)) elif camera_model == 'eucm': alpha_uni = intrinsics[0] beta_uni = intrinsics[1] focalLength = intrinsics[2:4] principalPoint = intrinsics[4:6] if dist_model == 'none': proj = cv.ExtendedUnifiedProjection( alpha_uni, beta_uni, focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1]) self.geometry = cv.ExtendedUnifiedCameraGeometry(proj) self.frameType = cv.ExtendedUnifiedFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.ExtendedUnifiedReprojectionErrorSimple else: raise RuntimeError( "camera model {} does not support distortion model '{}'". format(camera_model, dist_model)) elif camera_model == 'ds': xi_ds = intrinsics[0] alpha_ds = intrinsics[1] focalLength = intrinsics[2:4] principalPoint = intrinsics[4:6] if dist_model == 'none': proj = cv.DoubleSphereProjection(xi_ds, alpha_ds, focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1]) self.geometry = cv.DoubleSphereCameraGeometry(proj) self.frameType = cv.DoubleSphereFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.DoubleSphereReprojectionErrorSimple else: raise RuntimeError( "camera model {} does not support distortion model '{}'". format(camera_model, dist_model)) else: raise RuntimeError( "Unknown camera model '{}'".format(camera_model))
def __init__(self, camera_model, intrinsics, dist_model, dist_coeff, resolution): #setup the aslam camera if camera_model == 'pinhole': focalLength = intrinsics[0:2] principalPoint = intrinsics[2:4] if dist_model == 'radtan': dist = cv.RadialTangentialDistortion(dist_coeff[0], dist_coeff[1], dist_coeff[2], dist_coeff[3]) proj = cv.DistortedPinholeProjection( focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.DistortedPinholeCameraGeometry(proj) self.frameType = cv.DistortedPinholeFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.DistortedPinholeReprojectionErrorSimple self.undistorterType = cv.PinholeUndistorterNoMask elif dist_model == 'equidistant': dist = cv.EquidistantDistortion(dist_coeff[0], dist_coeff[1], dist_coeff[2], dist_coeff[3]) proj = cv.EquidistantPinholeProjection( focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.EquidistantDistortedPinholeCameraGeometry( proj) self.frameType = cv.EquidistantDistortedPinholeFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.EquidistantDistortedPinholeReprojectionErrorSimple self.undistorterType = cv.EquidistantPinholeUndistorterNoMask elif dist_model == 'fov': dist = cv.FovDistortion(dist_coeff[0]) proj = cv.FovPinholeProjection(focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.FovDistortedPinholeCameraGeometry(proj) self.frameType = cv.FovDistortedPinholeFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.FovDistortedPinholeReprojectionErrorSimple self.undistorterType = cv.FovPinholeUndistorterNoMask else: proj = cv.PinholeProjection(focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1]) self.camera = cv.PinholeCameraGeometry(proj) self.frameType = cv.PinholeFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.PinholeReprojectionErrorSimple elif camera_model == 'omni': xi_omni = intrinsics[0] focalLength = intrinsics[1:3] principalPoint = intrinsics[3:5] if dist_model == 'radtan': dist = cv.RadialTangentialDistortion(dist_coeff[0], dist_coeff[1], dist_coeff[2], dist_coeff[3]) proj = cv.DistortedOmniProjection( xi_omni, focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.DistortedOmniCameraGeometry(proj) self.frameType = cv.DistortedOmniFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.DistortedOmniReprojectionErrorSimple self.undistorterType = cv.OmniUndistorterNoMask elif dist_model == 'equidistant': print "Omni with equidistant model not yet supported!" sys.exit(0) dist = cv.EquidistantPinholeProjection(dist_coeff[0], dist_coeff[1], dist_coeff[2], dist_coeff[3]) proj = cv.EquidistantOmniProjection( xi_omni, focalLength[0], focalLength[1], principalPoint[0], principalPoint[1], resolution[0], resolution[1], dist) self.geometry = cv.EquidistantDistortedOmniCameraGeometry(proj) self.frameType = cv.DistortedOmniFrame self.keypointType = cv.Keypoint2 self.reprojectionErrorType = cvb.EquidistantDistortedOmniReprojectionErrorSimple elif dist_model == 'none': self.raiseError( "camera model omni needs a distortion model! (none is invalid)" ) else: self.raiseError("Unknown camera model")