map_parser.py
Go to the documentation of this file.
1 # ArUco map parser (should be kept in sync with aruco_pose)
2 
3 from .marker import Marker
4 
5 
6 def _parse_line(line):
7  '''
8  Parse a line of map data, returning a Marker object if
9  parsing succeeded, or None if it failed.
10  '''
11  if line.startswith('#'):
12  return None
13  elems = line.split()
14  if len(elems) < 4:
15  return None
16  try:
17  id_ = int(elems[0])
18  size = float(elems[1])
19  x = float(elems[2])
20  y = float(elems[3])
21  z = float(elems[4]) if len(elems) > 4 else 0
22  yaw = float(elems[5]) if len(elems) > 5 else 0
23  pitch = float(elems[6]) if len(elems) > 6 else 0
24  roll = float(elems[7]) if len(elems) > 7 else 0
25  except:
26  print('Warning - marformed line: {}'.format(line, sys.exc_info()[0]))
27  return None
28  return Marker(id_, size, x, y, z, roll, pitch, yaw)
29 
30 
31 def parse(map_path):
32  '''
33  Parse a map at a given path.
34 
35  map_path: Path to the ArUco map file.
36 
37  Returns a list of Marker objects.
38  '''
39  markers = []
40  with open(map_path, 'r') as map_contents:
41  for line in map_contents.readlines():
42  parser_result = _parse_line(line)
43  if parser_result is not None:
44  markers.append(parser_result)
45  return markers


clover_simulation
Author(s): Alexey Rogachevskiy, Andrey Ryabov, Arthur Golubtsov, Oleg Kalachev, Svyatoslav Zhuravlev
autogenerated on Mon Feb 28 2022 22:08:36