feat(cardwallet): card-shaped camera frame with strict auto-scan
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
- Domain
- computer-vision, mobile
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
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 whencropEnabledis false.
🛠️ Approach
- Guide as detector option: a
guideblock in the existing options JSON{ quad (normalized, upright), tolerance }, parsed inDocumentDetector::updateOptions.scanPointonly 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
nativeBufferScanJSONgets anoptionsstring (JNI +document_detector.cpp) andCustomImageAnalysisCallback.detectOptions; iOSOpencvDocumentProcessDelegate.detectOptionsreplacesoptions:nil. Only quads near the frame reachCropViewandAutoScanHandler: auto-scan stays on and becomes strict. The polygon locking on the card + the progress arc are the "aligned" feedback. - Frame drawing: a
canvasViewover the preview (scrim with rounded hole + rounded stroke). Geometry from a puregetCardFrame: 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
rotateNormalizedQuadmaps 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_APPonly. Toggle persists ascardFrame(default true), toast liketoggleBatchMode. Rotate shows only when the frame is on; its override resets on screen orientation change. - Sharpness extension point:
guideis a config object, sominSharpnesscan sit next totolerancelater; 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. contoursApproxEpsilonFactorcan 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
- Verify the coordinate space of live frames and capture files (raw vs EXIF-upright) in the 4 orientations on both platforms (iOS
processSampleBufferpassesimageRotation:0and ignores its computedrotation). cardFrame.tstest-first: frame fit, orientation from view aspect + override, guide quad,rotateNormalizedQuad.guideoption in C++, filter ordering inscanPoint.- Plumb
detectOptionsthrough Android (JNI + Kotlin) and iOS. - Rebuild the plugin binaries (Android aar, iOS pod).
- Frame canvas, toggle, rotate button, persistence in
Camera.svelte; re-apply the guide reactively on size/orientation change. processCameraImage({ guide })with fallback to the guide quad.- Icons and i18n keys.
yarn svelte-check,npx eslinton 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
aspectFilllandscape tiles (card list,CardView). Optional later fix: a 90° pagerotation, not part of this issue. - Rounded-corner vertex-count issue may need
contoursApproxEpsilonFactortuning 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ossappscollective/OSS-DocumentScanner
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ossappscollective/OSS-DocumentScanner#739 ·
Maintainers usually reply within 1 day
-
[BUG] Disabling JPEG Compression doesn't actually disable it and exported PDFs still get compressedOpenbug done
Difficulty 3/5 1-2 days Newbie friendliness 48/100
ossappscollective/OSS-DocumentScanner#882 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 52/100
ossappscollective/OSS-DocumentScanner#864 ·
Maintainers usually reply within 1 day
-
enhancement wallet
Difficulty 5/5 Over a week Newbie friendliness 35/100
ossappscollective/OSS-DocumentScanner#863 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 56/100
ossappscollective/OSS-DocumentScanner#816 ·
Maintainers usually reply within 1 day
All issues in ossappscollective/OSS-DocumentScanner
Similar issues
-
new issue
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
llvm/llvm-project#245835 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 72/100
EchoTools/nevr-runtime#2823 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
triton-lang/triton#12945 ·
Maintainers usually reply within 1 day
-
Releases do not move the `latest` Docker tag: the branch `30.12` is taken for the latest release branchPossibly taken @alexey-milovidov claimed this today. Opencomp-ci-infrastructure unexpected behaviour
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ClickHouse/ClickHouse#134282 ·
Maintainers usually reply within 1 day