Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
zesje
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Show more breadcrumbs
Works on my machine
zesje
Commits
0d640374
Commit
0d640374
authored
5 years ago
by
RABijl
Browse files
Options
Downloads
Patches
Plain Diff
adds scale function and applies it to test rot and pipeline
parent
f1abb25c
No related branches found
Branches containing commit
No related tags found
1 merge request
!28
combine precise positioning with pregrading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_scans.py
+29
-18
29 additions, 18 deletions
tests/test_scans.py
with
29 additions
and
18 deletions
tests/test_scans.py
+
29
−
18
View file @
0d640374
...
...
@@ -181,6 +181,13 @@ def apply_scan(img, rotation=0, scale=1, skew=(0, 0)):
return
dst
.
convert
(
"
RGB
"
)
def
upscale_image
(
image
,
scale
=
2
):
width
,
height
=
image
.
size
scale
=
2
# so 72*2=144 dpi
new_size
=
(
int
(
scale
*
width
),
int
(
scale
*
height
))
image
=
image
.
resize
(
new_size
,
resample
=
1
)
return
image
# Pipeline tests:
# General strucuture:
# 1. Make/clean Database
...
...
@@ -194,6 +201,7 @@ def apply_scan(img, rotation=0, scale=1, skew=(0, 0)):
def
test_pipeline
(
new_exam
,
datadir
):
genPDF
=
generate_pdf
(
new_exam
,
5
)
for
image
in
makeImage
(
genPDF
):
image
=
upscale_image
(
image
)
success
,
reason
=
scans
.
process_page
(
image
,
new_exam
,
datadir
)
assert
success
is
True
,
reason
...
...
@@ -215,13 +223,14 @@ def test_noise(new_exam, datadir, threshold, expected):
(
-
2
,
True
),
(
0.5
,
True
),
(
0.8
,
True
),
(
2
,
Fals
e
)],
ids
=
[
'
Large rot
'
,
'
Small rot
'
,
'
Medium rot
'
,
'
failing
rot
'
])
(
2
,
Tru
e
)],
ids
=
[
'
Large rot
'
,
'
Small rot
'
,
'
Medium rot
'
,
'
Large counterclockwise
rot
'
])
def
test_rotate
(
new_exam
,
datadir
,
rotation
,
expected
):
genPDF
=
generate_pdf
(
new_exam
,
1
)
for
image
in
makeImage
(
genPDF
):
image
=
upscale_image
(
image
,
scale
=
2
)
image
=
apply_scan
(
img
=
image
,
rotation
=
rotation
)
#
image.show()
# image.show()
success
,
reason
=
scans
.
process_page
(
image
,
new_exam
,
datadir
)
assert
success
is
expected
,
reason
...
...
@@ -283,39 +292,41 @@ def test_image_extraction(datadir, filename):
assert
page
==
2
@pytest.mark.parametrize
(
'
file_name
'
,
[
"
a4-rotated.png
"
,
"
a4-3-markers.png
"
,
"
a4-rotated-3-markers.png
"
])
def
test_realign_image
(
datadir
,
file_name
):
@pytest.mark.parametrize
(
'
file_name, markers
'
,
[(
"
a4-rotated.png
"
,
[(
59
,
59
),
(
1181
,
59
),
(
59
,
1695
),
(
1181
,
1695
)]),
(
"
a4-3-markers.png
"
,
[(
1181
,
59
),
(
59
,
1695
),
(
1181
,
1695
)]),
(
"
a4-rotated-3-markers.png
"
,
[(
1181
,
59
),
(
59
,
1695
),
(
1181
,
1695
)])
])
def
test_realign_image
(
datadir
,
file_name
,
markers
):
dir_name
=
"
cornermarkers
"
epsilon
=
1
test_file
=
os
.
path
.
join
(
datadir
,
dir_name
,
file_name
)
test_image
=
np
.
array
(
PIL
.
Image
.
open
(
test_file
))
correct_corner_markers
=
[(
59
,
59
),
(
1181
,
59
),
(
59
,
1695
),
(
1181
,
1695
)]
result_image
,
result_corner_markers
=
scans
.
realign_image
(
test_image
)
result_image
=
scans
.
realign_image
(
test_image
)
result_corner_markers
=
scans
.
find_corner_marker_keypoints
(
result_image
)
assert
result_corner_markers
is
not
None
for
i
in
range
(
4
):
diff
=
np
.
absolute
(
np
.
subtract
(
correct_corner_
markers
[
i
],
result_corner_markers
[
i
]))
for
i
in
range
(
len
(
markers
)
):
diff
=
np
.
absolute
(
np
.
subtract
(
markers
[
i
],
result_corner_markers
[
i
]))
assert
diff
[
0
]
<=
epsilon
assert
diff
[
1
]
<=
epsilon
def
test_incomplete_reference_realign_image
(
datadir
):
dir_name
=
"
cornermarkers
"
epsilon
=
2
test_file
=
os
.
path
.
join
(
datadir
,
dir_name
,
"
a4-rotated
-3-markers
.png
"
)
epsilon
=
1
test_file
=
os
.
path
.
join
(
datadir
,
dir_name
,
"
a4-rotated.png
"
)
test_image
=
cv2
.
imread
(
test_file
)
reference_markers
=
[(
59
,
59
),
(
1179
,
59
),
(
11
79
,
169
3
)]
reference_markers
=
[(
59
,
59
),
(
59
,
1695
),
(
11
81
,
169
5
)]
correct_corner_markers
=
[(
5
8
,
5
8
),
(
118
0
,
5
8
),
(
5
8
,
169
4
),
(
118
0
,
169
4
)]
correct_corner_markers
=
[(
5
9
,
5
9
),
(
118
1
,
5
9
),
(
5
9
,
169
5
),
(
118
1
,
169
5
)]
result_image
,
result_corner_markers
=
scans
.
realign_image
(
test_image
,
reference_keypoints
=
reference_markers
)
result_image
=
scans
.
realign_image
(
test_image
,
reference_keypoints
=
reference_markers
)
result_corner_markers
=
scans
.
find_corner_marker_keypoints
(
result_image
)
assert
result_corner_markers
is
not
None
for
i
in
range
(
4
):
diff
=
np
.
absolute
(
np
.
subtract
(
correct_corner_markers
[
i
],
result_corner_markers
[
i
]))
assert
diff
[
0
]
<
epsilon
assert
diff
[
1
]
<
epsilon
assert
diff
[
0
]
<
=
epsilon
assert
diff
[
1
]
<
=
epsilon
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