报错:Traceback (most recent call last): File "D:\anaconda3_xz\envs\luopytorch\lib\threading.py", line 932, in _bootstrap_inner self.run() File "D:\anaconda3_xz\envs\luopytorch\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "D:\Pythonprojects\yolov5-7.0_222\utils\plots.py", line 305, in plot_images annotator.box_label(box, label, color=color) File "D:\Pythonprojects\yolov5-7.0_222\utils\plots.py", line 91, in box_label w, h = self.font.getsize(label) # text width, height AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
原因:Pillow
的新版中 FreeTypeFont
对象的 getsize
方法已被移除。
解决方法:1、Pillow降级,但是又容易出现其他问题
2、
使用 textbbox
方法获取文本尺寸;更新 box_label
方法:具体修改如下:
在utils/plots.py文件中修改box_label()
将原代码中的:
w, h = self.font.getsize(label) # text width, height
替换为:
bbox = self.font.getbbox(label) w = bbox[2] - bbox[0] h = bbox[3] - bbox[1]
问题解决,不再报错。
标签:box,yolov5,attribute,self,py,label,getsize,报错,bbox From: https://blog.csdn.net/m0_62144370/article/details/141679483