You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Python复刻Project Naptha:实现全系统图片文本可选中复制功能

目标:

我正尝试复刻Project Naptha,这是一款Chrome浏览器扩展,支持在浏览器内从任意图片中选择并复制文本;我希望通过Python在全电脑及所有应用中实现该功能。

当前进展:

以下是我编写的图片OCR代码:

import pyautogui, keyboard, pytesseract, cv2

pytesseract.pytesseract.tesseract_cmd = r"C:\Users<<username>>\AppData\Local\Programs\Tesseract-OCR\tesseract.exe"

print("Press s to save position of first top-left corner of the screenshot.")
keyboard.wait("s")
x1, y1 = pyautogui.position()
print("Press s to save position of second bottom-right corner of the screenshot.")
keyboard.wait("s")
x2, y2 = pyautogui.position()

img = pyautogui.screenshot(region=(x1, y1, x2 - 280, y2 - 160))
#img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_text = pytesseract.image_to_string(img, lang="eng")
print("Recognition process done. Dumping into image_text.txt ...")

with open("image_text.txt", "w") as file:
    file.write(img_text)

该程序在按下s键时保存截图区域的左上角和右下角坐标,随后截取该区域并提取文本,最终将文本导出至image_text.txt文件。

预期效果:

我希望程序能自动扫描屏幕中的文本并使其可高亮选中,当选中文本后按下Ctrl+C时,文本可复制至剪贴板。

内容的提问来源于stack exchange,提问作者Oki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 17:20:28