import pytesseract
from PIL import Image
# Load an image using PIL (Python Imaging Library)
img=Image.open('test_2.png')
img
# Custom configuration for Pytesseract
custom_config = r'-l eng --oem 3 --psm 6'
# Perform OCR on the image to extract text
text = pytesseract.image_to_string(img,config=custom_config)
# Print the extracted text
print(text)
Normal text and bold text Italic text and bold italic text Normal text and artificially bold text Artificially outlined text Artificially italic text and bold italic text
pytesseract
and Image
from the PIL
module (Pillow).¶Image.open()
function from the PIL library. Replace 'image.jpg'
with the path to your image file.¶custom_config
variable. This configuration includes parameters like -l eng
(language set to English), --oem 3
(using the LSTM OCR Engine), and --psm 6
(page segmentation mode set to assume a single uniform block of text).¶pytesseract.image_to_string()
function is used to perform OCR on the loaded image. The config
parameter is set to the custom_config
we defined earlier.¶text
variable.¶print()
function.¶