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
728f190b
Commit
728f190b
authored
5 years ago
by
RABijl
Browse files
Options
Downloads
Patches
Plain Diff
adds realign function to scans
parent
8c60ea38
No related branches found
Branches containing commit
No related tags found
1 merge request
!20
Feature/precise positioning
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
zesje/scans.py
+31
-1
31 additions, 1 deletion
zesje/scans.py
with
31 additions
and
1 deletion
zesje/scans.py
+
31
−
1
View file @
728f190b
...
...
@@ -15,7 +15,7 @@ from pylibdmtx import pylibdmtx
from
.database
import
db
,
Scan
,
Exam
,
Page
,
Student
,
Submission
,
Solution
,
ExamWidget
from
.datamatrix
import
decode_raw_datamatrix
from
.images
import
guess_dpi
,
get_box
from
.images
import
guess_dpi
,
get_box
,
fix_corner_markers
from
.factory
import
make_celery
from
.pregrader
import
add_feedback_to_solution
...
...
@@ -788,3 +788,33 @@ def check_corner_keypoints(image_array, keypoints):
if
max
(
corners
.
values
())
>
1
:
raise
RuntimeError
(
"
Found multiple corner markers in the same corner
"
)
def
realign_image
(
image_array
,
keypoints
=
None
,
reference_keypoints
=
None
):
if
(
keypoints
is
None
):
keypoints
=
find_corner_marker_keypoints
(
image_array
)
check_corner_keypoints
(
image_array
,
keypoints
)
if
(
len
(
keypoints
)
!=
4
):
keypoints
=
fix_corner_markers
(
keypoints
,
image_array
.
shape
)
# use standard keypoints if no custom ones are provided
if
(
reference_keypoints
is
None
):
reference_keypoints
=
[(
59
,
59
),
(
1179
,
59
),
(
59
,
1693
),
(
1179
,
1693
)]
rows
,
cols
,
_
=
image_array
.
shape
keypoints_32
=
np
.
float32
(
keypoints
)
reference_keypoints_32
=
np
.
float32
(
reference_keypoints
)
# get the transformation matrix
M
=
cv2
.
getPerspectiveTransform
(
keypoints_32
,
reference_keypoints_32
)
# apply the transformation matrix
return_image
=
cv2
.
warpPerspective
(
image_array
,
M
,
(
cols
,
rows
))
return_keypoints
=
find_corner_marker_keypoints
(
return_image
)
return
return_image
,
return_keypoints
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