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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Réouven ASSOULY
zesje
Commits
2e4a8970
Commit
2e4a8970
authored
7 years ago
by
Anton Akhmerov
Browse files
Options
Downloads
Patches
Plain Diff
improve the logic of using zbar by looping over resolutions
parent
9399ad19
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
zesje/helpers/pdf_helper.py
+27
-27
27 additions, 27 deletions
zesje/helpers/pdf_helper.py
with
27 additions
and
27 deletions
zesje/helpers/pdf_helper.py
+
27
−
27
View file @
2e4a8970
...
...
@@ -180,35 +180,35 @@ def make_temp_directory():
shutil
.
rmtree
(
temp_dir
)
def
extract_qr
(
image_path
,
yaml_version
,
scale_factor
=
4
):
image
=
cv2
.
imread
(
image_path
,
cv2
.
IMREAD_GRAYSCALE
)[::
scale_factor
,
::
scale_factor
]
def
extract_qr
(
image_path
,
yaml_version
):
image
=
cv2
.
imread
(
image_path
,
cv2
.
IMREAD_GRAYSCALE
)
if
image
.
shape
[
0
]
<
image
.
shape
[
1
]:
image
=
image
.
T
# Varied thresholds because zbar is picky about contrast.
for
threshold
in
(
200
,
150
,
220
):
thresholded
=
255
*
(
image
>
threshold
)
# zbar also cares about orientation.
for
direction
in
itertools
.
product
([
1
,
-
1
],
[
1
,
-
1
]):
flipped
=
thresholded
[::
direction
[
0
],
::
direction
[
1
]]
scanner
=
zbar
.
Scanner
()
results
=
scanner
.
scan
(
flipped
.
astype
(
np
.
uint8
))
if
results
:
try
:
version
,
name
,
page
,
copy
=
\
results
[
0
].
data
.
decode
().
split
(
'
;
'
)
except
ValueError
:
return
if
version
!=
'
v{}
'
.
format
(
yaml_version
):
raise
RuntimeError
(
'
Yaml format mismatch
'
)
coords
=
np
.
array
(
results
[
0
].
position
)
# zbar doesn't respect array ordering!
if
not
np
.
isfortran
(
flipped
):
coords
=
coords
[:,
::
-
1
]
coords
*=
direction
coords
%=
image
.
shape
coords
*=
scale_factor
return
ExtractedQR
(
name
,
int
(
page
),
int
(
copy
),
coords
)
# Empirically we observed that the most important parameter
# for zbar to successfully read a qr code is the resolution
# controlled below by scaling the image by factor.
# zbar also seems to care about image orientation, hence
# the loop over dirx/diry.
for
dirx
,
diry
,
factor
in
itertools
.
product
([
1
,
-
1
],
[
1
,
-
1
],
[
8
,
5
,
4
,
3
]):
flipped
=
image
[::
factor
*
dirx
,
::
factor
*
diry
]
scanner
=
zbar
.
Scanner
()
results
=
scanner
.
scan
(
flipped
)
if
results
:
try
:
version
,
name
,
page
,
copy
=
\
results
[
0
].
data
.
decode
().
split
(
'
;
'
)
except
ValueError
:
return
if
version
!=
'
v{}
'
.
format
(
yaml_version
):
raise
RuntimeError
(
'
Yaml format mismatch
'
)
coords
=
np
.
array
(
results
[
0
].
position
)
# zbar doesn't respect array ordering!
if
not
np
.
isfortran
(
flipped
):
coords
=
coords
[:,
::
-
1
]
coords
*=
[
factor
*
dirx
,
factor
*
diry
]
coords
%=
image
.
shape
return
ExtractedQR
(
name
,
int
(
page
),
int
(
copy
),
coords
)
else
:
return
...
...
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