0

The code below pastes the translated words based on the co-ordinates in output variable

image = Image.open("image.jpg")

#red color
color = (0, 0, 255)
thickness = 1 



fontpath = "/content/drive/MyDrive/ArialTh.ttf"

TEXT_Font = ImageFont.truetype(fontpath, 20)

draw = ImageDraw.Draw(image)

i=0

#output is the extracted words using easyocr so bound[0] are the co-ordinates
for bound in output:
  
  tl, tr, br, bl = bound[0]
  #TEXT = bound[1]
  tl = (int(tl[0]), int(tl[1]))
  tr = (int(tr[0]), int(tr[1]))
  br = (int(br[0]), int(br[1]))
  bl = (int(bl[0]), int(bl[1]))

  
  draw.text(tl, translation[i], font = TEXT_Font, align='left', fill='black') 
  i=i+1

image.save('image_translation.jpg')

This is the translation

translation = ['Srihari: 1',
 '1',
 'Good man',
 'A rich man built a temple. A priest was appointed to worship God in the temple. In order to run the temple, a lot of land, agriculture and gardens were given to the temple. Those who come to the temple hungry, miserable and saints, can stay there for a couple of days, they will get the offerings of God from the temple for their meal; He had made such an arrangement. Now they needed a man who could manage the temple funds and run the temple properly. Very interested people came to that rich man. He knew that whoever got the job of arranging this temple would get a good salary. But the rich man sent them all back. He used to say to everyone- I want a good man, I will choose him myself. Many people cursed the rich man in their hearts. A lot of people were calling him stupid or crazy. But the rich man did not listen to anyone. When the doors of the temple were opened and people started coming to see God, the rich man was sitting on the roof of his house and quietly watching the people coming to the temple.']

The problem is that the text is not being fully pasted. Can I know where the error is in the code. I am not able to locate it.

This is the image:

This is the image

Original image: Original image

berak
  • 1,226
  • 2
  • 5
  • 7
sha25
  • 23
  • 6

0 Answers0