Skip to content
Xeron
Go back

Python OCR 自动化脚本

编辑此页

Hyprland 下没找到舒服的 OCR 软件,用脚本代替。

所需软件:Tesseract(OCR 引擎)、Grim(Wayland 截屏)、Slurp(区域选择)、wl-clipboard(剪贴板)

安装:

sudo pacman -S tesseract grim slurp wl-clipboard

脚本内容

#!/bin/bash

# Take a screenshot with Grim and Slurp
grim -g "$(slurp)" /tmp/screenshot.png

# Perform OCR with both Chinese and English language support and copy the result to clipboard
tesseract /tmp/screenshot.png - -l chi_sim+eng | wl-copy

# Optionally, remove the screenshot file
rm /tmp/screenshot.png

赋予执行权限和移动脚本

  1. ocr_screenshot.sh 脚本保存到主目录(如 ~/ocr_screenshot.sh

  2. 赋予脚本执行权限:

    chmod +x ~/ocr_screenshot.sh
  3. 移动脚本到 /usr/local/bin 目录:

    sudo mv ~/ocr_screenshot.sh /usr/local/bin/

Hyprland 配置

  1. 打开Hyprland 配置文件,通常位于 ~/.config/hypr/hyprland.conf

  2. 添加以下行,将 SUPER + O 键组合绑定为执行 ocr_screenshot.sh 脚本:

    bind = SUPER, O, exec, ocr_screenshot.sh

编辑此页
Share this post on:

Previous Post
Wayland 下 Neovim 剪贴板配置
Next Post
ENS 域名注册指南