admin管理员组文章数量:1247285
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
本文标签:
版权声明:本文标题:python - Correct coordinates text in images With the same coordinates pos(x,y) subtitle .srt - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740253805a2248991.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论