mirror of
https://github.com/tiennm99/chambai.git
synced 2026-05-21 00:24:00 +00:00
5.7 KiB
5.7 KiB
Claude Code Prompt: Vietnamese Multiple Choice Test Scoring Web Application
Project Overview
Create a web application that allows teachers to:
- Set up test configurations (number of questions, correct answers)
- Upload and process scanned student answer sheets
- Automatically recognize student IDs and answers using OpenCV
- Calculate scores and export results to CSV
Technical Requirements
Core Technologies
- Frontend: HTML5, CSS3, JavaScript (vanilla or React)
- Image Processing: OpenCV.js for browser-based image recognition
- File Handling: FileReader API for image uploads
- Data Storage: localStorage for persistence (with reset functionality)
- Export: CSV generation and download
Application Structure
/chambai/
├── index.html
├── css/
│ └── styles.css
├── js/
│ ├── main.js
│ ├── opencv-setup.js
│ ├── image-processor.js
│ ├── answer-recognizer.js
│ └── csv-exporter.js
├── lib/
│ └── opencv.js
└── README.md
Detailed Feature Requirements
1. Test Configuration Page
UI Components:
- Input for total number of questions per section:
- Phần I (Multiple Choice): Input field + answer key grid (A/B/C/D buttons)
- Phần II (True/False): Input field + answer key grid (True/False buttons)
- Phần III (Numerical): Input field + answer input boxes
- "Save Configuration" button
- "Reset All Data" button (clears localStorage)
Data Structure:
const testConfig = {
phanI: {
questionCount: 40,
answers: ['A', 'B', 'C', 'D', 'A', ...] // Array of correct answers
},
phanII: {
questionCount: 8,
answers: [
{ a: true, b: false, c: true, d: true }, // Question 1
{ a: false, b: true, c: false, d: true }, // Question 2
// ... more questions
]
},
phanIII: {
questionCount: 6,
answers: ['-1.5', '2.3', '45', ...] // Array of correct numerical answers
}
}
2. Image Upload and Processing Page
UI Components:
- Drag & drop zone for images (JPG/PNG)
- Image preview area
- "Process Image" button
- Progress indicator
- Results display table
Image Processing Requirements:
- Use OpenCV.js to:
- Convert image to grayscale
- Apply adaptive thresholding
- Detect filled bubbles using contour detection
- Extract student ID from section 7 (số báo danh)
- Extract answers from all three sections
Recognition Logic:
- Student ID: Recognize filled bubbles in the grid format shown in the PDF
- Phần I: Detect A/B/C/D bubble selections
- Phần II: Detect True/False bubble selections for each sub-question
- Phần III: Detect numerical bubble selections (0-9, comma, negative sign)
3. Results Management
Features:
- Display processed results in a table
- Allow manual correction of misrecognized answers
- Calculate scores automatically
- Show individual question results
- Export to CSV functionality
Data Structure:
const studentResults = [
{
studentId: '123456789',
phanI: ['A', 'B', 'C', 'D', ...], // Student's answers
phanII: [
{ a: true, b: false, c: true, d: false },
// ... more answers
],
phanIII: ['-1.5', '2.0', '45', ...],
score: {
phanI: 35, // out of 40
phanII: 6, // out of 8
phanIII: 4, // out of 6
total: 45, // out of 54
percentage: 83.33
}
}
]
4. CSV Export Format
Student ID,Total Score,Percentage,P1_Q1,P1_Q2,...,P2_Q1_a,P2_Q1_b,...,P3_Q1,P3_Q2,...
123456789,45,83.33,A,B,C,D,true,false,true,false,-1.5,2.0,45
OpenCV Implementation Guide
Image Preprocessing
// Convert to grayscale
let gray = new cv.Mat();
cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY);
// Apply adaptive threshold
let thresh = new cv.Mat();
cv.adaptiveThreshold(gray, thresh, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 11, 2);
Bubble Detection
// Find contours
let contours = new cv.MatVector();
let hierarchy = new cv.Mat();
cv.findContours(thresh, contours, hierarchy, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE);
// Filter circular contours (bubbles)
// Check if bubble is filled by analyzing pixel density
Region of Interest (ROI) Extraction
- Define coordinate ranges for each section based on the template
- Extract specific regions for student ID, Phần I, Phần II, Phần III
- Process each region separately
User Interface Design
Step-by-Step Workflow
- Setup Page: Configure test parameters
- Upload Page: Process answer sheets
- Review Page: Verify and correct recognition results
- Export Page: Download CSV results
Responsive Design
- Mobile-friendly interface
- Clear navigation between steps
- Visual feedback for processing status
- Error handling and user guidance
Error Handling
- Invalid image formats
- Poor image quality detection
- Ambiguous bubble selections
- Missing student ID recognition
- Network/processing errors
Additional Features to Consider
- Batch processing multiple images
- Image rotation/alignment correction
- Template matching for better accuracy
- Statistics and analytics dashboard
- Print-friendly result summaries
Implementation Priority
- Basic UI structure and navigation
- OpenCV.js integration and setup
- Image upload and preprocessing
- Student ID recognition
- Multiple choice (Phần I) recognition
- True/False (Phần II) recognition
- Numerical (Phần III) recognition
- Scoring logic and results display
- CSV export functionality
- Error handling and UI polish
Create this web application with clean, well-documented code, focusing on accuracy of bubble detection and user-friendly interface for teachers to efficiently score multiple choice tests.