Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

extracting bounding box from xml file python

import xml.etree.ElementTree as ET

def extract_boxes(filename):        
    # load and parse the file
    tree = ET.parse(filename)
    # get the root of the document
    root = tree.getroot()
    # extract each bounding box
    boxes = list()
    for box in root.findall('.//bndbox'):
        xmin = int(box.find('xmin').text)
        ymin = int(box.find('ymin').text)
        xmax = int(box.find('xmax').text)
        ymax = int(box.find('ymax').text)
        coors = [xmin, ymin, xmax, ymax]
        boxes.append(coors)
        
    # extract image dimensions
    width = int(root.find('.//size/width').text)
    height = int(root.find('.//size/height').text)
    return boxes, width, height


bbs = extract_boxes(r'C:UserszleslDesktopkangaroo-masterannots0001.xml')```
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #extracting #bounding #box #xml #file #python
ADD COMMENT
Topic
Name
3+3 =