如何修复边界框中的文本大小?

发布于 2025-02-03 10:14:33 字数 1584 浏览 4 评论 0原文

我是计算机视觉的新手。我正在努力修复文本周围的边界框的大小。

这是示例代码

#extracting text using easyocr
    output = reader_hi.readtext('/content/drive/MyDrive/hindi_image.jpg')

    #translating words to other indian languages
    #removing text from images 
    
    #this is the code where I am pasting the translated words
    image = Image.open("image.jpg")#text removed from the image
    
    #red color
    color = (0, 0, 255)
    thickness = 1 
    
    fontpath = "/content/drive/MyDrive/ArialTh.ttf"
    TEXT_Font = ImageFont.truetype(fontpath, 16)
    
    draw = ImageDraw.Draw(image)
    
    i=0
    
    for bound in output:      
      tl, tr, br, bl = bound[0]
      
      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')

“翻译图像”

“文本周围的边界框”

我想将边界框大小调整到相同的大小。因此,当我粘贴翻译文本时,它将被一行对齐。

我可以在这部分上做一些更改,以便将翻译的文本在一行中对齐,

for bound in output:      
      tl, tr, br, bl = bound[0]
      
      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 am new to computer vision. I am struggling to fix the size of the bounding box around the text.

Here is the sample code

#extracting text using easyocr
    output = reader_hi.readtext('/content/drive/MyDrive/hindi_image.jpg')

    #translating words to other indian languages
    #removing text from images 
    
    #this is the code where I am pasting the translated words
    image = Image.open("image.jpg")#text removed from the image
    
    #red color
    color = (0, 0, 255)
    thickness = 1 
    
    fontpath = "/content/drive/MyDrive/ArialTh.ttf"
    TEXT_Font = ImageFont.truetype(fontpath, 16)
    
    draw = ImageDraw.Draw(image)
    
    i=0
    
    for bound in output:      
      tl, tr, br, bl = bound[0]
      
      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')

translated image

Glimpse of the bounding box around the text

I would like to resize the bounding box to same size. So that when I paste the translated text it would be aligned in one line.

Can I do some changes in this part so that the translated text will be aligned in one line

for bound in output:      
      tl, tr, br, bl = bound[0]
      
      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')

Is there some other way to make the text fall in one line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文