pip install pytesseract
(安裝套件)
點此可以安裝
Tesseract installer for Windows
code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 13 18:12:44 2023
@author: SavingKing
"""
import pytesseract
from PIL import Image
import os
# 指定 Tesseract 可执行文件的路径
pytesseract.pytesseract.tesseract_cmd = \
r'C:\Users\AppData\Local\Programs\Tesseract-OCR\tesseract.exe'
"""
pytesseract.pytesseract.tesseract_cmd 是一个变量,
用于指定 Tesseract OCR 的可执行文件(tesseract.exe)的路径。
通过设置这个变量,您可以告诉 pytesseract 库
在哪里找到 Tesseract OCR 引擎,以便进行图像文字识别。
通常情况下,您需要在代码中将
pytesseract.pytesseract.tesseract_cmd
设置为 Tesseract OCR 可执行文件的路径
"""
folder = "D:\Temp"
fname ="02.png"
fpath = os.path.join(folder,fname)
# 開啟圖片
image = Image.open(fpath)
# 使用 Tesseract 进行文字識別
text = pytesseract.image_to_string(image)
# 輸出識別結果
print(text)code:

推薦hahow線上學習python: https://igrape.net/30afN
![Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index) Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/04/20250420212553_0_6fb2c3.png?quality=90&zoom=2&ssl=1&resize=350%2C233)









近期留言