https://github.com/madmaze/pytesseract
安裝
$ pip install pytesseract
方法
- image_to_string:輸出識別的子串
- image_to_boxes:輸出識別的子串和邊界框
- image_to_data:輸出邊界框、置信度和一些其他信息
使用
``` python
try:
import Image
except ImportError:
from PIL import Image
import 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))
近期评论