Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
segmentation-pytorch
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Norbert Fischer
segmentation-pytorch
Commits
aa7eb15b
Commit
aa7eb15b
authored
4 years ago
by
Alexander Hartelt
Browse files
Options
Downloads
Patches
Plain Diff
removed image extension form xml filename and changed id generation for xml tags
parent
4019e618
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
segmentation/gui/xml_util.py
+6
-4
6 additions, 4 deletions
segmentation/gui/xml_util.py
with
6 additions
and
4 deletions
segmentation/gui/xml_util.py
+
6
−
4
View file @
aa7eb15b
import
itertools
import
os
from
typing
import
Tuple
,
List
import
math
...
...
@@ -67,6 +68,9 @@ class XMLGenerator:
creates the xml to the given baselines
:return: xml-string of baselines
"""
def
make_id_gen
(
identifier
):
return
map
(
lambda
x
:
f
"
{
identifier
}{
x
}
"
,
itertools
.
count
(
start
=
1
))
textline_id_gen
=
make_id_gen
(
"
TextLine
"
)
xmlns_uris
=
{
'
pc
'
:
'
http://schema.primaresearch.org/PAGE/gts/pagecontent/2017-07-15
'
}
attr_qname
=
ET
.
QName
(
"
http://www.w3.org/2001/XMLSchema-instance
"
,
"
schemaLocation
"
)
root_node
=
ET
.
Element
(
"
PcGts
"
,
{
...
...
@@ -84,11 +88,9 @@ class XMLGenerator:
ET
.
SubElement
(
tr_node
,
"
Coords
"
,
points
=
coords_to_string
(
t
.
coords
))
for
i_ind
,
i
in
enumerate
(
t
.
textLines
):
# ET.SubElement(tr_node, "Coords", points=self.coords_to_string(region.coords))
tl_node
=
ET
.
SubElement
(
tr_node
,
"
TextLine
"
,
id
=
"
TextLine
"
)
tl_node
=
ET
.
SubElement
(
tr_node
,
"
TextLine
"
,
id
=
next
(
textline_id_gen
))
ET
.
SubElement
(
tl_node
,
"
Coords
"
,
points
=
coords_to_string
(
i
.
coords
))
ET
.
SubElement
(
tl_node
,
"
Baseline
"
,
points
=
coords_to_string
(
i
.
baseline
.
coords
))
# annotate_with_XMLNS_prefixes(root_node, "pc", False)
return
minidom
.
parseString
(
ET
.
tostring
(
root_node
)).
toprettyxml
(
indent
=
'
'
)
def
save_textregions_as_xml
(
self
,
output_path
:
str
):
...
...
@@ -96,7 +98,7 @@ class XMLGenerator:
Transform textregions to xml and save it to output_path
:param output_path:
"""
complete_name
=
os
.
path
.
join
(
output_path
,
self
.
imageFilename
+
"
.xml
"
)
complete_name
=
os
.
path
.
join
(
output_path
,
self
.
imageFilename
.
split
(
"
.
"
)[
0
]
+
"
.xml
"
)
# remove .image extensions from filename
output_string
=
self
.
baselines_to_xml_string
()
file
=
open
(
complete_name
,
"
w
"
)
file
.
write
(
output_string
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment