Auto Image Occlusion

AnkiWeb addon 1414192727

Automatically detects text regions in images and creates Image Occlusion shapes in Anki with one click, including multi-line merging, toolbar tolerance controls, and Tesseract OCR.
AI-generated summary; may contain mistakes.

card-creationimage-occlusion

Open on AnkiWeb GitHub Ask about alternatives

AnkiWeb

Rating
5 (πŸ‘ 5 Β· πŸ‘Ž 0)
Updated
2026-09-09
Anki versions
26.08.1~
Description language
en

Maintenance

active

  • Last update or commit was 22 days before the snapshot (2026-09-09).

Will it work on my Anki?

Version branches
Min AnkiMax AnkiUpdated
25.0926.08.1+2026-09-09
History across monthly snapshots

Loading…

Similar addons

README

Auto Image Occlusion - Anki Addon

Automatically detect text regions in images and create Image Occlusion shapes with one click. Works with Anki's native Image Occlusion editor (25.09+).

Anki Version License

Inspired by logseq-anki-sync

Features

  • One-click text detection via magic wand button in the IO toolbar
  • Changeable Merge Factor input right next to the magic wand (scroll wheel or type to adjust line-grouping tolerance on the fly)
  • Keyboard shortcut: Ctrl+Shift+X
  • Skips existing occlusions (collision detection)
  • Merges multi-line labels (configurable & dynamically adjustable)
  • Works with 100+ Tesseract languages
  • Zero Python dependencies (no Pillow, no pytesseract, no pip downloads)

Installation

Prerequisites: Tesseract OCR

Linux:

sudo apt-get install tesseract-ocr

macOS:

brew install tesseract

Windows: Download from GitHub releases, add C:\Program Files\Tesseract-OCR to PATH.

Additional languages: Install via package manager (e.g. sudo apt-get install tesseract-ocr-spa) or download .traineddata files from tessdata into Tesseract's tessdata directory.

Install Addon

AnkiWeb: Tools > Add-ons > Get Add-ons > code 1414192727

Manual: Copy this folder to your Anki addons directory:

  • Windows: %APPDATA%\Anki2\addons21\
  • macOS: ~/Library/Application Support/Anki2/addons21/
  • Linux: ~/.local/share/Anki2/addons21/

Restart Anki. The addon is ready to use immediately with zero setup.

Usage

  1. Open Add cards, select Image Occlusion note type
  2. Load your image
  3. Click the magic wand button or press Ctrl+Shift+X
  4. Wait 2-10 seconds for OCR processing
  5. Adjust the generated occlusion boxes as needed
  6. Click Add to create your cards

Configuration

Tools > Add-ons > Auto Image Occlusion > Config

{
    "tesseract_lang": "eng",
    "min_confidence": 48,
    "min_width": 4,
    "min_height": 4,
    "min_area_percent": 0.0001,
    "vertical_merge_factor": 0.8,
    "box_padding": 4,
    "button_shortcut": "Ctrl+Shift+X"
}
Option Default Description
tesseract_lang "eng" Language code. Use "eng+fra" for multiple
tesseract_cmd "" Path to tesseract binary. Auto-detects if empty
min_confidence 48 OCR confidence threshold (0-100). Lower = more detections
min_width 4 Minimum box width in pixels
min_height 4 Minimum box height in pixels
min_area_percent 0.0001 Minimum box area as fraction of image
vertical_merge_factor 0.8 Max vertical gap as multiple of line height. 0 to disable
box_padding 4 Symmetric padding in pixels around detected text boxes
button_shortcut "Ctrl+Shift+X" Keyboard shortcut (modifiers + key)

See config.md for detailed examples.

How It Works

  1. User clicks button, JS captures the image as base64
  2. Image sent to Python via pycmd()
  3. Tesseract runs PSM 12 (sparse text detection)
  4. Words are grouped by line, filtered by confidence/size/text-length
  5. Vertically close lines are merged (e.g. multi-line labels)
  6. Collision check against existing canvas shapes
  7. Results sent back to JS, which creates Rectangle shapes on the canvas

Troubleshooting

"TesseractNotFoundError": Tesseract isn't installed or not on PATH. Run tesseract --version to verify. On macOS with Homebrew, set tesseract_cmd in config (e.g. "/opt/homebrew/bin/tesseract").

"No text detected": Lower min_confidence (try 35) and min_area_percent (try 0.00005). Ensure image has clear, readable text.

"OCR timeout": Image too large. Reduce to ~1920px width.

Poor accuracy: Adjust min_confidence up (fewer false positives) or down (catch more text).

Architecture

__init__.py             # Addon entry point
addon.py                # Hook registration
editor_integration.py   # JS injection via editor_mask_editor_did_load_image hook
js_builder.py           # Generates injected JavaScript (button, OCR flow, canvas interaction)
message_handler.py      # pycmd() message routing (JS <-> Python)
ocr_engine.py           # Native Tesseract runner (PSM 12, line grouping, merging)

Credits

License

GNU AGPL v3+ (same as Anki)