Beispiel #1
0
 def test_xml(self):
     """
     Test conversion to and from xml.  This is just a basic functionality
     test of a round trip from Box3d to xml and back.
     """
     box = Box3d(corner1=Vector3(1.5, 2.6, 3.7),
                 corner2=Vector3(5.1, 6.2, 7.9))
     box_xml = box.to_xml()
     assert (box_xml.tag == 'box3d')
     box_rt = Box3d.from_xml(box_xml)
     assert (box.almost_equal(box_rt))
Beispiel #2
0
    def _parse_xml(base_elem):
        """
        Parse the xml of an <element> tag, extracting the ProjectObject attributes.

        Inputs:
        base_elem (ET.Element) - An Element with tag "element" and appropriate
            sub-elements.

        Return:
        tuple (id, pose, category, bounds, symmetry, score, evaluated)
        ProjectObject attributes (see constructor for details).

        Exceptions:
        ValueError - If base_elem is not <element> or if none of its children is <id>.
        """
        # verify base_elem tag is 'element'
        if base_elem.tag != "element":
            raise ValueError('Expected tag to be "element"')

        # defaults
        proxy = ProjectObject(1)
        category = proxy.category
        pose = proxy.pose
        symmetry = proxy.symmetry
        score = proxy.score
        evaluated = proxy.evaluated

        for elem in base_elem:
            if elem.tag == "id":
                id = elem.text
            elif elem.tag == "pose":
                pose = Pose3.from_xml(elem)
            elif elem.tag == "category":
                category = elem.text
            elif (elem.tag == "bounds"):
                # Note: Boxe3d.from_xml expects tag to be 'box3d'
                elem_temp = deepcopy(elem)
                elem_temp.tag = "box3d"
                bounds = Box3d.from_xml(elem_temp)
            elif elem.tag == "symmetry":
                symmetry = ObjectSymmetry.from_xml(elem)
            elif elem.tag == "detectionScore":
                score = float(elem.text)
            elif elem.tag == "evaluated":
                evaluated = bool(elem.text)

        if id is None:
            raise ValueError("XML is missing required <id> tag.")

        return (id, pose, category, bounds, symmetry, score, evaluated)