Photo-based medicine batch verification using local OCR and conservative matching.
- Problem. India's drug regulator (CDSCO) publishes monthly lists of medicine batches that failed quality tests ("Not of Standard Quality"). The August 2026 list runs to 22 portal pages and 220 batches. Checking a strip in your hand against it means comparing batch numbers character by character.
- What MedCheck does. Reads the batch number from a photo with local OCR, looks it up in that list, and answers with one of four outcomes. The safe default is Unable to verify.
- Why it is cautious. An alert needs an exact batch match and matching product details. Batches that differ only by look-alike characters (O/0, I/1, S/5, B/8) make it abstain rather than guess. A clean "No alert found" appears only after you confirm the batch against the pack, and it is never shown in green. The dataset is hash-checked on every start.
- What is verified. The automated suite (475 tests) and the dataset rebuild check pass on Ubuntu in CI. On real photographs from one phone, OCR read the batch exactly in 3 of the 7 development photos with a certain reference reading, and in 1 of 4 reserved photos. It accepted no wrong batch among those. All 27 photos first showed "Unable to verify", either abstaining or waiting for you to confirm the batch (docs/HELDOUT_EVALUATION.md). These are not accuracy figures. The alert path has never been exercised on a photograph of a real listed pack. See Known limitations.
- What it is not. It does not detect counterfeits, test the medicine or give medical advice.
Upload or capture a photo of a medicine strip or box. MedCheck reads the batch number with local OCR (RapidOCR, with Tesseract as extra evidence) and checks it against the CDSCO August 2026 NSQ (Not of Standard Quality) alert list (220 records). It then reports one of four outcomes:
| Outcome | Meaning |
|---|---|
| Alert found | The batch read from the photo matches one NSQ entry and the product details corroborate it. The matched record is shown, with a "Check before acting" prompt: compare the printed batch character by character, and the product, strength and manufacturer, with the listed record. |
| No alert found | A batch was read, no qualifying entry exists in the August 2026 list, and you confirmed the batch matches the number printed on the pack. This does not mean the medicine is safe, genuine or free of defects; confirming only means you checked the printed number. |
| Expired | Reserved. Never shown yet: how month-only expiry dates should be interpreted is an open owner decision (see docs/EXPIRY_POLICY.md). |
| Unable to verify | The batch could not be read consistently, or the evidence is ambiguous, conflicting or too weak. This is the deliberate safe default. |
Separate from these outcomes, system errors (dataset failed its integrity check, OCR engine missing, timeout, internal error) are shown as "System error" and are never reported as "No alert found".
MedCheck is not an authenticity or counterfeit detector, a laboratory test, or medical advice. If unsure about a medicine, ask a pharmacist or doctor.
Windows (developed on Windows 11), Python 3.13, and Tesseract OCR 5.x with English data (tesseract --version must work, or set MEDCHECK_TESSERACT_CMD).
cd D:\MedCheck
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
.\.venv\Scripts\python.exe -m pip install --no-deps -r requirements-ocr.txt
.\.venv\Scripts\python.exe -m streamlit run app.pyThe second install adds the primary OCR engine (RapidOCR, about 72 MB, offline, models bundled and hash-checked); see docs/OCR_ENGINES.md. Without it the app runs on Tesseract alone and says so.
The app opens at http://localhost:8501 and listens on localhost only. Run locally, photos are processed in memory on your computer and are not saved, logged or sent anywhere.
requirements.txt now also lists the OCR stack (used by Streamlit Community Cloud, which reads only that file); on an existing environment the second install above stays valid. Hosted use is a different privacy case: the photo is uploaded to the hosting server (processed in memory, not saved or logged by MedCheck, no external OCR service). See docs/DEPLOYMENT.md (prepared, not yet deployed).
The default interface is a five-scene scroll story (a capsule, an illustrative glass of water, evidence turning into text, a magnified medicine carton, and a neutral comparison) that leads into the check tool. The water scene is an illustration only: MedCheck never tests or dissolves a medicine. It runs entirely offline (Three.js is vendored in static/vendor/three/, with its licence) and the scan animation runs while the real OCR runs. If the browser cannot render WebGL, or you prefer the plain interface, set MEDCHECK_PLAIN_UI=1 before streamlit run app.py; every check works identically. The 3D layer is decoration: it never receives your photo or text. See docs/UI_UX_GUIDELINES.md.
The result is shown as a status banner, one card each for the batch, expiry and manufacturing date, the matched record (for an alert), the batch form, and the explanation and notes, always with the full limitation text; a "No alert found" is neutral blue, never green. Branch note: this interface (milestones M14-M16) exists only on branch ui-redesign; master is at milestone M13 and has not been updated, because the rehearsal on the demonstration laptop is still pending.
.\.venv\Scripts\python.exe -m pytest -qThe latest recorded results are in BUILD_PROGRESS.md.
.\.venv\Scripts\python.exe scripts\make_demo_images.py # writes demo_images\ + fixtures_manifest.csv
.\.venv\Scripts\python.exe scripts\run_fixture_check.py # optional: records a fixture run (7 of 7 expected)
.\.venv\Scripts\python.exe -m streamlit run app.pyUpload the images from demo_images\ one at a time and press Check this photo:
| Image | Expected result | Why |
|---|---|---|
FIXTURE_1_alert_found.png |
Alert found (serial 4), with "Check before acting" | listed batch plus matching product |
FIXTURE_2_alert_found_trailing_comma.png |
Alert found (serial 150) | published batch ends with a comma; punctuation is ignored |
FIXTURE_3_no_alert_after_confirmation.png |
Unable to verify, then No alert found after you tick the confirmation | batch not in the list, but a clean negative needs you to compare the batch with the pack first |
FIXTURE_4_unable_batch_alone.png |
Unable to verify | listed batch, wrong product: a batch alone never alerts |
FIXTURE_5_unable_collision.png |
Unable to verify | serials 38 and 157 differ only by 0 vs letter O |
FIXTURE_6_unable_no_batch.png |
Unable to verify | no batch number present |
FIXTURE_7_alert_listed_neighbour.png |
Alert found (serial 113) | listed serial 118 is one character away; the alert warns that one misread character could produce the match |
These are synthetic test fixtures (rendered text built from public list values), not photographs of affected medicines. Every image carries a red in-frame banner "TEST FIXTURE - SYNTHETIC - NOT A REAL MEDICINE"; keep it visible if you print and photograph one. They show how the software behaves; their pass rate is not evidence of accuracy on real photographs and is recorded separately (evaluation/results/fixtures/). tests/test_demo.py verifies every row above.
Under every result MedCheck shows the batch it read and lets you correct it or type it when OCR found none. A typed or corrected batch goes through the same checks, is labelled as yours, never counts as OCR evidence and never confirms the product; a number that matches nothing (whether OCR read it, you corrected it or you typed it) gives No alert found only after you tick that you compared it with the one printed on the pack. Until you do, the result is Unable to verify and the batch is shown back to you, because OCR can read look-alike characters (S for 5, O for 0, I for 1) wrongly and consistently. An alert is never delayed for this. When the OCR passes disagreed, the different readings appear as buttons above the batch box: clicking one only fills the box with that exact text (nothing is chosen for you, it is never confirmed or submitted by the click, and the confirmation tick is cleared); you still compare it with the pack, tick the box and press the button.
Exact normalized batch is the only route to an alert, and a product brand or all active-ingredient words must corroborate it (short batches need two independent signals). Look-alike characters (O/0, I/1/L, S/5, B/8) are never substituted; if another listed batch differs only by such characters, MedCheck abstains. Near-matches only ever lead to "Unable to verify". Details: docs/MATCHING.md.
The immutable official CDSCO extraction (data/cdsco_august_2026_nsq_official_extraction.csv) is the source; the app reads a generated canonical file whose SHA-256 is checked on every start. Source anomalies (for example serials 72, 121, 136, 150, 152, 153) are preserved verbatim, not corrected. See docs/DATASET.md.
- OCR accuracy on real photographs has not been evaluated. No performance claims are made; no evaluation protocol has been run: D-014 is open, and both the original 60-image proposal and the evidence-category revision in
docs/EVALUATION.mdare pending approval and further planning. Diagnostic runs on 20 development photos and a one-time run on 7 reserved photos exist (BUILD_PROGRESS.md,docs/HELDOUT_EVALUATION.md); neither is an accuracy figure (no listed pack was among them, and the references are visual readings). - OCR can read a batch confidently but wrongly or incompletely; always compare the "Batch checked" line with the number printed on the pack.
- A one-character misread of an unlisted neighbouring batch of a listed product could produce a false
Alert found(listed batches often come in sequences); the product check does not compare the manufacturer and uses all text in the photo. Every alert therefore asks you to compare batch, product, strength and manufacturer with the listed record. Alert foundhas only been exercised on synthetic test fixtures and programmatic tests, never on a photograph of a real listed pack (none can be obtained).- Extraction needs a recognisable label (
B.No.,Batch No.,Lot); strict agreement across OCR passes means blurry, glary, cut-off or dark-ink-on-gold photos often end as "Unable to verify". On the development PC a check typically takes 3-10 seconds when a batch label is found and up to about 20 seconds when nothing is found (it then tries the photo rotated); times vary with other programs using the computer. After updating the code, stop and restart the app so the running copy is not out of date. - Batches shorter than 3 characters (serials 24 and 26) are never read; they always end as "Unable to verify".
- English only; no deskew or perspective correction; one image per check; no barcode/QR support.
- Covers only the August 2026 list, not other months, other regulators or the full regulatory record.
- Thresholds in
medcheck/config.pyare uncalibrated engineering defaults. - Local use only. Public hosting would send photos to a server and needs a separate privacy review (
docs/DEPLOYMENT.md).
PROJECT_GUIDE.md (instructions and document map), BUILD_PROGRESS.md (state of the build), docs/ (specifications and decisions), docs/archive/ (superseded history).
The MedCheck source code is released under the MIT License. The NSQ data in data/ is extracted from the public CDSCO portal (see docs/DATASET.md); it is CDSCO's publication, not covered by the MIT License, and is included unchanged for verification. Third-party components keep their own licences (Three.js under static/vendor/three/; OCR engines listed in docs/OCR_ENGINES.md).