LoginSignup
0
0

More than 1 year has passed since last update.

クリップボードの画像イメージから文字列を取り出し翻訳する

Posted at

クリップボードの画像イメージから文字列を取り出し翻訳する

Pythonでクリップボードの画像イメージから文字列を取り出し翻訳する手順を解説します。

👇この記事の内容は下記記事の内容を組み合わせて実現します

クリップボードの画像イメージから文字列を取り出し翻訳するコード

import pyocr
import pyocr.builders
import deepl
from PIL import ImageGrab, Image

DEEPL_AUTH_KEY:str = '****************************'

def main_logic():

    tool = pyocr.get_available_tools()[0]

    clip_img = ImageGrab.grabclipboard()
    if isinstance(clip_img,Image.Image):
        
        original_text = tool.image_to_string(clip_img,lang="tessdata/eng",builder=pyocr.builders.TextBuilder())
        print("----- original text ------")
        print(original_text)
        translator = deepl.Translator(DEEPL_AUTH_KEY)
        result = translator.translate_text(original_text, target_lang="JA")
        print("----- translated text ------")
        print(result.text)

    else:
        print("this is not image.")

if __name__ == '__main__':
    main_logic()

👇参考URL

クリップボードの画像イメージから文字列を取り出し翻訳する

更新日:2023/03/12

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0