From 9d46ed71d538794e2b7bea94b8b199e80936fe8d Mon Sep 17 00:00:00 2001 From: Ruben Young On <r.d.youngon@student.tudelft.nl> Date: Sat, 25 May 2019 15:15:39 +0200 Subject: [PATCH] =?UTF-8?q?fix=5Fcorner=5Fmarkers=20now=20raises=20runtime?= =?UTF-8?q?=20=C2=86error=20if=20fewer=20than=203=20corner=20markers=20are?= =?UTF-8?q?=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zesje/images.py | 2 +- zesje/pregrader.py | 1 - zesje/scans.py | 7 ++++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/zesje/images.py b/zesje/images.py index 06eef077..d4afe766 100644 --- a/zesje/images.py +++ b/zesje/images.py @@ -59,7 +59,7 @@ def fix_corner_markers(corner_keypoints, shape): """ if len(corner_keypoints) == 4 or len(corner_keypoints) < 3: - return corner_keypoints + raise RuntimeError("Fewer then 3 corner markers found") x_sep = shape[1] / 2 y_sep = shape[0] / 2 diff --git a/zesje/pregrader.py b/zesje/pregrader.py index 37c3535c..4954bc8a 100644 --- a/zesje/pregrader.py +++ b/zesje/pregrader.py @@ -22,7 +22,6 @@ def add_feedback_to_solution(sub, exam, page, page_img, corner_keypoints): """ problems_on_page = [problem for problem in exam.problems if problem.widget.page == page] - # TODO: What if less than 3 keypoints are found? top_left_point, fixed_corner_keypoints = fix_corner_markers(corner_keypoints, page_img.shape) for problem in problems_on_page: diff --git a/zesje/scans.py b/zesje/scans.py index ac0be8e0..4d3e1c5b 100644 --- a/zesje/scans.py +++ b/zesje/scans.py @@ -339,7 +339,12 @@ def process_page(image_data, exam_config, output_dir=None, strict=False): return True, "Testing, image not saved and database not updated." sub, exam = update_database(image_path, barcode) - add_feedback_to_solution(sub, exam, barcode.page, image_array, corner_keypoints) + + try: + add_feedback_to_solution(sub, exam, barcode.page, image_array, corner_keypoints) + except RuntimeError as e: + if strict: + return False, str(e) if barcode.page == 0: description = guess_student( -- GitLab