Search
 
SCRIPT & CODE EXAMPLE
 

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')```
Comment

PREVIOUS NEXT
Code Example
Python :: python get currentmonth 
Python :: continue loop django template 
Python :: Python Anagram Using sorted() function 
Python :: modern ui python 
Python :: Find Factors of a Number Using for Loop 
Python :: Python Switch case statement using if-elif-else 
Python :: PHP echo multi lines Using Heredoc variable 
Python :: Math Module atan() Function in python 
Python :: how to return and use a single object in custom template filters django 
Python :: ascii julius caesar python encryption 
Python :: Example of importing module in python 
Python :: python comment faire une boucle 
Python :: python convert dataframe target to numbers 
Python :: catkin_make ignore pkg 
Python :: transfer learning in python with custom dataset 
Python :: How to find text of h2 tag in python requests-html 
Python :: Python NumPy transpose Function Example in one line of code 
Python :: df create dummy from multiple category 
Python :: Python NumPy asarray Function Example list to array 
Python :: Python NumPy dstack Function Syntax 
Python :: How can I Duplicate 1 Dimensional array 
Python :: codeforces problem 580A 
Python :: NumPy rot90 Example Rotating Once 
Python :: colorbar over two axes 
Python :: django check for empty onetoone exists 
Python :: if not isinstance multiple values 
Python :: Double all numbers using a map() Function 
Python :: Use one function for the "ComboboxSelected", to read multiple combobox 
Python :: fetch inbox mail python 
Python :: python if corto 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =