Auto Image Occlusion

AnkiWeb addon 1414192727

Automatically detects text regions in images using Tesseract OCR and creates configurable, merged image occlusion shapes with one click.
AI-generated summary; may contain mistakes.

card-creationshortcutsimage-occlusion

Open on AnkiWeb GitHub Find alternatives

AnkiWeb

Votes
5 (πŸ‘ 5 Β· πŸ‘Ž 0)
Updated
2026-09-09
Anki versions
26.08.1~
License
AGPL-3.0 (from the license file in the package)
Virus scan
No ClamAV match A match does not prove malware. No match does not prove that the code is safe.
Languages
Python, JSON
Description language
en

Maintenance

active

  • Last update or commit: 2026-09-09 (53 days before the snapshot).
  • Commits in the last year: 19.
  • Issues: 0 open, 7 closed.
  • Pull requests: 0 open, 0 merged.
  • Median first response: 549 hours (6 answered issues and pull requests).

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

pasteOCR has 1 fork β†’

Extracts text from clipboard images using Tesseract OCR, letting users paste screenshots of lecture slides or textbooks directly into Anki cards via a button or keyboard shortcut.

card-creationshortcutsbeta

16 votes 72% approval πŸ‘ 15 Β· πŸ‘Ž 1 ⭐ 6 Anki 2.1.16~ Updated 2023-02-26

Description

Auto Image Occlusion β€” Automatic Image Occlusion for Anki

Automatically detect text regions in images and create Image Occlusion shapes with a single click. Ideal for diagrams, anatomy labels, flowcharts, and other study materials with scattered or multi-line labels.

Key features

  • One-click auto-detection of text regions powered by Tesseract OCR (PSM 12 β€” sparse text with OSD)
  • Live Line Merge Tolerance in the toolbar:
    • Segmented split button right next to the magic wand ([ πŸͺ„ | ↕ 0.80 β–Ύ ])
    • Floating presets popover (Separate Lines 0.00, Tight Spacing 0.40, Standard 0.80, Wide Spacing 1.20, Aggressive Merge 1.50)
    • Precision slider & numeric input (0.00 to 1.50 with 0.01 fine-tuning)
    • Smooth mouse-wheel scrolling over the button or inputs to adjust tolerance by Β±0.01 on the fly (or Β±0.05 with Shift)
  • Smart Typographic Line Merging: Automatically unifies multi-line terms using universal typographic continuation rules (lowercase continuation, unclosed parentheses, and hyphens) without merging adjacent independent labels
  • Leader-line & diagram noise filtering: Cleans leader-line dashes, dots, and stray diagram artifacts to generate tight, precise occlusion boxes
  • Symmetric box padding: Built-in padding (box_padding: 4px) around detected text to eliminate glyph clipping
  • Collision detection to preserve existing manually placed occlusions
  • Customizable keyboard shortcut (default: Ctrl+Shift+X)
  • Zero Python dependencies: No Pillow, no pytesseract, and no dynamic wheel downloads β€” instant 0ms startup
  • Works seamlessly with Anki's native Image Occlusion editor (both Dark and Light modes)

Quick highlights

  • Instant & Lightweight: Zero external Python packages to install or compile. Uses Anki's bundled Qt and standard library.
  • Fast & Reliable: Tuned specifically for sparse labels, high-density diagrams, and noisy medical/scientific illustrations.
  • Intelligent Line Merging: Groups multi-line labels into a single cohesive occlusion card without merging unrelated labels.

Requirements

  • Anki 25.09+ (or any Anki version with native Image Occlusion support)
  • Tesseract OCR installed on your system

Quick install

  1. Install Tesseract on your operating system:

    • Debian / Ubuntu / Mint:
      sudo apt-get install tesseract-ocr
      
    • macOS (Homebrew):
      brew install tesseract
      
    • Windows: Download and run the installer from UB-Mannheim releases.
  2. Install this addon in Anki:

    • Via AnkiWeb code: 1414192727 (Tools > Add-ons > Get Add-ons...)
    • Or unpack the .ankiaddon file directly into your Anki addons21 folder.
    • Restart Anki β€” it is ready to use immediately with zero additional setup!

Configuration (examples)

Default configuration (Tools > Add-ons > Auto Image Occlusion > Config):

{
  "tesseract_lang": "eng",
  "min_confidence": 48,
  "vertical_merge_factor": 0.8,
  "box_padding": 4,
  "button_shortcut": "Ctrl+Shift+X"
}

More detections (blurry or low-contrast images):

{
  "min_confidence": 35,
  "min_area_percent": 0.00005
}

Fewer false positives (crisp, high-contrast diagrams):

{
  "min_confidence": 60,
  "min_area_percent": 0.001
}

Loose line spacing (diagrams with wider line gaps):

{
  "vertical_merge_factor": 1.2
}

No merging (each line separate):

{
  "vertical_merge_factor": 0
}

Custom shortcut (macOS):

{
  "button_shortcut": "Cmd+Alt+D"
}

Manual Tesseract executable path (if installed in a non-standard location):

{
  "tesseract_cmd": "/opt/homebrew/bin/tesseract"
}

How it works

  1. Captures the image directly from Anki's Image Occlusion editor.
  2. Direct subprocess invocation of your system's Tesseract binary with TSV structured output.
  3. Cleans leader-line artifacts, groups words into lines with confidence anchoring, and unifies multi-line labels using universal typographic continuation rules.
  4. Injects native occlusion rectangles with symmetric padding directly onto Anki's Fabric canvas for instant review and fine-tuning.

Troubleshooting tips

  • Nothing detected? Verify that Tesseract is installed on your system. Try lowering min_confidence (e.g. 35) or min_area_percent.
  • Tesseract not found? Standard paths on Windows, macOS (Homebrew/MacPorts), and Linux are auto-detected. If using a custom installation path, set "tesseract_cmd" in the addon configuration to the absolute path of the binary.
  • Labels merged too aggressively or kept separate? Adjust the merge factor directly from the toolbar split button (0.00 keeps every line separate; 0.80 is standard; 1.50 merges wider blocks).
  • Timeouts on giant images? Downscale images exceeding ~3000px before occluding for optimal OCR speed.

For full documentation, updates, and issue reports β€” visit the project on GitHub: https://github.com/BEST8OY/Auto-Image-Occlusion-Anki-Addon

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)