Skip to main content

Core workflow

  1. Receive multipart input. The controller requires image and answers parts. Missing parts or malformed content enters the controller's exception path.
  2. Parse the answer key. GradingService reads the CSV with OpenCSV into AnswerKey rows.
  3. Persist the image temporarily. ImageProcessingService transfers the image to a temporary .jpg file, reads it with OpenCV, and deletes the temporary file in a finally block.
  4. Align the sheet. The service detects likely corner markers and applies a perspective warp; if it cannot find four corners, it resizes the source to 800x1200.
  5. Read identity regions. Fixed crops are sent to the configured OCR service for student name and class.
  6. Extract 40 answers. The processor classifies filled bubble contours into four columns and ten rows per column. Multiple marked choices are retained as a sorted string such as AC.
  7. Grade. Each answer-key row is compared case-insensitively. The result contains the count, total, score, incorrect question numbers, and extracted answers.
  8. Return JSON or 500. A successful call returns the GradeResult. Any exception escaping the controller's work is logged and returned as an empty HTTP 500 response.