然后你可以用我的答案here中的代码用单倍行距字体绘制。您只需要注释“Get a drawing context”后的3行。在
然后,可以使用以下命令转换回OpenCV图像:
^{pr2}$
可能是这样的:
#!/usr/local/bin/python3
from PIL import Image, ImageFont, ImageDraw
import numpy as np
import cv2
# Open image with OpenCV
im_o = cv2.imread('start.png')
# Make into PIL Image
im_p = Image.fromarray(im_o)
# Get a drawing context
draw = ImageDraw.Draw(im_p)
monospace = ImageFont.truetype("/Library/Fonts/Andale Mono.ttf",32)
draw.text((40, 80),"Hopefully monospaced",(255,255,255),font=monospace)
# Convert back to OpenCV image and save
result_o = np.array(im_p)
cv2.imwrite('result.png', result_o)
你可以很容易地用枕头/枕头。OpenCV图像是
numpy
数组,因此可以使用以下内容从OpenCV图像制作枕头图像:然后你可以用我的答案here中的代码用单倍行距字体绘制。您只需要注释“Get a drawing context”后的3行。在
然后,可以使用以下命令转换回OpenCV图像:
^{pr2}$可能是这样的:
或者,你可以让一个函数生成一块画布,在上面写上你的文本,然后把它拼接到你想要的OpenCV图像中。我不知道你需要什么样的灵活性,所以我没有把所有的东西都参数化:
关键词:OpenCV、Python、Numpy、PIL、pill、图像、图像处理、monospace、字体、字体、固定宽度、courier、HERSHEY。在
相关问题 更多 >
编程相关推荐