labelImg闪退问题深度解析
环境:Ubuntu16.04,python3.10
使用pip安装的labelImg点击绘制会发生闪退并报错:
Traceback (most recent call last):
File "/python3.10/site-packages/libs/canvas.py", line 530, in paintEvent
p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())
TypeError: arguments did not match any overloaded call:
drawLine(self, l: QLineF): argument 1 has unexpected type 'float'
drawLine(self, line: QLine): argument 1 has unexpected type 'float'
drawLine(self, x1: int, y1: int, x2: int, y2: int): argument 1 has unexpected type 'float'
drawLine(self, p1: QPoint, p2: QPoint): argument 1 has unexpected type 'float'
drawLine(self, p1: Union[QPointF, QPoint], p2: Union[QPointF, QPoint]): argument 1 has unexpected type 'float'
已放弃 (核心已转储)
原因:python3.8之后绘图函数不允许有非整数。
解决
1.打开报错提示的canvas.py文件
1.1 修改526行:
p.drawRect(left_top.x(), left_top.y(), rect_width, rect_height)
修改为:
p.drawRect(int(left_top.x()),int(left_top.y()), int(rect_width), int(rect_height))
1.2 530行:
p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())
修改为:
p.drawLine(int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))
1.3 531行:
p.drawLine(0, self.prev_point.y(),self.pixmap.width(), self.prev_point.y())
修改为
p.drawLine(0, int(self.prev_point.y()),int( self.pixmap.width()), int(self.prev_point.y()))
2.修改python3.10/site-packages/labelImg/labelImg.py
第950行
bar.setValue(bar.value() + bar.singleStep() * units)
修改为
bar.setValue(int(bar.value() + bar.singleStep() * units))
作者:code_crusher