【已解决】attributeerror: ‘FreeTypeFont‘ object has no attribute ‘getsize‘

简介: 【已解决】attributeerror: ‘FreeTypeFont‘ object has no attribute ‘getsize‘

问题

报错:attributeerror: ‘FreeTypeFont’ object has no attribute ‘getsize’

运行yolo代码时,出现如下面的报错

原因分析

看过很多博客分析,都是说FreeTypeFont 字体的原因,其实真实问题出现yolo版本安装的Pillow库更新后,getsize()方法已经抛弃使用了,而你拉下来的代码肯定是github之前的老旧版本

解决方法

解决步骤

如图,之前版本是10.2.0,安装9.5会自动卸载原来版本

很简单,把Pillow库还原回之前的版本就行

pip install Pillow==9.5

关于Pillow库

Pillow 是 Python 中一个非常流行的图像处理库,它是 PIL(Python Imaging Library)的一个分支,PIL 最初由 Fredrik Lundh 在 1997 年创建。Pillow 提供了大量的图像文件格式支持,并且可以用于执行多种图像处理操作。


以下是 Pillow 的一些主要特性:

文件格式支持:Pillow 支持打开和保存许多不同格式的图像文件,包括但不限于 PNG, JPEG, TIFF, BMP, GIF 和 WebP。


图像操作:可以对图像进行多种变换,如缩放、裁剪、旋转、翻转、过滤等。


绘图:可以直接在图像上绘制文本、线条、多边形等图形。


颜色处理:可以处理不同模式的图像,如灰度、RGB、CMYK、HSV 等。


透明度和掩码:支持透明度操作和使用掩码进行复杂的图像合成。


特效:提供多种图像特效,如模糊、锐化、平滑、边缘增强等。


安全处理:Pillow 可以安全地处理文件路径和图像数据,减少安全漏洞的风险。


元数据:可以读取和写入图像文件的元数据。


动画:支持创建和操作 GIF 和其他格式的动画。


易于安装:通过 pip 可以很容易地安装 Pillow。

安装 Pillow 非常简单,你可以使用 pip 命令进行安装:

pip install Pillow

以下是使用 Pillow 打开图像、进行一些基本操作并保存图像的简单示例:

from PIL import Image

# 打开图像文件
img = Image.open("example.jpg")

# 将图像转换为灰度图像
img_gray = img.convert("L")

# 将图像旋转45度
img_rotate = img.rotate(45, expand=True)

# 将图像保存到文件
img_rotate.save("rotated_example.jpg")

# 在图像上绘制文本
draw = ImageDraw.Draw(img)
draw.text((20, 20), "Hello, Pillow!", (255, 255, 255))

# 显示图像
img.show()

Pillow 是图像处理和图形编程中一个非常强大且多用途的工具,它的灵活性和易用性使其成为 Python 图像处理的首选库之一。

相关文章
|
1月前
|
计算机视觉 Python
解决 NoneType‘ object has no attribute ‘astype’ 问题
解决 NoneType‘ object has no attribute ‘astype’ 问题
45 0
|
6天前
|
Python
【已解决】AttributeError: ‘Index‘ object has no attribute ‘to_list‘
【已解决】AttributeError: ‘Index‘ object has no attribute ‘to_list‘
5 0
|
1月前
|
机器学习/深度学习 监控 数据可视化
【已解决】 ‘Conv2d’ object has no attribute ‘register_full_backward_hook’
【已解决】 ‘Conv2d’ object has no attribute ‘register_full_backward_hook’
|
1月前
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
406 0
|
1月前
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
150 0
|
1月前
|
数据采集
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
401 0
|
1月前
'WebDriver' object has no attribute 'find_element_by_tag_name'
'WebDriver' object has no attribute 'find_element_by_tag_name'
173 0
|
1月前
|
Java
Java Object 类
5月更文挑战第16天
|
29天前
|
存储 算法 Java
滚雪球学Java(42):探索对象的奥秘:解析Java中的Object类
【5月更文挑战第17天】🏆本文收录于「滚雪球学Java」专栏,专业攻坚指数级提升,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!!
26 2
滚雪球学Java(42):探索对象的奥秘:解析Java中的Object类
|
7天前
|
Java
【Java】Object类简单解析
【Java】Object类简单解析
11 1