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 如何對某些欄做格式化字串? apply(); applymap() ; map() 的差別? df[‘Salary’] = df[‘Salary’].map( ‘${:,.2f}’ .format) Python: pandas.DataFrame 如何對某些欄做格式化字串? apply(); applymap() ; map() 的差別? df[‘Salary’] = df[‘Salary’].map( ‘${:,.2f}’ .format)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/05/20230527091636_49.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: 如何在pandas.read_csv() or pandas.read_excel() 中使用keep_default_na =False , na_values =[] 保留文件中的原始“NA”? Python: 如何在pandas.read_csv() or pandas.read_excel() 中使用keep_default_na =False , na_values =[] 保留文件中的原始“NA”?](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2024/05/20240530215737_0.png?quality=90&zoom=2&ssl=1&resize=350%2C233)





近期留言