代码之家  ›  专栏  ›  技术社区  ›  JuanPKl

LabelImg在尝试标记时关闭,“Canvas.py”文件中出错

  •  0
  • JuanPKl  · 技术社区  · 2 年前
    • 所以: Windows 11 21H2
    • python 3.11.4
    • 版本标签Img: 1.8.6
    • 安装收集的软件包: pyqt5(5.15.9)、lxml(4.9.3)、pyqt5 sip(12.12.2)、pyqt5-Qt5(5.15.2)


    安装: pip安装标签


    问题:

    我正在使用YOLOv7开发一个对象检测模型,为此我需要“labelImg”工具,我可以安装它,我可以运行它。

    当我选择“创建RectBox”工具并将光标移动到图像上时(尚未进行任何选择), 程序关闭 .


    错误:

    C:\Users\Alecx>labelImg
    Traceback (most recent call last):
      File "C:\Users\Alecx\AppData\Local\Programs\Python\Python311\Lib\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'
    

    我试图用以下方式解决它:

    1. 尝试查看canvas.py中引用drawLine的代码部分,并检查参数是如何传递的。
      但我无法修复传递值的方式,以匹配drawLine函数所期望的类型。

    2. 尝试通过克隆存储库来安装“labelImg”(同样的错误)

    3. 安装所需软件包的早期版本,直观地感觉到这是最新版本中的错误。

    4. 我在Windows 10 Home上安装了它(同样的错误)

    您可以检查驱动器上的“Canvas.py”文件:

    Canvas.py

    0 回复  |  直到 2 年前
        1
  •  3
  •   Gnomioo    2 年前

    当几个人试图解决这些问题时,他们说要更改操作系统、Python版本和一系列其他更改,这些更改并不意味着解决了问题,而是转移到系统的另一个版本,这样就不会出现这个问题。 在这个答案中,我将教你如何在没有类似问题的情况下解决问题,答案是通过错误本身自学的,但让我们走吧。

    在Python目录中有一个名为 C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\libs ,进入其中并查找一个名为 canvas.py 。在此文件中,您将转到第526、530和531行,并更改进入drawLine函数的所有信息,如下所示。

    将第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)) .

    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())) .

    最后,第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())) .

    请注意,我只是在函数中声明变量为整数,这可能意味着对所绘制的图形进行了最小舍入,但在最终结果中没有任何具有最小有效维度的内容。

    之后,为了确保一切正常,在目录中 C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\labelImg 查找调用的代码 labelImg.py 并将其第965行更改为 bar.setValue(bar.value() + bar.singleStep() * units) bar.setValue(int(bar.value() + bar.singleStep() * units)) .

    说明:问题在于绘图函数读取这些变量时出错,如果我没记错的话,从Python 3.8版本开始,绘图函数目前不允许非整数。也就是说,这些修改应该适用于上述任何版本的Python,我甚至在3.11和3.12上测试过它,无论是Windows还是Linux,它都能正常工作。

        2
  •  -1
  •   hamidreza zarrabi    2 年前

    在Windows 10上未能解决问题后,我切换到了在线对象注释工具。有一些工具,但我选择了对象注释工具 Saiwa 因为它快速且易于使用。