Turn any image, screenshot, or manga panel into rich Anki cards in seconds.
A lightweight, local-first companion app running on-device via Termux (or desktop) that combines Google Lens OCR, Yomitan dictionary lookups, live image pre-processing filters, and 1-tap or automated Anki card image attachment.
When immersing in Japanese through games, manga, visual novels, or physical books, turning an unfamiliar sentence into an Anki flashcard should have as little friction as possible.
- ๐ฎ No capture card required. Just snap a photo of your Switch, TV, Steam Deck, or handheld screen with your phone.
- ๐ Works with any source. Physical novels, manga volumes, game screenshots, visual novels, emulators, hard-coded subs.
- ๐ Free & self-hosted. No accounts, no API keys, no subscriptions. The server runs on your own device and uses Google Lens for OCR โ no paid cloud services required.
CardLens is a guide through the visual mining loop:
- ๐ธ Capture from anywhere. Snap a photo, import a screenshot, drag-and-drop, or paste from your clipboard (
Ctrl+V). - โ๏ธ Crop & enhance. Pinch-to-crop on mobile or drag on desktop, with optional filters (contrast, sharpen, invert) to clean up stylized game text.
- ๐ Google Lens OCR. High-accuracy multilingual text recognition with automatic language detection.
- ๐ Dictionary-ready output. Clean, selectable text designed for Yomitan and other browser dictionary extensions โ tap a word to look it up instantly.
- ๐ด Automatic Anki attachment. Creates and attaches the cropped screenshot to your newest card automatically, or with one tap.
- ๐ฑ Runs on Android & desktop. Installable as a PWA on your phone or as a local server on Windows, macOS, and Linux.
[ Screen / Manga / Photo / Clipboard ]
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CardLens PWA (http://localhost:5050) โ
โ 1. Load image (Camera, Gallery, or Clipboard Paste) โ
โ 2. Crop text region with touch/mouse controls โ
โ 3. (Optional) Apply filters: Contrast/Sharpen/Invert โ
โ 4. Tap "Extract Text" โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ POST /ocr (Base64)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Starlette Backend (Termux on Android / Localhost:5050)โ
โ โข Google Lens OCR via chrome-lens-py โ
โ โข Returns: { "text": "ๅ้บใฎๅงใพใ..." } โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Firefox Android / Browser (Yomitan Extension) โ
โ โข Tap Japanese word in OCR text box โ
โ โข Yomitan pop-up shows definition + audio โ
โ โข Tap [+] to create Anki card โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Card created via AnkiConnect
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CardLens PWA โ
โ โข Auto-Attach: Polls diff & attaches automatically โ
โ OR Manual: Tap "Attach Image to Card" โ
โ โข storeMediaFile -> findNotes -> updateNoteFields โ
โ โข Cropped screenshot attached to note's Picture field!โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Important
Do not install Termux from Google Play (the Play Store build is abandoned and broken). Always install Termux from F-Droid.
- Install the following apps from F-Droid (or via direct APK downloads):
- Termux
- Termux:Widget (optional, for one-tap home screen launch; must be installed from F-Droid to match Termux's signing key)
- AnkiDroid
- AnkiConnect Android (from IzzyOnDroid F-Droid repo or GitHub releases)
- In Firefox for Android, install the Yomitan add-on and load your Japanese dictionary.
Open Termux on your phone and paste this single command:
apt update && apt full-upgrade -y && apt install -y curl && curl -sL https://raw.githubusercontent.com/valpr/card-lens/main/setup_termux.sh | bash
What this automated script does:
- Updates packages and installs
python,git, and build tools - Clones CardLens to
~/cardlensand installs dependencies in an isolatedvenv - Installs the global
cardlenscommand into your PATH - Sets up the home screen launcher for Termux:Widget
Android will kill background services by default unless you grant these:
- Go to Android Settings โ Apps โ Termux:
- Battery โ Select Unrestricted (or "Don't optimize").
- (If using Termux:Widget) Appear on top / Display pop-up window while running in background โ Allow.
- Open AnkiConnect Android and toggle the service to Started.
Pick whichever method you prefer:
- One-Tap Home Screen Shortcut (Termux:Widget): Long-press an empty space on your home screen โ Widgets โ Termux:Widget โ drag the Termux shortcut (1ร1) onto your screen and tap
CardLens.sh. - Terminal: Open Termux and simply run:
cardlens
- Open Firefox for Android and navigate to:
- Same Phone (Recommended โ 100% Features):
http://localhost:5050
Features: High-performance native in-app camera viewfinder, tap-to-focus, mechanical shutter audio, Yomitan dictionary lookups, and automatic AnkiConnect card attachment. - From Another Phone on Your Wi-Fi:
http://<server-ip>:5050
Features: Opens immediately over plain HTTP with zero SSL cert errors. Tapping the Camera button seamlessly opens your phone's native camera app (capture="environment"fallback). OCR, Yomitan lookups, and AnkiConnect proxy attachment work smoothly.
- Same Phone (Recommended โ 100% Features):
- Tap the Firefox menu (
โฎ) โ "Add to Home screen" (or "Install"). - Tap the CardLens icon on your home screen to use it in full-screen standalone mode!
- The first-time wizard will guide you to auto-configure with your Yomitan settings or Anki deck.
- Go to CardLens Releases and download the package for your OS:
- Windows:
CardLens-Windows-x64.zip - macOS:
CardLens-macOS.zip - Linux:
CardLens-Linux-x64.tar.gz
- Windows:
- Extract the archive and double-click
CardLens(CardLens.exeon Windows). - The server starts immediately and opens
http://localhost:5050in your default browser!
Run CardLens 24/7 on your PC or home server (Raspberry Pi, NAS, Unraid) so any phone or device on your Wi-Fi can mine without installing Termux:
docker run -d -p 5050:5050 --name cardlens --restart unless-stopped ghcr.io/valpr/card-lens:latest
Or with Docker Compose:
docker compose up -d
Then simply open http://<your-computer-ip>:5050 in your phone's browser!
# Option 1: Run directly with pipx pipx run cardlens # Option 2: Clone & run in virtual environment git clone https://github.com/valpr/card-lens.git cd card-lens python -m venv venv # Windows (PowerShell): venv\Scripts\Activate.ps1 # macOS / Linux: source venv/bin/activate pip install -r requirements.txt python main.py
CardLens on PC supports two streamlined workflows:
-
Mode 1: Anki Desktop with AnkiConnect (Automated & 1-Tap Attach)
- In Anki Desktop, go to Tools โ Add-ons (
Ctrl+Shift+A). - Click Get Add-ons..., paste code
2055492159, and restart Anki. - Keep Anki Desktop open in the background.
- Zero CORS Configuration: CardLens includes a built-in transparent AnkiConnect proxy (
/api/ankiconnect), so you never need to edit AnkiConnect'swebCorsOriginList! - Use 1-tap "๐ Attach Image to Card" (or Auto-Attach) to attach crops directly to new Yomitan cards.
- In Anki Desktop, go to Tools โ Add-ons (
-
Mode 2: Standalone Clipboard Mode (Zero Setup - No AnkiConnect Needed!)
- Don't have AnkiConnect or prefer adding cards manually?
- Paste any screenshot (
Ctrl+V) into CardLens and extract Japanese text with Google Lens OCR. - Hover text with Yomitan to read definitions and create cards.
- 1-Click "๐ Copy Image" (or press
I) or "๐ Copy Text" to copy the cropped panel straight to your clipboard and paste (Ctrl+V) directly into Anki Desktop's card fields!
When you open http://localhost:5050 for the first time, the Setup Wizard welcomes you with dedicated platform tabs:
- Option 1: AnkiConnect: Quickly copy the add-on code (
2055492159), click "โจ Auto-Detect from Recent Anki Card", and CardLens will automatically populate your target deck and picture field! - Option 2: ๐ Import Yomitan Settings JSON: Drop your
yomitan-settings.jsonexported from Yomitan to configure deck/fields instantly. - Option 3: โก Clipboard Mode: 1-Click to activate standalone mode without AnkiConnect.
- Option 1: AnkiConnect Android: Connect directly to AnkiDroid / AnkiConnect Android (
localhost:8765) and auto-detect your card. - Option 2: ๐ Import Yomitan Settings JSON: Drop your
yomitan-settings.jsonexported from Yomitan to configure deck/fields instantly. - Option 3: โก Clipboard Mode: 1-Click to activate standalone mode without AnkiConnect.
You can switch workflow modes or re-run the wizard anytime from the โ๏ธ Settings modal.
- Open
http://localhost:5050in Firefox on Android (or Chrome/Edge on Desktop). - Tap the browser menu (
โฎ) โ "Add to Home screen" (or "Install CardLens"). - Launch CardLens from your app launcher or desktop shortcut in full-screen standalone mode!
- Capture:
- Method A (Camera): Tap Camera and take a quick photo of your Switch screen, TV, or physical manga.
- Method B (Gallery / Screenshot): Select a screenshot from your device gallery.
- Method C (PC Clipboard Paste): Take a screenshot (
Win+Shift+S) and pressCtrl+Vin CardLens.
- Crop & Enhance:
- Drag the box selection around dialogue text or manga panel.
- (Optional) Tap a filter chip (
Contrast,Sharpen,Invert, orB&W) to boost readability. - Tap "Extract Text โ" (or press
Enter).
- Mine with Yomitan:
- Recognized text renders in large, selectable typography.
- Tap or hover any word with Yomitan to view definitions, readings, and pitch accents.
- Click the green
+button in Yomitan to create an Anki card.
- Attach Image / Copy to Clipboard:
- AnkiConnect Mode: Tap "๐ Attach Image to Card" (or let Auto-Attach run) to update the card in Anki.
- Clipboard Mode: Tap "๐ Copy Image" (or press
I) to copy the panel and paste (Ctrl+V) into Anki Desktop.
- Repeat:
- Tap "๐ New Capture" (or press
N) to jump straight to the next sentence.
- Tap "๐ New Capture" (or press
| Shortcut | Action |
|---|---|
Enter |
Crop & Extract Text |
R |
Rotate Image 90ยฐ Clockwise |
Shift + R |
Rotate Image 90ยฐ Counter-Clockwise |
A |
Attach Cropped Image to Anki Card |
I / Shift + C |
๐ Copy Cropped Image to Clipboard |
C |
โ๏ธ Adjust Crop Selection on Current Image |
E |
โ๏ธ Edit Extracted OCR Text Inline |
N |
๐ Start New Capture |
Escape |
Close Modal / Cancel Polling / Cancel Edit |
Ctrl + V |
Paste Image from Clipboard |
The codebase includes automated unit and integration tests covering the Starlette ASGI server, OCR pipeline, static assets, and AnkiConnect client:
# Run Python backend & OCR integration tests python -m unittest discover tests # Run AnkiConnect client unit tests (Node.js) node tests/test_ankiconnect.mjs # Run multilingual script-aware line merging unit tests (Node.js) node tests/test_line_merging.mjs # Validate AnkiConnect Android connectivity via bash bash test_ankiconnect.sh
card-lens/
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # Automated CI workflow
โ โโโ release.yml # Multi-platform binaries, Docker & GitHub Releases
โโโ cardlens.spec # PyInstaller desktop bundle specification
โโโ Dockerfile # Multi-arch container image
โโโ docker-compose.yml # Docker Compose configuration
โโโ pyproject.toml # Python packaging & pipx configuration
โโโ main.py # Starlette ASGI backend & OCR endpoint (POST /ocr)
โโโ run.sh # Server launcher & non-destructive updater
โโโ requirements.txt # Python dependencies
โโโ setup_termux.sh # Automated Termux installation script (Port 5050)
โโโ test_ankiconnect.sh # Bash verification script for AnkiConnect
โโโ LICENSE # BSD 3-Clause License
โโโ README.md # Project documentation & user guide
โโโ tests/
โ โโโ test_api.py # Backend API unit tests & static mount validation
โ โโโ test_ankiconnect.mjs # AnkiConnect JS client unit tests
โ โโโ test_line_merging.mjs # Line merging JS tests
โโโ frontend/
โโโ index.html # PWA single-page interface
โโโ styles.css # Dark OLED console styling
โโโ app.js # UI controller, camera capture, filters & audio cues
โโโ ankiconnect.js # AnkiConnect API client module & auto-attach polling
โโโ manifest.json # PWA web app manifest (CardLens)
โโโ sw.js # Service Worker (app shell offline caching)
โโโ icons/ # PWA app icons (192x192, 512x512, favicon, icon.ico)
โโโ vendor/
โโโ cropperjs/ # Vendored Cropper.js (offline ready)
Q: "Permission denied" error when running run.sh on Termux.
- Quick Fix: Run
chmod +x run.sh && ./run.shorbash run.sh. - Repository in Shared Storage: Make sure CardLens is located in Termux's internal home directory (
~/cardlensor/data/data/com.termux/files/home/cardlens), not in/sdcardor/storage/emulated/0. Android mounts external and shared storage withnoexec, preventing any script or binary execution.
Q: What if Google Lens OCR fails or changes?
The backend uses chrome-lens-py to interface with Google Lens. If the upstream endpoint ever changes, main.py is modularly structured so you can swap in alternative OCR engines (such as manga-ocr, easyocr, or Google Cloud Vision) behind the exact same POST /ocr contract without modifying the frontend.
Q: AnkiConnect gives a "Cannot connect" error on PC / Desktop.
- Is Anki running? Make sure the Anki Desktop application is open on your computer.
- Is AnkiConnect installed? In Anki Desktop, go to Tools โ Add-ons (
Ctrl+Shift+A), click Get Add-ons..., enter code2055492159, and restart Anki. - CORS issues? CardLens includes an automatic local proxy (
/api/ankiconnect), so browser CORS restrictions are handled automatically out of the box. - Prefer no add-ons? Switch to Clipboard Mode in โ๏ธ Settings โ Card Mining Workflow to copy cropped images directly to your clipboard (press
I) and paste (Ctrl+V) into Anki Desktop!
Q: AnkiConnect gives a "Cannot connect" error on Android.
- Ensure the AnkiConnect Android app is opened and the service is toggled to Started.
- Make sure battery optimization is disabled for AnkiConnect Android so Android does not kill the background service.
- Tap โ๏ธ Settings in CardLens and ensure the URL is set to
http://localhost:8765.
Q: The image was attached to the wrong field or note.
- By default, CardLens searches for the most recently added card in your configured deck (
deck:"Mining" added:1). Always tap "Attach Image" (or let Auto-Attach run) right after creating your card with Yomitan. - In Settings or the Setup Wizard, ensure Picture Field Name matches your note type's picture field (e.g.
Picture,Image, orScreenshot).
Q: Can I customize how the image tag is saved into the card?
Yes! In โ๏ธ Settings โ Image Field Template, you can change <img src="{filename}"> to any custom HTML format (e.g. <div class="screenshot"><img src="{filename}"></div>).
Zero-dependency hooks live in .githooks/ (enabled via core.hooksPath):
| Hook | What it does |
|---|---|
pre-commit |
Rejects whitespace errors, syntax-checks staged Python (py_compile) and JS (node --check), blocks files >1 MiB |
commit-msg |
Enforces Conventional Commits (`feat |
pre-push |
Fast checks only: Python compile + JS syntax + JS unit tests. Full suite (including live Lens OCR tests) runs in CI |
git config core.hooksPath .githooks
CI mirrors this server-side: ci.yml runs the full test suite on push/PR, and commitlint.yml validates commit message format (hooks can be bypassed with --no-verify).
BSD 3-Clause License. See LICENSE for details. Designed with โค๏ธ for Japanese language learners and immersion miners.