Skip to content
Snippets Groups Projects
Commit e25ffb23 authored by Ruben Young On's avatar Ruben Young On
Browse files

Changed commented out code back, changed the way errors are printed, added...

Changed commented out code back, changed the way errors are printed, added temporary fix for box check, feedback description should be the label of the mc_option if it is present
parent bb0b131d
No related branches found
No related tags found
1 merge request!17Add pregrading
Pipeline #17930 passed
......@@ -13,7 +13,7 @@
import cv2
import numpy as np
from zesje.database import db, Solution, Problem, ProblemWidget
from zesje.database import db, Solution, ProblemWidget
from zesje.images import guess_dpi, get_box, fix_corner_markers
......@@ -26,7 +26,7 @@ def add_feedback_to_solution(page, page_img, corner_keypoints):
page_img: image of the page
barcode: data from the barcode on the page
"""
widgets = ProblemWidget.filter(ProblemWidget.page == page).all()
widgets = ProblemWidget.query.filter(ProblemWidget.page == page).all()
problems_on_page = [widget.problem for widget in widgets]
......@@ -41,7 +41,7 @@ def add_feedback_to_solution(page, page_img, corner_keypoints):
# check if box is filled
if box_is_filled(box, page_img, corner_keypoints):
sol.feedback.append(mc_option.feedback)
sol.feedback.text = mc_option.label
db.session.commit()
......@@ -82,10 +82,10 @@ def box_is_filled(box, page_img, corner_keypoints, marker_margin=72/2.54, thresh
# add the actually margin from the scan to corner markers to the coords in inches
dpi = guess_dpi(page_img)
coords[0] = coords[0] + corner_keypoints[1]/dpi
coords[1] = coords[1] + corner_keypoints[1]/dpi
coords[2] = coords[2] + corner_keypoints[0]/dpi
coords[3] = coords[3] + corner_keypoints[0]/dpi
coords[0] = coords[0] + corner_keypoints[1][1]/dpi
coords[1] = coords[1] + corner_keypoints[1][1]/dpi
coords[2] = coords[2] + corner_keypoints[0][0]/dpi
coords[3] = coords[3] + corner_keypoints[0][0]/dpi
# get the box where we think the box is
cut_im = get_box(page_img, coords, padding=cut_padding)
......
......@@ -5,6 +5,7 @@ import os
from collections import namedtuple, Counter
from io import BytesIO
import signal
import traceback
import cv2
import numpy as np
......@@ -53,7 +54,7 @@ def process_pdf(scan_id):
# TODO: When #182 is implemented, properly separate user-facing
# messages (written to DB) from developer-facing messages,
# which should be written into the log.
write_pdf_status(scan_id, 'error', "Unexpected error: " + str(error))
write_pdf_status(scan_id, 'error', "Unexpected error: " + traceback.format_exc())
def _process_pdf(scan_id, app_config):
......@@ -77,22 +78,22 @@ def _process_pdf(scan_id, app_config):
total = PyPDF2.PdfFileReader(open(pdf_path, "rb")).getNumPages()
failures = []
# try:
for image, page in extract_images(pdf_path):
report_progress(f'Processing page {page} / {total}')
# try:
success, description = process_page(
image, exam_config, output_directory
)
if not success:
print(description)
failures.append(page)
# except Exception as e:
# report_error(f'Error processing page {e.__cause__}')
return
# except Exception as e:
# report_error(f"Failed to read pdf: {e}")
# raise
try:
for image, page in extract_images(pdf_path):
report_progress(f'Processing page {page} / {total}')
try:
success, description = process_page(
image, exam_config, output_directory
)
if not success:
print(description)
failures.append(page)
except Exception:
report_error(f'Error processing page {traceback.format_exc()}')
raise
except Exception as e:
report_error(f"Failed to read pdf: {e}")
raise
if failures:
processed = total - len(failures)
......
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