【bug】PPOCRLabel p.drawRect(self, rect: QRectF): argument 1 has unexpected type ‘float’ TypeError: arguments did not match any overloaded call
环境
win 11
python 3.10
opencv-contrib-python 4.10.0.84
opencv-python 4.10.0.84
paddleocr 2.8.1
paddlepaddle 2.5.2
PPOCRLabel 2.1.3
PyQt5 5.15.11
PyQt5-Qt5 5.15.2
PyQt5_sip 12.15.0
xlrd 1.2.0
详情
在使用PPOCRLabel工具进行矩形标注
时弹出的错误,PPOCRLabel为标注ocr数据集的工具。
bug 详细输出
Traceback (most recent call last):
File "xxx\lib\site-packages\PPOCRLabel\libs\canvas.py", line 596, in paintEvent
p.drawRect(leftTop.x(), leftTop.y(), rectWidth, rectHeight)
TypeError: arguments did not match any overloaded call:
drawRect(self, rect: QRectF): argument 1 has unexpected type 'float'
drawRect(self, x: int, y: int, w: int, h: int): argument 1 has unexpected type 'float'
drawRect(self, r: QRect): argument 1 has unexpected type 'float'
原因:从输出可以发现,这是由于drawRect函数的输入坐标为float
类型引发的错误。
实际上,drawRect函数的输入坐标应该为整型int
。
解决方法
找到出现bug的canvas.py
中paintEvent
函数的 p.drawRect(leftTop.x(), leftTop.y(), rectWidth, rectHeight)
将里面坐标值强制转为int
:
p.drawRect(int(leftTop.x()), int(leftTop.y()), int(rectWidth), int(rectHeight))