1from PIL import Image
2import pytesseract
3
4image = 'PATH/TO/IMAGE'
5text = pytesseract.image_to_string(Image.open(image), lang="eng")
6print(text)
7
8# Code From here: https://www.youtube.com/watch?v=kxHp5ng6Rgw
1# Import some modules
2import cv2 # An image proccessing library
3import pytesseract # an image to text library
4import numpy as np # used for mathematics but can be used in image proccessing
5
6# Configure the module
7pytesseract.pytesseract.tesseract_cmd = r'C:\Users\yourname\AppData\Local\Tesseract-OCR\tesseract.exe'
8
9# Make the image grey
10img = cv2.imread('your_img.png')
11gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
12gray, img_bin = cv2.threshold(gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
13gray = cv2.bitwise_not(img_bin)
14kernel = np.ones((2, 1), np.uint8)
15img = cv2.erode(gray, kernel, iterations=1)
16img = cv2.dilate(img, kernel, iterations=1)
17# Use OCR to read the text from the image
18out_below = pytesseract.image_to_string(img)
19# Print the text
20print(out_below)
1from os import closerange
2from PIL import Image
3import pytesseract as tess
4tess.pytesseract.tessetact_cmd = r'give your PATH TO TESSETACT.EXE'
5
6image = r'complete path to image file'
7text = tess.image_to_string(Image.open(image), lang="eng")
8print(text)
1import Image
2import ImageDraw
3import ImageFont
4
5def getSize(txt, font):
6 testImg = Image.new('RGB', (1, 1))
7 testDraw = ImageDraw.Draw(testImg)
8 return testDraw.textsize(txt, font)
9
10if __name__ == '__main__':
11
12 fontname = "Arial.ttf"
13 fontsize = 11
14 text = "example@gmail.com"
15
16 colorText = "black"
17 colorOutline = "red"
18 colorBackground = "white"
19
20
21 font = ImageFont.truetype(fontname, fontsize)
22 width, height = getSize(text, font)
23 img = Image.new('RGB', (width+4, height+4), colorBackground)
24 d = ImageDraw.Draw(img)
25 d.text((2, height/2), text, fill=colorText, font=font)
26 d.rectangle((0, 0, width+3, height+3), outline=colorOutline)
27
28 img.save("D:/image.png")
29