[英]Python : any ideas without using PIL to draw the text on a image
我使用的是 Python 3.3,我已經安裝了(只執行下載的文件 .exe,不需要任何設置?)從下面的鏈接中的 aspell PIL,不幸的是我導入 PIL 是錯誤未解決的 PIL。 為什么?
http://www.lfd.uci.edu/~gohlke/pythonlibs/
import PIL
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
font = ImageFont.truetype("C:/arial.ttf",25)
img=Image.new("RGBA", (200,200),(120,20,20))
draw = ImageDraw.Draw(img)
draw.text((0, 0),"This is a test",(255,255,0),font=font)
draw = ImageDraw.Draw(img)
draw = ImageDraw.Draw(img)
img.save("a_test.png")
或者有什么想法而不使用 PIL 在圖像上繪制文本?
因為它還沒有在 3.3 中發布。
“當前的免費版本是 PIL 1.1.7。此版本支持 Python 1.5.2 及更新版本,包括 2.5 和 2.6。稍后將發布 3.X 版本。” - 取自 PILs 主頁。
如果要使用 PIL,請使用 Python 2.6。 Python 的 3.X 版本對 python 進行了一些更改,因此它不完全向后兼容。
我建議您使用舊版本的 Python 而不是 3.X,除非您有充分的理由使用 3.X。
import cv2
font = cv2.FONT_HERSHEY_SIMPLEX
orgin = (50, 50)
fontScale = 1
color = (255, 0, 0)
thickness = 2
使用 cv2.putText() 方法
image = cv2.putText(image, 'OpenCV', org, font, fontScale, color, thickness, cv2.LINE_AA)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.