Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Converts xml annotation file into required text format training data" #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions xml_to_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import xml.etree.ElementTree as ET
import os


images_path="./Images/" # Add path of labelled images
xml_path='/Annotations/' # add images xml file path



print("Converting images")
for file in os.listdir(xml_path):


root = ET.parse(xml_path+'/'+file)
#image_name=root.find("filename").text
for elem in root.iter():

if 'filename' in elem.tag:
image_name=elem.text
if 'object' in elem.tag:
for attr in list(elem):
#print(attr)
if 'name' in attr.tag:
object_name=attr.text

if 'bndbox' in attr.tag:
for dim in list(attr):
if 'xmin' in dim.tag:
xmin=dim.text

if 'ymin' in dim.tag:
ymin=dim.text

if 'xmax' in dim.tag:
xmax=dim.text

if 'ymax' in dim.tag:
ymax=dim.text
data=images_path+image_name+"," +xmin+','+ ymin +',' + xmax + ","+ ymax + ","+ object_name

with open("test.txt", "a") as myfile:
myfile.write(data+"\n")
print("finished")