Skip to content
Snippets Groups Projects
Commit 8e88151c authored by RABijl's avatar RABijl
Browse files

Merge branch 'master' into 'develop'

Update master (this MR contains no useful information)

See merge request !21
parents 8dc85ca5 f3567df4
No related branches found
No related tags found
1 merge request!21Master->develop (this MR contains no useful information)
Pipeline #18106 passed with warnings
Showing
with 30 additions and 18 deletions
...@@ -89,6 +89,12 @@ build/ ...@@ -89,6 +89,12 @@ build/
# development data # development data
data-dev data-dev
# test data
tests/data/submissions
# redis dump
dump.rdb
# webpack analyze data # webpack analyze data
stats.json stats.json
......
tests/data/scanned_pdfs/blank.jpg

28 KiB

tests/data/scanned_pdfs/jamy1.jpg

50.8 KiB

tests/data/scanned_pdfs/jamy2.jpg

50.8 KiB

tests/data/scanned_pdfs/latex1.jpg

125 KiB

tests/data/scanned_pdfs/latex2.jpg

124 KiB

tests/data/scanned_pdfs/latex3.jpg

119 KiB

tests/data/scanned_pdfs/latex4.jpg

121 KiB

tests/data/scanned_pdfs/latex5.jpg

111 KiB

tests/data/scanned_pdfs/latex6.jpg

113 KiB

tests/data/scanned_pdfs/messy_three_corners.jpg

69.1 KiB

tests/data/scanned_pdfs/missing_two_corners.jpg

67.6 KiB

tests/data/scanned_pdfs/sample_exam.jpg

59.4 KiB

tests/data/scanned_pdfs/shifted.jpg

67.3 KiB

tests/data/scanned_pdfs/tilted.jpg

65.7 KiB

import math import math
import os import os
import cv2
import numpy as np import numpy as np
import PIL import PIL
import pytest import pytest
...@@ -17,12 +16,12 @@ def distance(keyp1, keyp2): ...@@ -17,12 +16,12 @@ def distance(keyp1, keyp2):
# Given a name of a exam image and the location it is stored, retrieves the # Given a name of a exam image and the location it is stored, retrieves the
# image and converts it to binary image # image and converts it to binary image
def generate_binary_image(name, datadir): def generate_image(name, datadir):
pdf_path = os.path.join(datadir, 'scanned_pdfs', f'{name}') pdf_path = os.path.join(datadir, 'scanned_pdfs', f'{name}')
pil_im = PIL.Image.open(pdf_path) pil_im = PIL.Image.open(pdf_path)
opencv_im = cv2.cvtColor(np.array(pil_im), cv2.COLOR_RGB2BGR) pil_im = pil_im.convert('RGB')
_, bin_im = cv2.threshold(opencv_im, 150, 255, cv2.THRESH_BINARY) image_array = np.array(pil_im)
return bin_im return image_array
# Tests # Tests
...@@ -41,15 +40,22 @@ def test_calc_angle(test_input1, test_input2, expected): ...@@ -41,15 +40,22 @@ def test_calc_angle(test_input1, test_input2, expected):
# Tests whether the amount of cornermakers is enough to calculate the angle and # Tests whether the amount of cornermakers is enough to calculate the angle and
# whether it is lower than 5 as we only add 4 corner markers per page. # whether it is lower than 5 as we only add 4 corner markers per page.
@pytest.mark.parametrize('name', os.listdir( test_args = [
os.path.join('tests', ('missing_two_corners.jpg', 2),
'data', 'scanned_pdfs')), ('sample_exam.jpg', 4),
ids=os.listdir( ('shifted.jpg', 4),
os.path.join('tests', 'data', 'scanned_pdfs'))) ('tilted.jpg', 4),
def test_detect_enough_cornermarkers(name, datadir): ('messy_three_corners.jpg', 3),
bin_im = generate_binary_image(name, datadir) ('blank.jpg', 0)]
keypoints = scans.find_corner_marker_keypoints(bin_im)
assert(len(keypoints) >= 2 & len(keypoints) <= 4)
@pytest.mark.parametrize(
'name,expected', test_args,
ids=list(map(lambda e: f"{e[0]} ({e[1]} markers)", test_args)))
def test_detect_enough_cornermarkers(name, expected, datadir):
image = generate_image(name, datadir)
keypoints = scans.find_corner_marker_keypoints(image)
assert(len(keypoints) == expected)
# Tests whether the detected keypoints are actually corner markers. # Tests whether the detected keypoints are actually corner markers.
...@@ -62,10 +68,10 @@ def test_detect_enough_cornermarkers(name, datadir): ...@@ -62,10 +68,10 @@ def test_detect_enough_cornermarkers(name, datadir):
ids=os.listdir( ids=os.listdir(
os.path.join('tests', 'data', 'scanned_pdfs'))) os.path.join('tests', 'data', 'scanned_pdfs')))
def test_detect_valid_cornermarkers(name, datadir): def test_detect_valid_cornermarkers(name, datadir):
bin_im = generate_binary_image(name, datadir) image = generate_image(name, datadir)
keypoints = scans.find_corner_marker_keypoints(bin_im) keypoints = scans.find_corner_marker_keypoints(image)
h, w, *_ = bin_im.shape h, w, *_ = image.shape
(xmm, ymm) = (210, 297) (xmm, ymm) = (210, 297)
(xcorner, ycorner) = (round(30 * w / xmm), round(30 * h / ymm)) (xcorner, ycorner) = (round(30 * w / xmm), round(30 * h / ymm))
maxdist = math.hypot(xcorner, ycorner) maxdist = math.hypot(xcorner, ycorner)
......
...@@ -68,7 +68,7 @@ def full_exam_data(exam_id): ...@@ -68,7 +68,7 @@ def full_exam_data(exam_id):
if not data: if not data:
# No students were assigned. # No students were assigned.
columns = [] columns = []
for problem in exam.problems.order_by(Problem.id): for problem in exam.problems: # Sorted by problem.id
if not len(problem.feedback_options): if not len(problem.feedback_options):
# There is no possible feedback for this problem. # There is no possible feedback for this problem.
continue continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment