HomeCase studiesOffline Computer Vision Dose Verification for Injectable...

Case study · Perth, Australia

Offline Computer Vision Dose Verification for Injectable Care

Healthcare — self-administered injectable medication, patient-facing accessibility and adherence

Patients managing self-administered injectable therapies—particularly those experiencing visual impairment, neuropathy, or fatigue—face real risk when reading tiny pen-injector dials or syringe markings at home. We engineered an offline-first Swift and SwiftUI iOS application powered by AVFoundation, Apple Vision, and CoreML to verify dialed doses in real time without sending camera frames to external servers. Multi-frame stability consensus drives clear VoiceOver audio and haptic confirmations, while CoreData logs adherence securely for optional background sync to a clinician web portal.

Industry
Healthcare — self-administered injectable medication, patient-facing accessibility and adherence
Solution
An offline-capable native iOS computer vision and accessibility application built in Swift and SwiftUI, paired with a Laravel web API for anonymized adherence reporting.
Platforms
iOS · Web & API
Stack
Swift · SwiftUI · CoreML · Vision · AVFoundation · CoreData
Location
Perth, Australia · delivered remotely
Role
Engineering, with the team behind for mobile and QA

Delivered remotely for a business based in Perth, Australia. Names withheld by agreement.

Project Overview

Self-administered injectable therapies demand precision under imperfect conditions: small mechanical dials, low-contrast etched syringe graduations, shaky hands, and dim bedside lighting. For patients living with diabetic retinopathy, age-related macular degeneration, or post-treatment fatigue in Perth and regional Western Australia, verifying whether an injector is dialed to the prescribed units can become a daily barrier to independence. We engineered an offline-first iOS accessibility application in Swift and SwiftUI that turns the iPhone camera into a deterministic, voice-guided dose verifier, backed by an optional Laravel clinical adherence portal.

Business Bottleneck

Existing patient support apps offered static reminder alarms and manual logbooks—requiring users to squint at the injector and self-report what they thought they dialed. Cloud-based OCR solutions proved unworkable for three reasons: patients in regional homes lacked consistent bandwidth at dosing time, network round-trips broke real-time camera aiming, and uploading continuous video frames of home medications triggered severe privacy compliance concerns. Meanwhile, standard text-recognition libraries struggled with cylindrical pen barrels, metallic foil reflections, and partial dial windows.

Architectural Strategy

We built a zero-cloud-inference, safety-gated mobile architecture. Every optical operation—injector localization, dial window cropping, numeral/graduation classification, and temporal smoothing—executes inside an isolated Swift concurrency pipeline on the Apple Neural Engine via Vision and CoreML. The SwiftUI interface treats accessibility as the primary navigation contract rather than an afterthought, coordinating VoiceOver, spoken prompts, and distinct haptic signatures. Once a patient confirms administration, CoreData commits a structured adherence record locally and synchronizes asynchronously with the Laravel web API only when authorized and online.

Core Capabilities

  • On-Device Injector & Dial Verification: Real-time detection of supported pen injectors and syringe windows running completely offline in airplane mode.
  • VoiceOver & Haptic Aiming Guidance: Directional audio and tactile cues guide low-vision users to center the device window without needing to read visual bounding boxes.
  • Multi-Frame Temporal Consensus: Requires consistent, blur-free agreement across consecutive frames before speaking or displaying a verified dose reading.
  • Regime Guardrails & Mismatch Alerts: Compares detected dial values against the patient's active CoreData prescription schedule, flagging under- or over-doses immediately with distinct warning tones.
  • Zero-Image Adherence Sync: Stores structured dose events locally and syncs compact compliance summaries to a Laravel care-program portal when network access returns.

Technical Architecture

Flow: AVFoundation Camera Buffer -> Swift Inference Actor (Vision + CoreML Quantized Models) -> Temporal Consensus Gate -> SwiftUI / VoiceOver / CoreHaptics -> CoreData Encrypted Store -> Background URLSession -> Laravel Care API

AVFoundation captures CVPixelBuffer frames at 30 fps on a dedicated serial capture queue, throttling inference submissions to avoid thermal throttling on older iPhones. Each candidate frame passes luminance and Laplacian blur checks before entering a two-stage CoreML pipeline orchestrated via VNCoreMLRequest: stage one locates the injector body and isolates the rotated dial region of interest, while stage two classifies the visible dose readout.

Candidate predictions flow into a sliding-window consensus buffer inside a Swift actor. Only when consecutive sharp detections agree on both injector class and dose value—and remain free of high-glare warnings—does the state machine emit a VerifiedDose event to the SwiftUI layer, triggering AVSpeechSynthesizer or VoiceOver announcement alongside a CoreHaptics confirmation pulse. Raw pixel buffers are immediately deallocated; CoreData persists solely the resulting metadata event.

