cv2 resize 到指定大小_python在图片上添加指定字体的文字
时间: 2023-10-07 17:03:58 浏览: 44
好的,关于你的问题,cv2 resize 可以使用 OpenCV 库中的 resize 函数实现。具体操作代码如下:
```python
import cv2
img = cv2.imread('example.jpg') # 读取图片
resized_img = cv2.resize(img, (800, 600)) # 将图片大小调整为 800*600
cv2.imshow('Resized Image', resized_img) # 显示调整后的图片
cv2.waitKey(0) # 等待按键
cv2.destroyAllWindows() # 关闭窗口
```
另外,关于在图片上添加指定字体的文字,可以使用 PIL 库中的 ImageFont 和 ImageDraw 模块实现。具体操作代码如下:
```python
from PIL import Image, ImageFont, ImageDraw
img = Image.open('example.jpg') # 读取图片
draw = ImageDraw.Draw(img) # 创建 ImageDraw 对象
font = ImageFont.truetype('arial.ttf', 36) # 加载指定字体,大小为 36
draw.text((50, 50), 'Hello World', font=font, fill=(255, 255, 255)) # 在图片上添加文字
img.show() # 显示添加文字后的图片
```
以上是针对你的问题的解答,希望能够帮到你。
阅读全文
相关推荐



















