-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnablingTheBlindToReadCode.py
77 lines (64 loc) · 2.2 KB
/
EnablingTheBlindToReadCode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# import the following libraries
# will convert the image to text string
import pytesseract
# will connect webcam for near real-time detection
import cv2
# adds image processing capabilities
from PIL import Image
# converts the text to speech
#import pyttsx3
from gtts import gTTS
import os
#(optional feature, can implement later)
#translates into the mentioned language
#from googletrans import Translator
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
i=0 #to save all the clicked images
while(True):
ret, frame = cap.read()
cv2.imshow("PRESS C TO CAPTURE",frame)
key=cv2.waitKey(30)
if key==ord('q'):
break
if key==ord('c'):
#x=str(datetime.now())
#print(x)
#i+=1
cv2.imshow("Image Captured",frame)
cv2.imwrite('image'+str(i)+'.png', frame)
print("Wrote Image")
break
# release the capture
cap.release()
cv2.destroyAllWindows()
# opening an image from the source path
img = Image.open('image0.png')
# describes image format in the output
print(img)
# path where the tesseract module is installed
#pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract.exe'
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
# converts the image to result and saves it into result variable
result = pytesseract.image_to_string(img)
# write text in a text file and save it to source path
with open('abc.txt',mode ='w') as file:
file.write(result)
print(result)
#p = Translator()
# translates the text into german language
#k = p.translate(result,dest='german')
#print(k)
##engine = pyttsx3.init() #runs only in english
# an audio will be played which speaks the test if pyttsx3 recognizes it
##engine.say(result)
##engine.runAndWait()
# Passing the text and language to the engine,
# here we have marked slow=False. Which tells
# the module that the converted audio should
# have a high speed
myobj = gTTS(text=result, lang='en', slow=False)
# Saving the converted audio in a mp3 file named result
myobj.save("result.mp3")
# Playing the converted file
os.system("result.mp3")
#print("Would you like to translate the given text?")