Fix QPointF IndexError: list index out of range (#11393)

* Fix QPointF IndexError: list index out of range

当QPointF 获取异常时,self.center  赋予默认值

* 增加QPointF异常时的提醒信息
pull/11390/head
firmament2008 2023-12-27 19:47:04 +08:00 committed by GitHub
parent 1f6712c370
commit b5e5dba3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import sys
from PyQt5.QtCore import QPointF from PyQt5.QtCore import QPointF
from PyQt5.QtGui import QColor, QPen, QPainterPath, QFont from PyQt5.QtGui import QColor, QPen, QPainterPath, QFont
from libs.utils import distance from libs.utils import distance
from ppocr.utils.logging import get_logger
DEFAULT_LINE_COLOR = QColor(0, 255, 0, 128) DEFAULT_LINE_COLOR = QColor(0, 255, 0, 128)
DEFAULT_FILL_COLOR = QColor(255, 0, 0, 128) DEFAULT_FILL_COLOR = QColor(255, 0, 0, 128)
@ -92,8 +93,15 @@ class Shape(object):
return pRes return pRes
def close(self): def close(self):
try:
self.center = QPointF((self.points[0].x() + self.points[2].x()) / 2, self.center = QPointF((self.points[0].x() + self.points[2].x()) / 2,
(self.points[0].y() + self.points[2].y()) / 2) (self.points[0].y() + self.points[2].y()) / 2)
except:
self.center = None
logger = get_logger()
logger.warning(
'The XY coordinates of QPointF are not detectable!'
)
self._closed = True self._closed = True
def reachMaxPoints(self): def reachMaxPoints(self):