浏览代码

Cache exception when connecting only two points for polygon

Kentaro Wada 7 年之前
父节点
当前提交
3895d9664d
共有 2 个文件被更改,包括 10 次插入2 次删除
  1. 9 1
      labelme/canvas.py
  2. 1 1
      labelme/shape.py

+ 9 - 1
labelme/canvas.py

@@ -17,6 +17,10 @@
 # along with Labelme.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
+
+import sys
+
 try:
     from PyQt5.QtGui import *
     from PyQt5.QtCore import *
@@ -207,7 +211,11 @@ class Canvas(QWidget):
         if ev.button() == Qt.LeftButton:
             if self.drawing():
                 if self.current:
-                    self.current.addPoint(self.line[1])
+                    try:
+                        self.current.addPoint(self.line[1])
+                    except Exception as e:
+                        print(e, file=sys.stderr)
+                        return
                     self.line[0] = self.current[-1]
                     if self.current.isClosed():
                         self.finalise()

+ 1 - 1
labelme/shape.py

@@ -78,7 +78,7 @@ class Shape(object):
             self.line_color = line_color
 
     def close(self):
-        assert len(self.points) > 2
+        assert len(self.points) > 2, 'Polygon should be created with points >2'
         self._closed = True
 
     def addPoint(self, point):