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
2612860d
Commit
2612860d
authored
5 years ago
by
RABijl
Browse files
Options
Downloads
Patches
Plain Diff
removes check_corner_markers, adds check for between 2 and 4 markers and updates comments
parent
8c2638cc
No related branches found
Branches containing commit
No related tags found
1 merge request
!41
Simplified realigning the image
Pipeline
#18595
passed
5 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
zesje/scans.py
+7
-7
7 additions, 7 deletions
zesje/scans.py
with
7 additions
and
7 deletions
zesje/scans.py
+
7
−
7
View file @
2612860d
...
...
@@ -701,9 +701,6 @@ def realign_image(image_array, keypoints=None, page_format="A4"):
keypoints : List[(int,int)]
tuples of coordinates of the found keypoints, (x,y), in pixels. Can be a set of 3 or 4 tuples.
if none are provided, they are found by using find_corner_marker_keypoints on the input image.
reference_keypoints: List[(int,int)]
Similar to keypoints, only these belong to the keypoints found on the original scan.
If none are provided, ideal ones are calculated based on the dpi of the input image.
returns
-------
return_array: numpy.array
...
...
@@ -712,17 +709,20 @@ def realign_image(image_array, keypoints=None, page_format="A4"):
if
not
keypoints
:
keypoints
=
find_corner_marker_keypoints
(
image_array
)
check_corner_keypoints
(
image_array
,
keypoints
)
# use standard keypoints if no custom ones are provided
if
not
(
2
<=
len
(
keypoints
)
<=
4
):
raise
RuntimeError
(
f
"
Found
{
len
(
keypoints
)
}
markers while realigning image
"
)
# generate the coordinates where the markers should be
dpi
=
guess_dpi
(
image_array
)
reference_keypoints
=
original_corner_markers
(
page_format
,
dpi
)
# create a matrix with the distances between each keypoint and match the keypoint sets
dists
=
spatial
.
distance
.
cdist
(
reference_keypoints
,
keypoints
)
idxs
=
np
.
argmin
(
dists
,
1
)
idxs
=
np
.
argmin
(
dists
,
1
)
# apply to column 1 so indices for input keypoints
adjusted_markers
=
[
keypoints
[
i
]
for
i
in
idxs
]
rows
,
cols
,
_
=
image_array
.
shape
adjusted_markers
=
[
keypoints
[
i
]
for
i
in
idxs
]
# get the transformation matrix
M
=
cv2
.
estimateAffinePartial2D
(
np
.
asarray
(
adjusted_markers
),
np
.
asarray
(
reference_keypoints
))[
0
]
...
...
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