def parse_rec(filename):
 tree = ET.parse(filename)
 objects = []
 for obj in tree.findall('object'):
  obj_struct = {}
  obj_struct['name'] = obj.find('name').text
  obj_struct['pose'] = obj.find('pose').text
  obj_struct['truncated'] = int(obj.find('truncated').text)
  obj_struct['difficult'] = int(obj.find('difficult').text)
  bbox = obj.find('bndbox')
  obj_struct['bbox'] = [int(bbox.find('xmin').text), int(bbox.find('ymin').text), int(bbox.find('xmax').text), int(bbox.find('ymax').text)]
  objects.append(obj_struct)
 return objects

def parse_rec ( filename ) : tree = ET . parse ( filename ) objects = [ ] for obj in tree . findall ( 'object' ) : obj_struct = { } obj_struct [ 'name' ] = obj . find ( 'name' ) . text obj_struct [ 'pose' ] = obj . find ( 'pose' ) . text obj_struct [ 'truncated' ] = int ( obj . find ( 'truncated' ) . text ) obj_struct [ 'difficult' ] = int ( obj . find ( 'difficult' ) . text ) bbox = obj . find ( 'bndbox' ) obj_struct [ 'bbox' ] = [ int ( bbox . find ( 'xmin' ) . text ) , int ( bbox . find ( 'ymin' ) . text ) , int ( bbox . find ( 'xmax' ) . text ) , int ( bbox . find ( 'ymax' ) . text ) ] objects . append ( obj_struct ) return objects
parse a pascal voc xml file .