macOS Montereyでは、OCR機能にて日本語がサポート対象外であるため、このPythonスクリプトが役立ちます。Google Cloud Vision APIを使用して、スクリーンショット内のテキストを検出し、抽出したテキストをクリップボードにコピーできます。画像からのテキストや画面上のアクセス困難なテキスト領域から素早くテキストをコピーするのに便利なツールです。
※Google Cloud Vision APIの登録が必要です。(月1000回まで無料)
※VenturaであればOCR機能に日本語が追加されています。TRexがおすすめです。 ※TRex使ってみたけど日本語が中国の文字が入っていたりしそうなので、VisionAPIの方が綺麗な結果っぽいのでVenturaでも使える
This Python script allows you to capture a screenshot, detect text within the screenshot using Google Cloud Vision API, and copy the extracted text to your clipboard. It is a convenient tool to quickly copy text from images or inaccessible text regions on your screen.
- Python 3.6 or later
- Google Cloud Vision API credentials
- macOS
Before you run the script, make sure to install the following dependencies:
pip install google-cloud-vision
- Create a new Google Cloud project if you haven't already.
- Enable the Google Cloud Vision API for your project.
- Create a service account key for the Google Cloud Vision API. Download the JSON key file and set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the key file.
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"
- Run the script:
python screenshot_text_extractor.py
- When prompted, select the area of the screen you want to capture using the crosshair cursor.
- The script will detect any text within the screenshot and copy it to your clipboard.
- If the text was successfully copied to the clipboard, you'll see the message "Text copied to clipboard." Otherwise, an error message will be displayed.
- This script is designed for macOS, and may not work on other operating systems due to the use of the
screencapture
command andpbcopy
. - The text recognition quality depends on the Google Cloud Vision API.
If you encounter any issues or error messages, make sure you have set up your Google Cloud project, enabled the Vision API, and set the GOOGLE_APPLICATION_CREDENTIALS
environment variable correctly. If problems persist, refer to the Google Cloud Vision API documentation for more information.