Technology Stack

Category Technology detail
iOS language & UI Swift 5 and SwiftUI with Dynamic Type and full VoiceOver support
Camera pipeline AVFoundation real-time pixel buffer capture with torch and focus control
Vision & ML inference CoreML quantized detection models orchestrated via Apple Vision requests
Local persistence CoreData encrypted SQLite store for schedules, regimes, and dose history
Accessibility feedback UIAccessibility announcements, AVSpeechSynthesizer, and CoreHaptics cues
Backend API Laravel (PHP) REST endpoints for optional regimen sync and care portal feeds
Concurrency model Swift structured concurrency isolating camera inference from main UI thread
Privacy architecture Zero-retention in-memory frame processing; no raw camera images persisted

Engineering Trade-offs & Solutions

Architectural Dilemma Chosen Solution & Rationale
Single-frame speed vs. multi-frame reliability Instant single-frame OCR flickers wildly as hands tremble or cylinders rotate. Enforcing a multi-frame consensus window adds a brief hold requirement while eliminating transient misreads before audio output fires.
Generic OCR vs. constrained CoreML dial models General-purpose text recognizers misinterpret curved reflections and partial adjacent numbers on rotating drums. Training compact quantized CoreML models specifically on dial windows and perspective-corrected crops improved resilience under angled viewing.
Continuous 30 fps inference vs. thermal budget Running Neural Engine inference on every frame drains battery and heats the handset. Gating inference on frame sharpness and dropping queued frames while a pass is in flight keeps CPU/GPU thermals stable.
Cloud image audit vs. strict local ephemerality Retaining camera snapshots for troubleshooting would expose sensitive health environments. Discarding every buffer after inference and syncing only numerical verification records simplifies regulatory posture and patient trust.

Security & Reliability

All CoreData SQLite files leverage iOS Data Protection (NSFileProtectionComplete), ensuring regimen schedules and historical dose logs remain encrypted while the device is locked. Model weights are bundled inside the signed app binary and integrity-checked at load time so verification behavior cannot drift across network states. Optional synchronization to the Laravel care-program API uses TLS with short-lived OAuth tokens stored in the iOS Keychain, allowing patients to use the verification engine indefinitely even if they opt out of cloud sharing entirely.

Performance & Scale

Quantized CoreML models keep app bundle size compact and achieve single-frame inference within tens of milliseconds on A-series Neural Engines without blocking SwiftUI animations or VoiceOver responsiveness. On the server side, because heavy visual inference stays on the edge device, the Laravel adherence API processes only lightweight JSON event batches—scaling smoothly across large patient cohorts without GPU server infrastructure.

Operational Outcomes

Patients with low vision or dexterity challenges gained an independent, repeatable check before administering injections—receiving spoken confirmation of dialed units even without cellular reception. Care educators and adherence programs received structured, trustworthy dosing logs free of manual transcription gaps, while the platform avoided the cost, latency, and privacy exposure of streaming home camera feeds to cloud servers.

01 — Questions

asked about this kind of project

Why run the entire computer vision pipeline on-device instead of using a cloud vision API?

Dose verification happens in bedrooms and bathrooms where connectivity may be absent, latency must stay imperceptible while a patient holds an injector steady, and raw photographs of home environments or medication labels raise strict privacy risks. Running CoreML and Vision locally guarantees instant feedback offline and keeps every video frame inside volatile device memory.

How do you prevent a single blurry camera frame from misreporting a medication dose?

The app never acts on a lone inference frame. A temporal consensus filter evaluates consecutive sharp frames—gating out motion blur and specular glare on glossy pen barrels—and announces a verified dose only after multiple sequential detections agree above a strict confidence threshold.

How does a low-vision patient aim the camera accurately without seeing the screen?

Guided framing combines coarse device-orientation checks with real-time spatial audio and haptic cues. When the CoreML detector locates the injector body near the edge of the frame, VoiceOver and distinct CoreHaptics patterns nudge the user left, right, or closer until the dial window locks into the focal zone.

What happens if lighting conditions or pen-injector glare make verification uncertain?

Safety rules bias strictly toward conservative rejection. If illumination drops below luminance thresholds or glare obscures dial numerals, the pipeline triggers the iOS torch automatically and instructs the patient to tilt slightly rather than guessing a low-confidence value.

How are adherence logs shared with the care team without exposing raw patient imagery?

Only structured verification events—timestamp, prescribed target versus confirmed reading, and confirmation status—are written to CoreData. When the device regains internet connectivity and patient consent is active, background URLSession tasks transmit those compact encrypted JSON payloads to the Laravel adherence portal.

03 — Similar project?

describe what is different about yours

Build yours.

Tell me what exists, what you need and the deadline. Fixed price for a defined scope, or $55/day (8–9 hours work) with a written plan first.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.