Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
licenseplates
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
licenseplates
Commits
1483eda2
Commit
1483eda2
authored
Dec 09, 2011
by
Gijs van der Voort
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Omzetting van karakters naar zwart wit
parent
0ca94529
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
41 deletions
+66
-41
src/CharacterImageNormalizer.py
src/CharacterImageNormalizer.py
+44
-0
src/GrayscaleImage.py
src/GrayscaleImage.py
+1
-1
src/LetterCropper.py
src/LetterCropper.py
+5
-4
src/LicensePlate.py
src/LicensePlate.py
+16
-2
src/NormalizedCharacterImage.py
src/NormalizedCharacterImage.py
+0
-34
No files found.
src/CharacterImageNormalizer.py
0 → 100644
View file @
1483eda2
from
copy
import
deepcopy
from
GrayscaleImage
import
GrayscaleImage
from
LetterCropper
import
LetterCropper
from
GaussianFilter
import
GaussianFilter
from
numpy
import
resize
,
array
,
append
,
vstack
,
hstack
,
zeros
class
CharacterImageNormalizer
:
def
__init__
(
self
,
size
=
(
60
,
40
),
blur
=
1.1
,
crop_threshold
=
126
):
self
.
size
=
size
self
.
gausse_filter
=
GaussianFilter
(
blur
)
self
.
cropper
=
LetterCropper
(
crop_threshold
)
def
normalize
(
self
,
image
):
self
.
gausse_filter
.
filter
(
image
)
GrayscaleImage
.
resize
(
image
,
(
60
,
60
/
image
.
height
*
image
.
width
))
self
.
increase_contrast
(
image
)
self
.
to_black_white
(
image
,
30
)
self
.
cropper
.
crop_to_letter
(
image
)
self
.
add_padding
(
image
)
def
add_padding
(
self
,
image
):
data
=
array
(
image
.
data
)
top_bottom_padding
=
zeros
((
3
,
data
.
shape
[
1
]))
data
=
vstack
((
top_bottom_padding
,
data
))
data
=
vstack
((
data
,
top_bottom_padding
))
left_right_padding
=
zeros
((
data
.
shape
[
0
],
3
))
data
=
hstack
((
left_right_padding
,
data
))
data
=
hstack
((
data
,
left_right_padding
))
extra_left_padding
=
zeros
((
data
.
shape
[
0
],
data
.
shape
[
0
]
-
data
.
shape
[
1
]))
data
=
hstack
((
extra_left_padding
,
data
))
image
.
data
=
data
def
increase_contrast
(
self
,
image
):
image
.
data
-=
image
.
data
.
min
()
image
.
data
/=
image
.
data
.
max
()
/
255.0
def
to_black_white
(
self
,
image
,
bla
):
for
y
,
x
,
value
in
image
:
image
.
data
[
y
,
x
]
=
255
if
value
<
bla
else
0
\ No newline at end of file
src/GrayscaleImage.py
View file @
1483eda2
src/LetterCropper.py
View file @
1483eda2
from
Rectangle
import
Rectangle
from
Rectangle
import
Rectangle
import
sys
class
LetterCropper
:
class
LetterCropper
:
def
__init__
(
self
,
threshold
=
0.
9
):
def
__init__
(
self
,
threshold
=
0.
5
):
self
.
threshold
=
threshold
self
.
threshold
=
threshold
def
crop_to_letter
(
self
,
image
):
def
crop_to_letter
(
self
,
image
):
...
@@ -17,7 +18,7 @@ class LetterCropper:
...
@@ -17,7 +18,7 @@ class LetterCropper:
max_y
=
0
max_y
=
0
for
y
,
x
,
value
in
self
.
image
:
for
y
,
x
,
value
in
self
.
image
:
if
value
<
self
.
threshold
:
if
value
>
self
.
threshold
:
if
x
<
min_x
:
min_x
=
x
if
x
<
min_x
:
min_x
=
x
if
y
<
min_y
:
min_y
=
y
if
y
<
min_y
:
min_y
=
y
if
x
>
max_x
:
max_x
=
x
if
x
>
max_x
:
max_x
=
x
...
@@ -26,6 +27,6 @@ class LetterCropper:
...
@@ -26,6 +27,6 @@ class LetterCropper:
self
.
letter_bounds
=
Rectangle
(
self
.
letter_bounds
=
Rectangle
(
min_x
,
min_x
,
min_y
,
min_y
,
max_x
-
min_x
,
max_x
-
min_x
+
1
,
max_y
-
min_y
max_y
-
min_y
+
1
)
)
src/LicensePlate.py
View file @
1483eda2
...
@@ -3,11 +3,12 @@ from xml.dom.minidom import parse
...
@@ -3,11 +3,12 @@ from xml.dom.minidom import parse
from
Point
import
Point
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
CharacterImageNormalizer
import
CharacterImageNormalizer
class
LicensePlate
:
class
LicensePlate
:
def
__init__
(
self
,
folder_nr
,
file_nr
):
def
__init__
(
self
,
folder_nr
,
file_nr
):
self
.
character_normalizer
=
CharacterImageNormalizer
(
size
=
(
60
,
40
),
blur
=
1.1
,
crop_threshold
=
125
)
filename
=
'%04d/00991_%04d%02d'
%
(
folder_nr
,
folder_nr
,
file_nr
)
filename
=
'%04d/00991_%04d%02d'
%
(
folder_nr
,
folder_nr
,
file_nr
)
self
.
dom
=
parse
(
'../images/Infos/%s.info'
%
filename
)
self
.
dom
=
parse
(
'../images/Infos/%s.info'
%
filename
)
...
@@ -89,6 +90,17 @@ class LicensePlate:
...
@@ -89,6 +90,17 @@ class LicensePlate:
x2
,
y2
=
corners
[
2
].
to_tuple
()
x2
,
y2
=
corners
[
2
].
to_tuple
()
x3
,
y3
=
corners
[
3
].
to_tuple
()
x3
,
y3
=
corners
[
3
].
to_tuple
()
extra_space
=
3
x0
-=
extra_space
y0
-=
extra_space
x1
+=
extra_space
y1
-=
extra_space
x2
+=
extra_space
y2
+=
extra_space
x3
-=
extra_space
y3
+=
extra_space
M
=
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
)
...
@@ -193,7 +205,9 @@ class LicensePlate:
...
@@ -193,7 +205,9 @@ class LicensePlate:
value
=
self
.
get_node
(
"char"
,
character
).
firstChild
.
data
value
=
self
.
get_node
(
"char"
,
character
).
firstChild
.
data
corners
=
self
.
get_corners
(
character
)
corners
=
self
.
get_corners
(
character
)
data
=
self
.
retrieve_data
(
corners
)
data
=
self
.
retrieve_data
(
corners
)
image
=
NormalizedCharacterImage
(
data
=
data
)
image
=
GrayscaleImage
(
data
=
data
)
self
.
character_normalizer
.
normalize
(
image
)
self
.
characters
.
append
(
Character
(
value
,
corners
,
image
))
self
.
characters
.
append
(
Character
(
value
,
corners
,
image
))
else
:
else
:
...
...
src/NormalizedCharacterImage.py
deleted
100644 → 0
View file @
0ca94529
from
copy
import
deepcopy
from
GrayscaleImage
import
GrayscaleImage
from
LetterCropper
import
LetterCropper
from
GaussianFilter
import
GaussianFilter
class
NormalizedCharacterImage
(
GrayscaleImage
):
def
__init__
(
self
,
image
=
None
,
data
=
None
,
size
=
(
60
,
40
),
blur
=
1.1
,
crop_threshold
=
0.9
):
if
image
!=
None
:
GrayscaleImage
.
__init__
(
self
,
data
=
deepcopy
(
image
.
data
))
elif
data
!=
None
:
GrayscaleImage
.
__init__
(
self
,
data
=
deepcopy
(
data
))
self
.
blur
=
blur
self
.
crop_threshold
=
crop_threshold
self
.
size
=
size
self
.
gausse_filter
()
self
.
increase_contrast
()
self
.
crop_to_letter
()
self
.
resize
()
def
increase_contrast
(
self
):
self
.
data
-=
self
.
data
.
min
()
self
.
data
/=
self
.
data
.
max
()
def
gausse_filter
(
self
):
filter
=
GaussianFilter
(
1.1
)
filter
.
filter
(
self
)
def
crop_to_letter
(
self
):
cropper
=
LetterCropper
(
0.9
)
cropper
.
crop_to_letter
(
self
)
def
resize
(
self
):
GrayscaleImage
.
resize
(
self
,
self
.
size
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment