1

I'm trying to build a code to read the text from an image then Voice it over, and that what I already made ( shown below).

import pytesseract
import pyttsx3
from PIL import Image
engine = pyttsx3.init()


pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"
im=Image.open("E:\Capture.PNG")
engine.say(pytesseract.image_to_string(im,lang='eng'))
engine.runAndWait()
print(pytesseract.image_to_string(im,lang='eng'))

Fortunately, the code worked successfully, but, however, I want to improve it more by connecting the code to the external cam which I will use to take pictures then send it to Python to do his job. So, any suggestions to make the image path variable, instead of im=Image.open("E:\Capture.PNG"), I want the path to be dependent in the path in which my cam will send the taken image to. Thanks

Alselvdor
  • 13
  • 3
  • one way to make the path "variable" is to append a [datetime-stamp to the name of the file](https://stackoverflow.com/a/13891070/1248974): `ts = time.time(); dt = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d_%H%M%S'); path = os.path.join("E:", "Capture_{dt}.PNG".format(dt=dt))`. Then each image path will be dynamic and unique based on the time the camera saved the photo: e.g.`E:/Capture_20181204_124904.PNG` – chickity china chinese chicken Dec 04 '18 at 20:50
  • Thanks, that was helpful alot. – Alselvdor Dec 06 '18 at 20:23

0 Answers0