最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Correct coordinates text in images With the same coordinates pos(x,y) subtitle .srt - Stack Overflow

programmeradmin4浏览0评论

I have a text subtitle srt with coordinates example 270,270 video + sub srt

Result

When using "Pillow" or "opencv" or "tkinter" It gives you not the same coordinates. How can I get the same coordinates "{\pos(270,270)}Test" In the pictures above

Pillow

from PIL import Image, ImageDraw, ImageFont

# Load the image
image = Image.open("1.jpg")

# Create a drawing context
draw = ImageDraw.Draw(image)

# Define the text properties
font = ImageFont.truetype("Arial.ttf", 36)
text = "test"
text_color = (255, 255, 255)

# Calculate the position to center the text
text_length = draw.textlength(text, font)
x = 270
y = 270

# Add text to the image
draw.text((x, y), text, fill=text_color, font=font)

image.show()

Output .jpeg

opencv

import cv2

myimg = "1.jpg"

img = cv2.imread(myimg)

f_face = cv2.FONT_HERSHEY_PLAIN
f_size = 1
f_color = (255,255,255)
f_thickness = 2
text = 'Test'
x,y = 270,270
img = cv2.putText(img, text, (x,y), f_face, f_size, f_color, f_thickness)

cv2.imshow("Test", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output .jpeg

tkinter

import tkinter as tk
my_w = tk.Tk()
my_w.geometry("640x360")  # Size of the window 

l1=tk.Label(my_w,text='x=270,y=270',bg='yellow')
l1.place(x=270,y=270)

my_w.mainloop()  # Keep the window open

Output .jpeg

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论