Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Created November 15, 2024 06:42
Show Gist options
  • Save sonsongithub/ae04d8324f350a8a05b84985473ca1f6 to your computer and use it in GitHub Desktop.
Save sonsongithub/ae04d8324f350a8a05b84985473ca1f6 to your computer and use it in GitHub Desktop.
Avoid labelImg from crashing when creating annotaion
--- canvas.original.py 2024-11-09 01:08:48
+++ canvas.py 2024-11-09 01:09:31
@@ -523,12 +523,12 @@
p.setPen(self.drawing_rect_color)
brush = QBrush(Qt.BDiagPattern)
p.setBrush(brush)
- 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))
if self.drawing() and not self.prev_point.isNull() and not self.out_of_pixmap(self.prev_point):
p.setPen(QColor(0, 0, 0))
- p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())
- p.drawLine(0, self.prev_point.y(), self.pixmap.width(), self.prev_point.y())
+ 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()), int(self.pixmap.width()), int(self.prev_point.y()))
self.setAutoFillBackground(True)
if self.verified:
--- labelImg.original.py 2024-11-09 01:08:27
+++ labelImg.py 2024-11-09 01:08:33
@@ -962,7 +962,7 @@
def scroll_request(self, delta, orientation):
units = - delta / (8 * 15)
bar = self.scroll_bars[orientation]
- bar.setValue(bar.value() + bar.singleStep() * units)
+ bar.setValue(int(bar.value() + bar.singleStep() * units))
def set_zoom(self, value):
self.actions.fitWidth.setChecked(False)
@sonsongithub
Copy link
Author

cd <path to python>/lib/python3.12/site-packages/labelImg
patch -u ./labelImg.py < labelImg.py.patch
cd <path to python>/lib/python3.12/site-packages/libs
patch -u ./canvas.py < canvas.py.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment