The Problem: Manual Vote Counting Doesn't Scale
Election day ends. The real work begins.
Thousands of physical ballot papers—each with front and back sides, handwritten marks, QR codes, and official signatures—need to be processed, validated, and counted. In a preferential voting system, each ballot carries first, second, and third preference votes, multiplying the complexity.
Manual counting faces critical challenges:
- Speed: Counting thousands of ballots by hand takes days
- Accuracy: Human fatigue leads to miscounts and missed marks
- Fraud prevention: Duplicate ballots and missing signatures are hard to catch at scale
- Audit trail: Paper-based tracking makes recounts and verification painful
- Geographic complexity: Results need to be tracked across regions, provinces, districts, wards, and individual ballot boxes
What if you could photograph each ballot and let AI handle the rest—counting, validation, and reporting?
What We Built: AI-Powered Ballot Processing System
We built a complete election digitization platform for Papua New Guinea's preferential voting system. Photograph ballot papers, and the system automatically reads QR codes, identifies voter selections, verifies signatures, and tallies results—with a full audit trail for every ballot processed.
The Processing Pipeline
| Step | What Happens | Technology |
|---|---|---|
| 1. Batch Upload | Upload photos of ballot fronts and backs (mixed) | Image processing |
| 2. QR Detection | Extract ballot ID and serial from QR codes | ZXing WASM with auto-rotation |
| 3. Auto-Pairing | Match front and back sides using QR prefix (A/B) | Smart pairing algorithm |
| 4. OCR & Mark Detection | Identify voter selections and preferences | Gemini 2.0 Flash Vision AI |
| 5. Signature Verification | Detect and verify official signatures | Roboflow + MobileNetV2 |
| 6. Vote Tallying | Count 1st, 2nd, 3rd preferences per candidate | Preferential counting engine |
How It Works: From Paper to Data
Smart Ballot Pairing
The most clever piece: election ballots have two sides, but operators photograph them in random order. The system:
- Reads QR codes from every uploaded image
- Identifies front sides (A-prefix QR) and back sides (B-prefix QR)
- Automatically pairs matching fronts and backs by serial number
- Detects and flags duplicates to prevent double-counting
This means operators can photograph a stack of ballots in any order—fronts, backs, mixed—and the system sorts it out.
Multi-Scale QR Detection
Ballot QR codes are often small, smudged, or photographed at angles. Our detection system tries multiple approaches:
- Standard scan at original resolution
- Auto-rotation at 90°, 180°, 270°
- Multi-scale scanning at different zoom levels
- Inversion attempts for low-contrast codes
This cascade approach achieves reliable detection even from poor-quality phone photographs.
AI Vision for Mark Recognition
Once paired, Gemini 2.0 Flash Vision AI analyzes each ballot to identify:
- Checkmarks in candidate boxes
- Filled circles or boxes indicating selection
- Crosses and ticks in various handwriting styles
- Written-in votes that need special handling
- Preference ordering (1st, 2nd, 3rd choice)
The system shows operators a side-by-side view of each extracted field with cropped regions, allowing quick verification before confirmation.
The Technical Edge
Signature Verification Pipeline
Election integrity requires verifying that authorized officials signed each ballot. Our three-stage pipeline:
- Detection: Roboflow AI locates signature regions on the ballot image
- Extraction: Sharp image processing crops and normalizes the signature
- Comparison: MobileNetV2 generates embeddings, and cosine similarity scores match against registered official signatures
This catches unsigned ballots and flags potential forgeries for manual review.
Hierarchical Electoral Geography
Papua New Guinea has a complex electoral structure. The system models the full hierarchy:
Region → Province → District → LLG → Ward → Polling Location
Results roll up through every level, enabling analysis at any granularity—from individual ballot box to national totals. The geography data is imported via CSV and protected as read-only to prevent manipulation.
Complete Audit Trail
Every ballot gets a permanent log entry:
- Original image (front and back)
- QR code data extracted
- AI-detected voter selections
- Validation status and any flags
- Operator who processed it
- Timestamp and ballot box location
This makes recounts straightforward and provides evidence for any disputes.
Results & Reporting
Real-Time Dashboard
As ballots are processed, results update live:
| Feature | What It Shows |
|---|---|
| Candidate tallies | Vote counts by 1st, 2nd, 3rd preference |
| Party breakdown | Aggregate results by political party |
| Box-level stats | Per-ballot-box counts and processing status |
| Validation summary | Flagged ballots, duplicates caught, missing signatures |
Session Recording
The system supports recording election counting sessions with:
- Audio/video capture of the counting process
- AI-generated transcripts of proceedings
- Text-to-speech narration of results (via ElevenLabs)
- Exportable video summaries with charts and data overlays
Export Capabilities
- CSV export of all vote data for external analysis
- JSON export for integration with national election systems
- PDF reports for official record-keeping
- Chart visualizations for public result announcements
Security & Access Control
| Feature | Implementation |
|---|---|
| Authentication | Supabase Auth with email/password |
| Role-based access | Admin, Operator, and Viewer roles |
| Row Level Security | Database-level access control on all tables |
| Protected routes | Authentication middleware on all API endpoints |
| Read-only geography | Electoral boundaries cannot be modified during counting |
Impact
| Before AI | After AI | Impact |
|---|---|---|
| Days of manual counting | Hours of automated processing | 80%+ faster |
| Human error in mark reading | AI-assisted detection + verification | Consistent accuracy |
| No duplicate detection | Automatic QR-based deduplication | Fraud prevention |
| Paper audit trail | Digital logs with image evidence | Full traceability |
| Manual result compilation | Real-time dashboard | Instant visibility |
Who This Is For
This solution works for:
- Electoral commissions modernizing vote counting processes
- Government agencies digitizing paper-based workflows with audit requirements
- NGOs and observers monitoring election integrity
- Organizations running internal elections (unions, associations, boards)
- Any entity processing high-volume documents with verification requirements
If you're counting anything on paper and need accuracy, speed, and an audit trail, the same pipeline applies.

