小编Bug*_*Bug的帖子

Draw text on an angle (rotated) in Python

我在 Python 中将文本绘制到numpy数组图像上(使用自定义字体)。目前我正在将图像转换为 PIL,绘制文本然后转换回 numpy 数组。

import numpy as np
import cv2

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

char_image = np.zeros((200, 300, 3), np.uint8)

# convert to pillow image
pillowImage = Image.fromarray(char_image)
draw = ImageDraw.Draw(pillowImage)

# add chars to image
font = ImageFont.truetype("arial.ttf", 32)
draw.text((50, 50), 'ABC', (255, 255, 255), font=font)

# convert back to numpy array
char_image = np.array(pillowImage, np.uint8)

# show image on screen
cv2.imshow('myImage', char_image)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)

无论如何要在给定的角度绘制文本,即。33度?

绘制文本后旋转图像不是一种选择

python fonts rotation python-imaging-library python-3.x

4
推荐指数
2
解决办法
6616
查看次数