You are on page 1of 2

from PIL import Image

import pytesseract

path1 = "C:/Users/Vlad2002/Desktop/sample5.jpg"

im = Image.open(path1)

text = pytesseract.image_to_string(im, lang='eng')


print(text)
a = 0
b = 9
text1 = "0"
term = "plus"
term1 = "minus"
term2 = "impartit"
term3 = "inmultit"
number_of_characters = len(text)
words = text.split()
e = 1
x = len(words)
operator = 0
print(words)

for i in range(0, x):


c = words[i]
if c.isdigit():
text1 = text1 + c
e = 1
if e == 1:
if c.isalpha():
if term in c:
text1 = text1 + term
e = 0
text1 = text1.replace(term, " +")
else:
if term1 in c:
text1 = text1 + term1
text1 = text1.replace(term1, " -")
e = 0
else:
if term2 in c:
text1 = text1 + term1
text1 = text1.replace(term1, " /")
e = 0
else:
if term3 in c:
text1 = text1 + term1
text1 = text1.replace(term1, " *")
e = 0
words1 = text1.split()
x = len(words1)
operator = operator + int(words1[0])
print(words1)
for i in range(1, x):
c = words1[i]
if i != x - 1:
c1 = words1[i + 1]
if "+" in c:
if "/" in c1:
c1 = c1.replace("/", "")
operator = operator + (int(c) / int(c1))

else:
if "*" in c1:
c1 = c1.replace("*", "")
operator = operator + (int(c) * int(c1))

else:
c = c.replace("+", "")
operator = operator + int(c)

if "-" in c:
if "/" in c1:
c1 = c1.replace("/", "")
operator = operator + (int(c) / int(c1))

else:
if "*" in c1:
c1 = c1.replace("*", "")
operator = operator + (int(c) * int(c1))

else:
c = c.replace("-", "")
operator = operator - int(c)
print(operator)
print(operator)

You might also like