LabelImg使用时报错:TypeError: setValue(self, val: int)

项目场景:

TypeError: setValue(self, val: int): argument 1 has unexpected type ‘float’
使用LabelImg时突然间报错了


问题描述

突然的报错让我很意外,怎么会突然报错呢,下面是报错原因

Traceback (most recent call last):
  File "D:\miniconda\envs\mm\lib\site-packages\labelImg\labelImg.py", line 1014, in zoom_request
    self.add_zoom(scale * units)
  File "D:\miniconda\envs\mm\lib\site-packages\labelImg\labelImg.py", line 974, in add_zoom
    self.set_zoom(self.zoom_widget.value() + increment)
  File "D:\miniconda\envs\mm\lib\site-packages\labelImg\labelImg.py", line 971, in set_zoom
    self.zoom_widget.setValue(value)
TypeError: setValue(self, val: int): argument 1 has unexpected type 'float'

原因分析:

这个错误是因为在调用 drawLine 函数时传入了一个浮动类型(float)的参数,而该函数期望的是整数类型(int)或其他合适的类型(如 QPoint 或 QLine)。


解决方案:

按照报错上面的路径打开到canvas.py文件,右击选择打开方式–>记事本,接着搜索drawLine,可以发现有两行都使用了这个函数,全部修改:

p.drawLine(int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))
p.drawLine(0, int(self.prev_point.y()), self.pixmap.width(), int(self.prev_point.y()))

这个文件还有一处要修改

p.drawRect(int(left_top.x()), int(left_top.y()), int(rect_width), int(rect_height))

完成之后再次运行,发现还会报错,接着继续修改。
按照报错路径,找到labelImg.py文件,同样的方式,右击选择打开方式–>记事本,不同的是搜索bar.setValue,更改,保存:

bar.setValue(int(bar.value() + bar.singleStep() * units))

至此,重新打开LabelImg,成功可以使用!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值