sudo apt-get install tesseract-ocr
brew install tesseract
pip install pytesseract
python
import pytesseract
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
python
import pytesseract
from PIL import Image
image = Image.open('example.png')
text = pytesseract.image_to_string(image)
print(text)
python
import pytesseract
from PIL import Image
lang = 'chi_sim'
image = Image.open('example.png')
text = pytesseract.image_to_string(image, lang=lang)
print(text)
python
import pytesseract
from PIL import Image
import cv2
image = Image.open('example.png')
gray_image = image.convert('L')
opencv_image = cv2.cvtColor(np.array(gray_image), cv2.COLOR_RGB2BGR)
_, threshold_image = cv2.threshold(opencv_image, 128, 255, cv2.THRESH_BINARY)
temp_file = 'temp.png'
cv2.imwrite(temp_file, threshold_image)
text = pytesseract.image_to_string(Image.open(temp_file))
print(text)
python
import pytesseract
import re
text = pytesseract.image_to_string(image)
text = ' '.join(text.split())
text = text.replace('O', '0')
date_pattern = r'\d{4}/\d{2}/\d{2}'
matches = re.findall(date_pattern, text)
print(text)
print(matches)