feat(cardwallet): card-shaped camera frame with strict auto-scan

Open
#865 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
android, cpp, ios, opencv, typescript

Research direction

Start by verifying the coordinate space of live camera frames and captured images in all four orientations on Android and iOS; the issue notes that iOS currently passes imageRotation:0. Then read app/utils/cardFrame.ts and its tests for frame geometry and coordinate mapping, followed by the C++ DocumentDetector guide filtering and the Android and iOS option plumbing. Done means the frame, live detection, and capture crop stay aligned on both platforms, with the listed automated checks and device scenarios passing.

Written by the indexing model from the issue text.

Description

android enhancement ios wallet

Follow-up of #439 (card-shaped camera frame, suggested there by tedlatentai).

📋 Context

Cardwallet only. Edge detection struggles with cards (small, shiny, rounded corners). Draw an ID-1 (CARD_RATIO) frame on the camera preview and also give it to the detector, so live auto-scan and the post-capture detection only accept a card close to the frame. On by default, toggle in the camera view. The frame follows the screen orientation, a rotate button flips it. Captures are stored as captured.

Assumptions:

  • The cardwallet app rotates (Android screenOrientation="user", iOS all orientations), so the frame orientation comes from the camera view aspect, no sensor listener.
  • Hidden for QRCodeOnly, onlyForOCR, or when cropEnabled is false.

🛠️ Approach

  • Guide as detector option: a guide block in the existing options JSON { quad (normalized, upright), tolerance }, parsed in DocumentDetector::updateOptions. scanPoint only returns the best-by-area quad today; with a guide it first filters candidates by max corner distance (< tolerance × guide short side). Live and capture share one C++ implementation. A large frame puts the card at 35-50% of the image, so the area gate stops mattering.
  • Live path plumbing (no options today): Android nativeBufferScanJSON gets an options string (JNI + document_detector.cpp) and CustomImageAnalysisCallback.detectOptions; iOS OpencvDocumentProcessDelegate.detectOptions replaces options:nil. Only quads near the frame reach CropView and AutoScanHandler: auto-scan stays on and becomes strict. The polygon locking on the card + the progress arc are the "aligned" feedback.
  • Frame drawing: a canvasView over the preview (scrim with rounded hole + rounded stroke). Geometry from a pure getCardFrame: largest ID-1 rect fitting the visible preview (stretch mode, preview aspect) minus a margin; orientation from the view aspect + rotate override. Canvas size read in its draw callback: no layout measuring.
  • Orientation: pure rotateNormalizedQuad maps the screen-space guide to buffer/capture space (0/90/180/270). Guide recomputed and re-sent on every size/orientation change.
  • Capture: processCameraImage({ guide }) forwards the guide in the detection options. A matching quad is used; no match falls back to the guide quad, so the shot is never lost (even in auto-scan). Manual shots open the existing crop modal prefilled; auto-scan shots skip it, as today.
  • Toggle / rotate: buttons in the bottom-left stack next to batch mode, CARD_APP only. Toggle persists as cardFrame (default true), toast like toggleBatchMode. Rotate shows only when the frame is on; its override resets on screen orientation change.
  • Sharpness extension point: guide is a config object, so minSharpness can sit next to tolerance later; the detector already holds the upright Mat per frame (same pass for live + capture). Frame-colour callback to JS and result-shape change wait for that feature.
  • contoursApproxEpsilonFactor can be raised in guide mode through the same JSON for rounded corners (needs device tuning).
📂 Impacted files
File Action Description
app/utils/cardFrame.ts + cardFrame.test.ts Create Frame geometry, orientation rule, normalized guide quad, rotateNormalizedQuad
app/components/camera/Camera.svelte Edit Frame canvas, toggle + rotate buttons, cardFrame state, set detectOptions, pass the guide at capture
app/utils/ui/index.common.ts Edit processCameraImage({ guide }): options + fallback to the guide quad
plugin-nativeprocessor/index.d.ts Edit CornersOptions.guide type
cpp/src/include/DocumentDetector.h, cpp/src/DocumentDetector.cpp Edit guide option, candidate filter in scanPoint
plugin-nativeprocessor/platforms/android/cpp/document_detector.cpp Edit Options param on the live JNI call
.../CustomImageAnalysisCallback.kt Edit detectOptions property, forward to JNI
.../ios/src/OpencvDocumentProcessDelegate.{h,mm} Edit detectOptions property
app/utils/appIcons.ts + icon assets Edit Frame + rotate icons (sys:// iOS, res:// Android)
app/i18n/en.json Edit card_frame, card_frame_rotate
app/utils/constants.ts Edit Margin/tolerance constants, CARD_FRAME_ENABLED = true
📝 Steps
  1. Verify the coordinate space of live frames and capture files (raw vs EXIF-upright) in the 4 orientations on both platforms (iOS processSampleBuffer passes imageRotation:0 and ignores its computed rotation).
  2. cardFrame.ts test-first: frame fit, orientation from view aspect + override, guide quad, rotateNormalizedQuad.
  3. guide option in C++, filter ordering in scanPoint.
  4. Plumb detectOptions through Android (JNI + Kotlin) and iOS.
  5. Rebuild the plugin binaries (Android aar, iOS pod).
  6. Frame canvas, toggle, rotate button, persistence in Camera.svelte; re-apply the guide reactively on size/orientation change.
  7. processCameraImage({ guide }) with fallback to the guide quad.
  8. Icons and i18n keys.
  9. yarn svelte-check, npx eslint on changed files, npx vitest run app/utils/cardFrame.test.ts.
🧪 Test strategy
Type Scenario File
Unit Frame fits the visible preview: landscape/portrait, aspectFit/aspectFill, narrow/wide views cardFrame.test.ts
Unit Orientation follows the view aspect + rotate override cardFrame.test.ts
Unit rotateNormalizedQuad round trips for 0/90/180/270 cardFrame.test.ts
Manual (Android + iOS) Frame lines up with the capture content (iOS photo FOV vs preview) -
Manual (Android + iOS) Turn the phone in 4 orientations: frame, detection lock and capture crop stay aligned -
Manual (Android + iOS) Aligned card: auto-scan fires. Busy background / misaligned: no auto-scan. Shiny/rounded card works -
Manual Toggle off restores today's behaviour; persistence; rotate; auto-scan off gives a manual shot with the prefilled modal -

The C++ guide filter has no unit harness in the repo: covered by the device checks.

⚠️ Risks

  • Native rebuild (Android aar, iOS pod), on-device verification only.
  • iOS photo field of view may not match the preview.
  • A portrait capture of a landscape card is cropped by the aspectFill landscape tiles (card list, CardView). Optional later fix: a 90° page rotation, not part of this issue.
  • Rounded-corner vertex-count issue may need contoursApproxEpsilonFactor tuning rather than being fixed outright.

Automated plan by Claude — human validation required

Refs #439

Dominant language
C++
Stars
2.7k
Forks
153
Avg merge
9h 56m
Merged PRs (30d)
121

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ossappscollective/OSS-DocumentScanner

All issues in ossappscollective/OSS-DocumentScanner

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.