---
# System prepended metadata

title: 文字辨識

---

# 文字辨識
[參考資料](
https://steam.oxxostudio.tw/category/python/example/image-ocr.html)

註：用Colab嘗試時，中文套件要手動下載後上傳，自動會失敗
```python=
!sudo apt install tesseract-ocr
!sudo apt install libtesseract-dev
!wget https://github.com/tesseract-ocr/tessdata_best/blob/main/chi_tra.traineddata
!sudo mv chi_tra.traineddata /usr/share/tesseract-ocr/4.00/tessdata/
!pip install pytesseract
%env TESSDATA_PREFIX=/usr/share/tesseract-ocr/4.00/tessdata
```

```python=
from PIL import Image
import pytesseract

img = Image.open('/content/截圖 2023-06-18 下午9.37.11.png')
text = pytesseract.image_to_string(img, lang='chi_tra')
print(text)
```