python 使用 tesseract 進行光學字符檢測(ocr) French text image to string Get bounding box estimates Get verbose data including boxes, confidences, line and page numbers

https://github.com/madmaze/pytesseract

安裝

$ pip install pytesseract

方法

print(pytesseract.image_to_string(Image.open(‘test.png’)))

French text image to string

print(pytesseract.image_to_string(Image.open(‘test-european.jpg’), lang=’fra’))

Get bounding box estimates

print(pytesseract.image_to_boxes(Image.open(‘test.png’)))

Get verbose data including boxes, confidences, line and page numbers

print(pytesseract.image_to_data(Image.open(‘test.png’)))

也可以輸入 OpenCV 圖像或者 Numpy 數組
``` Python
import cv2

img = cv2.imread('/**path_to_image**/digits.png')
print(pytesseract.image_to_string(img))
# OR explicit beforehand converting
print(pytesseract.image_to_string(Image.fromarray(img))