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

项目场景:

TypeError: setValue(self, val: int): argument 1 has unexpected type 'float'

使用LabelImg时突然间报错了


问题描述

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

c 复制代码
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,可以发现有两行都使用了这个函数,全部修改:

python 复制代码
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()))

这个文件还有一处要修改

python 复制代码
p.drawRect(int(left_top.x()), int(left_top.y()), int(rect_width), int(rect_height))

完成之后再次运行,发现还会报错,接着继续修改。

按照报错路径,找到labelImg.py文件,同样的方式,右击选择打开方式-->记事本,不同的是搜索bar.setValue,更改,保存:

python 复制代码
bar.setValue(int(bar.value() + bar.singleStep() * units))

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

相关推荐
装不满的克莱因瓶2 小时前
链式法则如何传递参数误差 —— 深入理解神经网络中的梯度传播
人工智能·python·深度学习·神经网络·数学·机器学习·ai
Anastasiozzzz2 小时前
从有限状态机到智能体图:传统 FSM 与 Agent Graph的演进
java·人工智能·python·ai
biter down8 小时前
从 0 到 1 搭建 Python 接口自动化测试框架(博客系统实战)
开发语言·python
肖永威10 小时前
Python多业务并行计算框架插件化演进:从硬编码到动态注册
python·插件化·并行计算·动态注册
yz_aiks10 小时前
Linux Jar包配置Systemd自启动实战:从排查到配置全流程
linux·python·jar·自启动·systemd
不知名的老吴10 小时前
线程的生命周期之线程“插队“
java·开发语言·python
xsc69967511 小时前
从零搭建大模型与智能体平台 - 完整技术详解
python
无风听海12 小时前
多租户系统中的 OIDC:Discovery 端点与联合登录的深度实践
后端·python·flask
CTA终结者13 小时前
期货量化主力换月程序怎么移仓:天勤 underlying_symbol 与任务切换
python·区块链
马士兵教育13 小时前
Java还有前景吗?Java+AI大模型学习路线及项目?
java·人工智能·python·学习·机器学习