Image-to-text translate using Tesseract & OpenAI API
This project is using :
- Open AI API to translate text
- Tesseract-OCR to collect text from image
- Opencv to enchanting image processing
Requirement
From pytesseract
- Python-tesseract requires Python 3.6+
- You will need the Python Imaging Library (PIL) (or the Pillow fork). Under Debian/Ubuntu, this is the package python-imaging or python3-imaging.
- Install Google Tesseract-OCR (additional info how to install the engine on Linux, Mac OSX and Windows). You must be able to invoke the tesseract command as tesseract. If this isn’t the case, for example because tesseract isn’t in your PATH, you will have to change the “tesseract_cmd” variable
pytesseract.pytesseract.tesseract_cmd
. Under Debian/Ubuntu you can use the package tesseract-ocr. For Mac OS users. please install homebrew package tesseract. - More information is on the pytesseract documentation.
- OPEN AI API Key
HOW TO INSTALL
- After cloning this project go to the project directory
- Create constant.py
- Inside constant.py write
api_key = 'YOUR-OPENAI-API-KEY'
- open terminal ( cmd in windows )
pip install pytesseract
pip install pillow
pip install tk
pip install opencv-python
pip install openai
If issues appear this may help you
pip install --upgrade pip
HOW TO USE
- Save your image at the root folder of this project.
example : " C:\Image-to-text-Translate\ "
- At translate.py change the value inside
gambar
variable to your image name and extention.
gambar = 'YOUR_IMAGE_NAME.YOUR_IMAGE_EXTENSION' (example) :
gambar = myimage.png
- If you want to change the translated language, go to line 70 and change the following code:
response = openai.Completion.create(
engine=model_engine,
prompt="translate '" + text + "' to Bahasa",
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
to
response = openai.Completion.create(
engine=model_engine,
prompt="translate '" + text + "' to YOUR_LANGUAGE_CHOICE",
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
IMPORTANT
Supported Language.
- Eng
- Germany
- Italy
- French
- Korean
- Russian
- Chinese (sim)
- Vietnamese
- Thailand
Supported Image Extention
- jpeg
- jpg
- png
Future Update
- Symbolic languange and/or right-to-left recognation & translation.
- Enchanting image processing.
- Many more...
License & How to Contribute
This project is open for everyone, feel free to use it for any case.
But if you can, please don't delete my github username in the `translate.py` file. Thanks!