Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
licenseplates
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Taddeüs Kroes
licenseplates
Commits
26c8385b
Commit
26c8385b
authored
13 years ago
by
Fabien
Browse files
Options
Downloads
Patches
Plain Diff
.. xml helper functies WEER terug
parent
cc09b784
No related branches found
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
src/xml_helper_functions.py
+71
-91
71 additions, 91 deletions
src/xml_helper_functions.py
with
71 additions
and
91 deletions
src/xml_helper_functions.py
+
71
−
91
View file @
26c8385b
from
os
import
mkdir
from
os
import
mkdir
from
os.path
import
exists
from
os.path
import
exists
from
pylab
import
array
,
zeros
,
inv
,
dot
,
svd
,
floor
from
pylab
import
imsave
,
array
,
zeros
,
inv
,
dot
,
norm
,
svd
,
floor
from
xml.dom.minidom
import
parse
from
xml.dom.minidom
import
parse
from
Point
import
Point
from
Character
import
Character
from
Character
import
Character
from
GrayscaleImage
import
GrayscaleImage
from
GrayscaleImage
import
GrayscaleImage
from
NormalizedCharacterImage
import
NormalizedCharacterImage
from
NormalizedCharacterImage
import
NormalizedCharacterImage
from
LicensePlate
import
LicensePlate
from
LicensePlate
import
LicensePlate
# sets the entire license plate of an image
# Gets the character data from a picture with a license plate
def
retrieve_data
(
image
,
corners
):
def
retrieve_data
(
plate
,
corners
):
x0
,
y0
=
corners
[
0
].
to_tuple
()
x0
,
y0
,
x1
,
y1
,
x2
,
y2
,
x3
,
y3
=
corners
x1
,
y1
=
corners
[
1
].
to_tuple
()
x2
,
y2
=
corners
[
2
].
to_tuple
()
x3
,
y3
=
corners
[
3
].
to_tuple
()
M
=
int
(
1.2
*
(
max
(
x0
,
x1
,
x2
,
x3
)
-
min
(
x0
,
x1
,
x2
,
x3
)
))
M
=
max
(
x0
,
x1
,
x2
,
x3
)
-
min
(
x0
,
x1
,
x2
,
x3
)
N
=
max
(
y0
,
y1
,
y2
,
y3
)
-
min
(
y0
,
y1
,
y2
,
y3
)
N
=
max
(
y0
,
y1
,
y2
,
y3
)
-
min
(
y0
,
y1
,
y2
,
y3
)
matrix
=
array
([
matrix
=
array
([
...
@@ -29,7 +25,7 @@ def retrieve_data(image, corners):
...
@@ -29,7 +25,7 @@ def retrieve_data(image, corners):
[
0
,
0
,
0
,
x3
,
y3
,
1
,
-
N
*
x3
,
-
N
*
y3
,
-
N
]
[
0
,
0
,
0
,
x3
,
y3
,
1
,
-
N
*
x3
,
-
N
*
y3
,
-
N
]
])
])
P
=
inv
(
get_transformation_matrix
(
matrix
)
)
P
=
get_transformation_matrix
(
matrix
)
data
=
array
([
zeros
(
M
,
float
)]
*
N
)
data
=
array
([
zeros
(
M
,
float
)]
*
N
)
for
i
in
range
(
M
):
for
i
in
range
(
M
):
...
@@ -38,7 +34,7 @@ def retrieve_data(image, corners):
...
@@ -38,7 +34,7 @@ def retrieve_data(image, corners):
or_coor_h
=
(
or_coor
[
1
][
0
]
/
or_coor
[
2
][
0
],
or_coor_h
=
(
or_coor
[
1
][
0
]
/
or_coor
[
2
][
0
],
or_coor
[
0
][
0
]
/
or_coor
[
2
][
0
])
or_coor
[
0
][
0
]
/
or_coor
[
2
][
0
])
data
[
j
][
i
]
=
pV
(
imag
e
,
or_coor_h
[
0
],
or_coor_h
[
1
])
data
[
j
][
i
]
=
pV
(
plat
e
,
or_coor_h
[
0
],
or_coor_h
[
1
])
return
data
return
data
...
@@ -50,108 +46,92 @@ def get_transformation_matrix(matrix):
...
@@ -50,108 +46,92 @@ def get_transformation_matrix(matrix):
U
,
D
,
V
=
svd
(
matrix
)
U
,
D
,
V
=
svd
(
matrix
)
p
=
V
[
8
][:]
p
=
V
[
8
][:]
return
array
([
return
inv
(
array
([[
p
[
0
],
p
[
1
],
p
[
2
]],
[
p
[
3
],
p
[
4
],
p
[
5
]],
[
p
[
6
],
p
[
7
],
p
[
8
]]]))
[
p
[
0
],
p
[
1
],
p
[
2
]
],
[
p
[
3
],
p
[
4
],
p
[
5
]
],
[
p
[
6
],
p
[
7
],
p
[
8
]
]
])
def
pV
(
image
,
x
,
y
):
def
pV
(
image
,
x
,
y
):
#Get the value of a point (interpolated x, y) in the given image
#Get the value of a point (interpolated x, y) in the given image
if
image
.
in_bounds
(
x
,
y
):
if
not
image
.
in_bounds
(
x
,
y
):
x_low
=
floor
(
x
)
return
0
x_high
=
floor
(
x
+
1
)
y_low
=
floor
(
y
)
y_high
=
floor
(
y
+
1
)
x_y
=
(
x_high
-
x_low
)
*
(
y_high
-
y_low
)
a
=
x_high
-
x
x_low
,
x_high
=
floor
(
x
),
floor
(
x
+
1
)
b
=
y_high
-
y
y_low
,
y_high
=
floor
(
y
),
floor
(
y
+
1
)
c
=
x
-
x_low
x_y
=
(
x_high
-
x_low
)
*
(
y_high
-
y_low
)
d
=
y
-
y_low
return
image
[
x_low
,
y_low
]
/
x_y
*
a
*
b
\
a
=
x_high
-
x
+
image
[
x_high
,
y_low
]
/
x_y
*
c
*
b
\
b
=
y_high
-
y
+
image
[
x_low
,
y_high
]
/
x_y
*
a
*
d
\
c
=
x
-
x_low
+
image
[
x_high
,
y_high
]
/
x_y
*
c
*
d
d
=
y
-
y_low
return
0
return
image
[
x_low
,
y_low
]
/
x_y
*
a
*
b
\
+
image
[
x_high
,
y_low
]
/
x_y
*
c
*
b
\
+
image
[
x_low
,
y_high
]
/
x_y
*
a
*
d
\
+
image
[
x_high
,
y_high
]
/
x_y
*
c
*
d
def
xml_to_LicensePlate
(
filename
,
save_character
=
None
):
def
xml_to_LicensePlate
(
filename
,
save_character
=
None
):
image
=
GrayscaleImage
(
'
../images/Images/%s.jpg
'
%
filename
)
plate
=
GrayscaleImage
(
'
../images/Images/%s.jpg
'
%
filename
)
dom
=
parse
(
'
../images/Infos/%s.info
'
%
filename
)
dom
=
parse
(
'
../images/Infos/%s.info
'
%
filename
)
result_characters
=
[]
country
=
''
result
=
[]
version
=
dom
.
getElementsByTagName
(
"
current-version
"
)[
0
].
firstChild
.
data
version
=
get_node
(
dom
,
"
current-version
"
)
info
=
dom
.
getElementsByTagName
(
"
info
"
)
info
s
=
by_tag
(
dom
,
"
info
"
)
for
i
in
info
:
for
info
in
infos
:
if
version
==
i
.
getElementsByTagName
(
"
version
"
)[
0
].
firstChild
.
data
:
if
not
version
==
get_node
(
info
,
"
version
"
):
continue
country
=
i
.
get
ElementsByTagName
(
"
identification-letters
"
)
[
0
].
firstChild
.
data
country
=
get
_node
(
info
,
"
identification-letters
"
)
temp
=
i
.
getElementsByTagName
(
"
characters
"
)
temp
=
by_tag
(
info
,
"
characters
"
)
if
len
(
temp
):
if
not
temp
:
# no characters where found in the file
characters
=
temp
[
0
].
childNodes
break
else
:
characters
=
[]
break
for
i
,
character
in
enumerate
(
characters
):
characters
=
temp
[
0
].
childNodes
if
character
.
nodeName
==
"
character
"
:
value
=
character
.
getElementsByTagName
(
"
char
"
)[
0
].
firstChild
.
data
corners
=
get_corners
(
character
)
if
not
len
(
corners
)
==
4
:
for
i
,
char
in
enumerate
(
characters
):
break
if
not
char
.
nodeName
==
"
character
"
:
continue
character_data
=
r
et
rieve_data
(
image
,
corners
)
value
=
g
et
_node
(
char
,
"
char
"
)
character_image
=
NormalizedCharacterImage
(
data
=
character_data
)
corners
=
get_corners
(
char
)
result_characters
.
append
(
Character
(
value
,
corners
,
character_image
,
filename
))
if
not
len
(
corners
)
==
8
:
break
if
save_character
:
data
=
retrieve_data
(
plate
,
corners
)
single_character
=
GrayscaleImage
(
data
=
character_data
)
image
=
NormalizedCharacterImage
(
data
=
data
)
result
.
append
(
Character
(
value
,
corners
,
image
,
filename
))
if
save_character
:
character_image
=
GrayscaleImage
(
data
=
data
)
path
=
"
../images/LearningSet/%s
"
%
value
image_path
=
"
%s/%d_%s.jpg
"
%
(
path
,
i
,
filename
.
split
(
'
/
'
)[
-
1
])
path
=
"
../images/LearningSet/%s
"
%
value
if
not
exists
(
path
):
image_path
=
"
%s/%d_%s.jpg
"
%
(
path
,
i
,
filename
.
split
(
'
/
'
)[
-
1
]
)
mkdir
(
path
)
if
not
exists
(
path
):
if
not
exists
(
image_
path
):
mkdir
(
path
)
character_image
.
save
(
image_
path
)
if
not
exists
(
image_path
):
return
LicensePlate
(
country
,
result
)
single_character
.
save
(
image_path
)
return
LicensePlate
(
country
,
result_characters
)
def
get_node
(
node
,
tag
):
return
by_tag
(
node
,
tag
)[
0
].
firstChild
.
data
def
get_corners
(
dom
):
nodes
=
dom
.
getElementsByTagName
(
"
point
"
)
corners
=
[]
margin_y
=
3
def
by_tag
(
node
,
tag
):
margin_x
=
2
return
node
.
getElementsByTagName
(
tag
)
corners
.
append
(
def
get_attr
(
node
,
attr
):
Point
(
get_coord
(
nodes
[
0
],
"
x
"
)
-
margin_x
,
return
int
(
node
.
getAttribute
(
attr
))
get_coord
(
nodes
[
0
],
"
y
"
)
-
margin_y
)
)
corners
.
append
(
def
get_corners
(
dom
):
Point
(
get_coord
(
nodes
[
1
],
"
x
"
)
+
margin_x
,
p
=
by_tag
(
dom
,
"
point
"
)
get_coord
(
nodes
[
1
],
"
y
"
)
-
margin_y
)
)
corners
.
append
(
Point
(
get_coord
(
nodes
[
2
],
"
x
"
)
+
margin_x
,
get_coord
(
nodes
[
2
],
"
y
"
)
+
margin_y
)
)
corners
.
append
(
Point
(
get_coord
(
nodes
[
3
],
"
x
"
)
-
margin_x
,
get_coord
(
nodes
[
3
],
"
y
"
)
+
margin_y
)
)
return
corners
# Extra padding
y
=
3
x
=
2
def
get_coord
(
node
,
attribute
):
# return 8 values (x0,y0, .., x3,y3)
return
int
(
node
.
getAttribute
(
attribute
))
return
get_attr
(
p
[
0
],
"
x
"
)
-
x
,
get_attr
(
p
[
0
],
"
y
"
)
-
y
,
\
get_attr
(
p
[
1
],
"
x
"
)
+
x
,
get_attr
(
p
[
1
],
"
y
"
)
-
y
,
\
get_attr
(
p
[
2
],
"
x
"
)
+
x
,
get_attr
(
p
[
2
],
"
y
"
)
+
y
,
\
get_attr
(
p
[
3
],
"
x
"
)
-
x
,
get_attr
(
p
[
3
],
"
y
"
)
+
y
\ No newline at end of file
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