Repository navigation
OCR Integration for Android Registration Client #1102
SachinPremkumar
started this conversation in
General
Replies: 1 comment
|
As per the discussion below points are considered during the :
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
OCR Integration for Android Registration Client
1. Purpose
Enable an operator to scan an identity document during New Registration and
have relevant Demographic Details fields pre-filled automatically, while
preserving manual entry as the default, uninterrupted path. This document
describes the end-to-end design: camera capture, the OCR request/response
contract, client-side validation, form pre-fill, audit, and persistence.
2. Scope
In scope: native camera streaming and capture, OCR request construction,
OCR response handling and validation, mapping into the DemographicDetails
screen, audit logging, fallback behavior, packet metadata update.
3. Actors and Components
mosip.registration.*config (timeout, provider type, service URL, enable flag, quality-check thresholds)4. Configuration
Read through the existing global-param cache,
mosip.registration.*naming:mosip.registration.ocr.enabledmosip.registration.ocr.providerremote(HTTP service) ormlkit(on-device). Country/deployment-specific.mosip.registration.ocr.response.timeoutmosip.registration.ocr.quality.max_retriesmosip.registration.ocr.quality.thresholds.*ocr.enabled.4.1 Pluggable OCR Provider Abstraction
OCR is not tied to a single vendor or a single deployment model. The
Registration Client defines a common internal OCR provider interface
something like
Future<OcrResult> extract(image, spec)with eachprovider implementation satisfying the same request/response contract
described in 6, regardless of where extraction actually happens:
service.urlused?Rationale for on-device options like ML Kit:
device (data residency/privacy constraints) an on-device engine like
ML Kit satisfies this without a network round-trip.
without depending on a reachable OCR endpoint.
spec-matched
id:valuepairs the way a purpose-built remote OCR serviceis expected to return per 6.2), the on-device provider implementation
is responsible for its own field-matching logic (e.g. regex/heuristic
matching of recognized text blocks against the field list sent in
spec) so it still produces the same{ metadata, data }shape the restof the pipeline expects. This keeps 6.3 client-side validation,
fallback handling (8), and audit (9) identical regardless of which
provider is active.
(
ocr.provider), not a runtime user choice the operator experience(Scan → stream → quality-gated capture → pre-fill/fallback) is unchanged either way.
5. End-to-End Flow
flowchart TD A([Operator taps Scan]) --> B{ocr.enabled?} B -- No --> Z1[Manual entry only] B -- Yes --> C[Open camera stream] C --> D{Sample frames / live feedback,\noperator triggers capture,\nquality check\nbrightness/sharpness/\nframing/liveliness} D -- Pass --> G[Send OCR request\nimage + trimmed spec] D -- Fail, retries < max --> D D -- Fail, retries == max --> H{Operator choice} H -- Capture anyway --> G H -- Cancel scan --> Z1 G --> I{Response within\ntimeout?} I -- No --> Z1 I -- Yes --> J{error.errorCode\npopulated?} J -- Yes --> K[Log provider_error\nerrorCode + errorInfo] K --> Z1 J -- No --> L{documentType\nrecognized?} L -- No --> M[Log unrecognized_document_type] M --> Z1 L -- Yes --> N[Validate each field:\nid in spec, type/format,\nconditional visibility] N --> O{Any field\nsurvives validation?} O -- No --> P[Log no_data_extracted] P --> Z1 O -- Yes --> Q[Pre-fill DemographicDetails\nas editable values] Q --> R[Operator reviews /\ncorrects / accepts] R --> S[Persist via RegistrationDTO\n+ write documentType to\npacket metadata] S --> T([Done]) Z1 --> U[Operator fills form\nmanually] U --> RThis is the decision/process view of the flow. See 7 for the
quality-check retry loop detail and 6/8 for the request/response contract
and failure-reason mapping shown above.
6. Request/Response Contract
6.1 Request
Sent to
mosip.registration.ocr.service.url:{ "image": "<captured document image, base64 or multipart>", "spec": { "screen": "DemographicDetails", "fields": [ { "id": "firstName", "type": "simpleType", "controlType": "textbox", "subType": "firstName" }, { "id": "dateOfBirth", "type": "string", "controlType": "ageDate", "subType": "dateOfBirth" } ] } }Only the trimmed Demographic Details field list is sent (
id,type,controlType,subTypeper field) not the full process JSON.Consent, Documents, and Biometrics screens are excluded, they have no
document-extractable content.
label,validators,visible/requiredOn(MVEL expressions),group,fieldCategory, etc. are stripped the OCR service does not need formrendering/validation metadata, only enough to match and shape values.
6.2 Response
erroris always structurally present alongsidemetadata/data(MDS-style)populated on failure,
null/empty on success. The client checkserror.errorCodeto decide which path to take, rather than branching onwhich top-level keys exist.
Success (
errorpresent but empty):{ "metadata": { "documentType": "Passport", "confidence": 0.94 }, "data": { "firstName": "sachin", "dateOfBirth": "26/02/1996", "passportNumber": "N1234567" }, "error": null }Failure (
errorpopulated,metadata/datanull/absent):{ "metadata": null, "data": null, "error": { "errorCode": "101", "errorInfo": "Document not detected in frame" } }metadata.documentTypeone of the recognized document types(Passport, Voter ID, PAN, Aadhaar, etc.). Unrecognized/unsupported values
are a failure outcome (8).
datais a flat map ofid: value, already matched by the OCRservice against the field ids from the spec sent in the request. No
client-side label/id reconciliation step is needed that responsibility
now sits with the OCR service.
error:errorCodeprovider-defined string code (e.g."101"), stable enoughto log/alert on and to map to a user-facing message if needed later.
errorInfohuman-readable detail for logs/audit, not shownverbatim to the operator (surfaced as the generic "couldn't read
document, try again or enter manually" message see 8), but recorded
in full in the audit trail (9) for troubleshooting.
error.errorCodeis populated andmetadata/dataare also populated is itself a contract violation and is treated as
malformed_response(8).6.2.1 OCR Error Codes
Standard
errorCodevalues every OCR provider implementation (remote oron-device, 4.1) must return where applicable. Providers may not repurpose
a standard code for a different meaning, use the
5xxrange for anythingnot covered below.
Codes 0 and 101–111 are required: every OCR provider implementation
(remote or on-device, 4.1) must return one of these where applicable,
using the exact code and the standard meaning above a provider cannot
repurpose, e.g.,
107to mean something other than license/credentialexpiry. The
5xxrange is the only optional/custom space, forprovider-specific conditions not covered by the required list.
Note: unlike the MDS biometric device contract (which includes a
transactionIdper capture), the OCR request/response contract in 6.1/6.2 has no transaction ID field, so there is no corresponding "invalid
transaction ID" error code here.
These are distinct from the client-detected failure reasons in 8
(
timeout,quality_check_failed,malformed_response, etc.), whichcover cases where the client either never got a well-formed response or
rejected the frame before it was ever sent to the provider. Codes 101–111
above are reasons the provider gives after receiving a request, the
client maps
errorCodetoprovider_errorin the audit/failure tableregardless of which specific code came back, and records the code and
message verbatim for troubleshooting.
6.3 Client-side validation (still required)
Even though the server returns spec-matched ids, the client must still:
error.errorCodefirst, before touchingmetadata/data. Ifnon-null/non-empty, treat as a provider-reported failure log
errorCode/errorInfoand fall back to manual entry (8), do notattempt to parse
metadata/datain this case.(defensive check against a contract violation see 8).
type/controlType (e.g.
26/02/1996→ theageDateformat the UIexpects,
YYYY/MM/DDper the existing regex validator). If conversionfails, drop only that field do not discard the rest of the response.
is applied as an editable pre-fill only.
7. Camera Capture
separate enable/disable branch for this, streaming is simply how capture
works.
scored for brightness, sharpness, framing, and liveliness. Live
feedback is shown to the operator (e.g. "too dark", "hold steady",
"align document").
operator triggers capture (or auto-capture fires), the most recent
quality scores are evaluated against
ocr.quality.thresholds.*.(6.1).
the captured frame is discarded, the client returns to the live
camera stream (does not proceed to OCR), and a specific,
actionable prompt is shown (e.g. "Image too dark move to better
light and rescan").
current scan session.
retries < ocr.quality.max_retries, the client stays in thecapture → quality-check → recapture loop automatically.
retries == ocr.quality.max_retries, the quality gate isrelaxed for one attempt: the client shows an explicit "Capture
anyway" control so the operator can force-send a sub-threshold
frame to OCR, or Cancel scan to fall back to manual entry. This
preserves the never-block requirement while making the default path
"retry until good," not "silently send bad images."
(auto-capture vs. manual-button-unlocked) are open decisions to confirm
with the architect before implementation see the pre-capture addendum
for detail.
and the retry count are logged alongside the OCR audit entry, correlated
by a shared capture/session id (9).
8. Failure Modes and Fallback
All failure paths land on the same manual-entry form no dialog, no crash,
no block:
quality_check_failed(retry logged, loops back to capture, not a terminal failure)quality_check_exhausted→ manual entryresponse.timeouttimeouterror.errorCodepopulated)provider_error(errorCode + errorInfo recorded verbatim in audit)error.errorCodeandmetadata/datapopulated)malformed_responsedocumentTypeunrecognized_document_typeunmatched_field(field dropped, not a full failure unless it's the only field)no_data_extractedA single bad field never discards the rest of a response only "zero
usable fields after validation" triggers full fallback to manual entry.
Similarly, a single failed quality check never blocks the operator it
triggers a recapture, and only exhausted retries (with the operator
declining to force-capture) fall back to manual entry.
9. Persistence and Audit
existing RegistrationDTO path no new persistence mechanism.
metadata.documentTypefromthe OCR response is written into packet metadata at persist time.
audited, including the trimmed spec payload sent (so field-matching
issues can be traced later) and the full camera quality-check history
for that capture/session id: each attempt's scores, pass/fail per
check, retry count, and whether a forced override was used.
error.errorCodeis populated (6.2), the auditentry records
errorCodeand the fullerrorInfostring verbatimthis is the primary field-matching/provider-side troubleshooting signal
and should not be truncated or paraphrased in logs.
All reactions