I've a requirement to translate images, I was able to use google vision to detect the text and translate it using google translator, once I get translated text, I've to replace the content of input given image with translated text, I've gone through the google translator document for images where they extract the text and translated but not adding the text to same template of input given image. so can anyone help me how can we do that. I'm building in python. Here is the sample code.
client = vision.ImageAnnotatorClient()
# Opens the input image file
with open(infile, "rb") as image_file:
content = image_file.read()
image = vision.Image(content=content)
# For dense text, use document_text_detection
# For less dense text, use text_detection
response = client.document_text_detection(image=image)
text = response.full_text_annotation.text
parent = f"projects/<project_id>/locations/global" # Your GCP project ID
request = translate.TranslateTextRequest(
contents=[text],
target_language_code="en",
parent=parent,
)
result = translate_client.translate_text(
request=request
)
for translate in result.glossary_translations:
print(translate.translated_text)
translated_text = result.glossary_translations[0].translated_text
Now I've to replace existing input image words with the translated text words
Thanks in advance