# Copyright (c) 2020 Jeff Irion and contributors## This file originated from the `graphslam` package:## https://github.com/JeffLIrion/python-graphslam"""Functions for loading graphs."""import loggingimport numpy as npfrom .edge.edge_odometry import EdgeOdometryfrom .graph import Graphfrom .pose.se2 import PoseSE2from .util import upper_triangular_matrix_to_full_matrixfrom .vertex import Vertex_LOGGER = logging.getLogger(__name__)def load_g2o_se2(infile):"""Load an :math:`SE(2)` graph from a .g2o file.Parameters----------infile : strThe path to the .g2o fileReturns-------GraphThe loaded graph"""edges = []vertices = []with open(infile) as f:for line in f.readlines():if line.startswith("VERTEX_SE2"):numbers = line[10:].split()arr = np.array([float(number) for number in numbers[1:]],dtype=float)p = PoseSE2(arr[:2], arr[2])v = Vertex(int(numbers[0]), p)vertices.append(v)continueif line.startswith("EDGE_SE2"):numbers = line[9:].split()arr = np.array([float(number) for number in numbers[2:]],dtype=float)vertex_ids = [int(numbers[0]), int(numbers[1])]estimate = PoseSE2(arr[:2], arr[2])information = upper_triangular_matrix_to_full_matrix(arr[3:], 3)e = EdgeOdometry(vertex_ids, information, estimate)edges.append(e)continueif line.strip():_LOGGER.warning("Line not supported -- '%s'", line.rstrip())return Graph(edges, vertices)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。