“e47f03d5f36547791d6726008c11c2d75d2d4bfd”上不存在“tests/system-test/git@gitcode.net:taosdata/tdengine.git”
提交 30fb939e 编写于 作者: qq_25193841's avatar qq_25193841

Add English readme and interface

上级 d0db3066
...@@ -25,7 +25,6 @@ from functools import partial ...@@ -25,7 +25,6 @@ from functools import partial
from collections import defaultdict from collections import defaultdict
import json import json
__dir__ = os.path.dirname(os.path.abspath(__file__)) __dir__ = os.path.dirname(os.path.abspath(__file__))
sys.path.append(__dir__) sys.path.append(__dir__)
sys.path.append(os.path.abspath(os.path.join(__dir__, '../..'))) sys.path.append(os.path.abspath(os.path.join(__dir__, '../..')))
...@@ -61,7 +60,7 @@ from libs.zoomWidget import ZoomWidget ...@@ -61,7 +60,7 @@ from libs.zoomWidget import ZoomWidget
from libs.autoDialog import AutoDialog from libs.autoDialog import AutoDialog
from libs.labelDialog import LabelDialog from libs.labelDialog import LabelDialog
from libs.colorDialog import ColorDialog from libs.colorDialog import ColorDialog
from libs.labelFile import LabelFile, LabelFileError, LabelFileFormat from libs.labelFile import LabelFile, LabelFileError
from libs.toolBar import ToolBar from libs.toolBar import ToolBar
from libs.ustr import ustr from libs.ustr import ustr
from libs.hashableQListWidgetItem import HashableQListWidgetItem from libs.hashableQListWidgetItem import HashableQListWidgetItem
...@@ -70,14 +69,13 @@ __appname__ = 'PPOCRLabel' ...@@ -70,14 +69,13 @@ __appname__ = 'PPOCRLabel'
class WindowMixin(object): class WindowMixin(object):
def menu(self, title, actions=None): def menu(self, title, actions=None):
menu = self.menuBar().addMenu(title) menu = self.menuBar().addMenu(title)
if actions: if actions:
addActions(menu, actions) addActions(menu, actions)
return menu return menu
def toolbar(self, title, actions=None): def toolbar(self, title, actions=None):
toolbar = ToolBar(title) toolbar = ToolBar(title)
toolbar.setObjectName(u'%sToolBar' % title) toolbar.setObjectName(u'%sToolBar' % title)
# toolbar.setOrientation(Qt.Vertical) # toolbar.setOrientation(Qt.Vertical)
...@@ -91,23 +89,35 @@ class WindowMixin(object): ...@@ -91,23 +89,35 @@ class WindowMixin(object):
class MainWindow(QMainWindow, WindowMixin): class MainWindow(QMainWindow, WindowMixin):
FIT_WINDOW, FIT_WIDTH, MANUAL_ZOOM = list(range(3)) FIT_WINDOW, FIT_WIDTH, MANUAL_ZOOM = list(range(3))
def __init__(self, defaultFilename=None, defaultPrefdefClassFile=None, defaultSaveDir=None, language="zh-CN"): def __init__(self,
lang="ch",
defaultFilename=None,
defaultPrefdefClassFile=None,
defaultSaveDir=None):
super(MainWindow, self).__init__() super(MainWindow, self).__init__()
self.setWindowTitle(__appname__) self.setWindowTitle(__appname__)
# Load setting in the main thread # Load setting in the main thread
self.settings = Settings() self.settings = Settings()
self.settings.load() self.settings.load()
settings = self.settings settings = self.settings
self.lang = lang
# Load string bundle for i18n # Load string bundle for i18n
if language not in ['zh-CN', 'en']: if lang not in ['ch', 'en']:
language = 'zh-CN' lang = 'en'
self.stringBundle = StringBundle.getBundle(localeStr=language) # 'en' self.stringBundle = StringBundle.getBundle(localeStr='zh-CN'
if lang == 'ch' else
'en') # 'en'
getStr = lambda strId: self.stringBundle.getString(strId) getStr = lambda strId: self.stringBundle.getString(strId)
self.defaultSaveDir = defaultSaveDir self.defaultSaveDir = defaultSaveDir
self.ocr = PaddleOCR(use_pdserving=False, use_angle_cls=True, det=True, cls=True, use_gpu=True, lang="ch") self.ocr = PaddleOCR(
use_pdserving=False,
use_angle_cls=True,
det=True,
cls=True,
use_gpu=False,
lang=lang)
if os.path.exists('./data/paddle.png'): if os.path.exists('./data/paddle.png'):
result = self.ocr.ocr('./data/paddle.png', cls=True, det=True) result = self.ocr.ocr('./data/paddle.png', cls=True, det=True)
...@@ -125,7 +135,6 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -125,7 +135,6 @@ class MainWindow(QMainWindow, WindowMixin):
self.labelFile = None self.labelFile = None
self.currIndex = 0 self.currIndex = 0
# Whether we need to save or not. # Whether we need to save or not.
self.dirty = False self.dirty = False
...@@ -157,12 +166,12 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -157,12 +166,12 @@ class MainWindow(QMainWindow, WindowMixin):
filelistLayout = QVBoxLayout() filelistLayout = QVBoxLayout()
filelistLayout.setContentsMargins(0, 0, 0, 0) filelistLayout.setContentsMargins(0, 0, 0, 0)
filelistLayout.addWidget(self.fileListWidget) filelistLayout.addWidget(self.fileListWidget)
self.AutoRecognition = QToolButton() self.AutoRecognition = QToolButton()
self.AutoRecognition.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.AutoRecognition.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.AutoRecognition.setIcon(newIcon('Auto')) self.AutoRecognition.setIcon(newIcon('Auto'))
# self.AutoRecognition.setIconSize(QSize(100,20)) # self.AutoRecognition.setIconSize(QSize(100,20))
self.AutoRecognition.setFixedSize(QSize(80,30)) # self.AutoRecognition.setFixedSize(QSize(80,30))
# self.AutoRecognition.setStyleSheet('text-align:center;')#border:none;font-size : 12pt; # self.AutoRecognition.setStyleSheet('text-align:center;')#border:none;font-size : 12pt;
autoRecLayout = QHBoxLayout() autoRecLayout = QHBoxLayout()
autoRecLayout.setContentsMargins(0, 0, 0, 0) autoRecLayout.setContentsMargins(0, 0, 0, 0)
...@@ -177,7 +186,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -177,7 +186,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.filedock.setObjectName(getStr('files')) self.filedock.setObjectName(getStr('files'))
self.filedock.setWidget(fileListContainer) self.filedock.setWidget(fileListContainer)
self.addDockWidget(Qt.LeftDockWidgetArea, self.filedock) self.addDockWidget(Qt.LeftDockWidgetArea, self.filedock)
######## Right area ########## ######## Right area ##########
listLayout = QVBoxLayout() listLayout = QVBoxLayout()
listLayout.setContentsMargins(0, 0, 0, 0) listLayout.setContentsMargins(0, 0, 0, 0)
...@@ -189,19 +198,18 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -189,19 +198,18 @@ class MainWindow(QMainWindow, WindowMixin):
self.editButton = QToolButton() self.editButton = QToolButton()
self.reRecogButton = QToolButton() self.reRecogButton = QToolButton()
self.reRecogButton.setIcon(newIcon('reRec', 30)) self.reRecogButton.setIcon(newIcon('reRec', 30))
self.reRecogButton.setFixedSize(QSize(80,30)) # self.reRecogButton.setFixedSize(QSize(80,30))
self.reRecogButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.reRecogButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.newButton = QToolButton() self.newButton = QToolButton()
self.newButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.newButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.newButton.setFixedSize(QSize(80, 30)) # self.newButton.setFixedSize(QSize(80, 30))
self.SaveButton = QToolButton() self.SaveButton = QToolButton()
self.SaveButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.SaveButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.SaveButton.setFixedSize(QSize(60, 30)) # self.SaveButton.setFixedSize(QSize(60, 30))
self.DelButton = QToolButton() self.DelButton = QToolButton()
self.DelButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.DelButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.DelButton.setFixedSize(QSize(80, 30)) # self.DelButton.setFixedSize(QSize(80, 30))
lefttoptoolbox = QHBoxLayout() lefttoptoolbox = QHBoxLayout()
lefttoptoolbox.addWidget(self.newButton) lefttoptoolbox.addWidget(self.newButton)
...@@ -210,7 +218,6 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -210,7 +218,6 @@ class MainWindow(QMainWindow, WindowMixin):
lefttoptoolboxcontainer.setLayout(lefttoptoolbox) lefttoptoolboxcontainer.setLayout(lefttoptoolbox)
listLayout.addWidget(lefttoptoolboxcontainer) listLayout.addWidget(lefttoptoolboxcontainer)
################## label list #################### ################## label list ####################
# Create and add a widget for showing current label items # Create and add a widget for showing current label items
self.labelList = QListWidget() self.labelList = QListWidget()
...@@ -221,7 +228,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -221,7 +228,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.labelList.itemDoubleClicked.connect(self.editLabel) self.labelList.itemDoubleClicked.connect(self.editLabel)
# Connect to itemChanged to detect checkbox changes. # Connect to itemChanged to detect checkbox changes.
self.labelList.itemChanged.connect(self.labelItemChanged) self.labelList.itemChanged.connect(self.labelItemChanged)
self.labelListDock = QDockWidget(getStr('recognitionResult'),self) self.labelListDock = QDockWidget(getStr('recognitionResult'), self)
self.labelListDock.setWidget(self.labelList) self.labelListDock.setWidget(self.labelList)
self.labelListDock.setFeatures(QDockWidget.NoDockWidgetFeatures) self.labelListDock.setFeatures(QDockWidget.NoDockWidgetFeatures)
listLayout.addWidget(self.labelListDock) listLayout.addWidget(self.labelListDock)
...@@ -251,7 +258,6 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -251,7 +258,6 @@ class MainWindow(QMainWindow, WindowMixin):
self.dock.setObjectName(getStr('labels')) self.dock.setObjectName(getStr('labels'))
self.dock.setWidget(labelListContainer) self.dock.setWidget(labelListContainer)
########## zoom bar ######### ########## zoom bar #########
self.imgsplider = QSlider(Qt.Horizontal) self.imgsplider = QSlider(Qt.Horizontal)
self.imgsplider.valueChanged.connect(self.CanvasSizeChange) self.imgsplider.valueChanged.connect(self.CanvasSizeChange)
...@@ -259,7 +265,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -259,7 +265,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.imgsplider.setMaximum(150) self.imgsplider.setMaximum(150)
self.imgsplider.setSingleStep(1) self.imgsplider.setSingleStep(1)
self.imgsplider.setTickPosition(QSlider.TicksBelow) self.imgsplider.setTickPosition(QSlider.TicksBelow)
self.imgsplider.setTickInterval(1) self.imgsplider.setTickInterval(1)
op = QGraphicsOpacityEffect() op = QGraphicsOpacityEffect()
op.setOpacity(0.2) op.setOpacity(0.2)
self.imgsplider.setGraphicsEffect(op) self.imgsplider.setGraphicsEffect(op)
...@@ -278,7 +284,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -278,7 +284,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.zoomWidget = ZoomWidget() self.zoomWidget = ZoomWidget()
self.colorDialog = ColorDialog(parent=self) self.colorDialog = ColorDialog(parent=self)
self.zoomWidgetValue = self.zoomWidget.value() self.zoomWidgetValue = self.zoomWidget.value()
########## thumbnail ######### ########## thumbnail #########
hlayout = QHBoxLayout() hlayout = QHBoxLayout()
m = (0, 0, 0, 0) m = (0, 0, 0, 0)
...@@ -287,7 +293,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -287,7 +293,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.preButton = QToolButton() self.preButton = QToolButton()
# self.preButton.setFixedHeight(100) # self.preButton.setFixedHeight(100)
# self.preButton.setText(getStr("prevImg")) # self.preButton.setText(getStr("prevImg"))
self.preButton.setIcon(newIcon("prev",40)) self.preButton.setIcon(newIcon("prev", 40))
self.preButton.setIconSize(QSize(40, 100)) self.preButton.setIconSize(QSize(40, 100))
self.preButton.clicked.connect(self.openPrevImg) self.preButton.clicked.connect(self.openPrevImg)
# self.preButton.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) # self.preButton.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
...@@ -301,7 +307,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -301,7 +307,8 @@ class MainWindow(QMainWindow, WindowMixin):
self.iconlist.setResizeMode(QListView.Adjust) self.iconlist.setResizeMode(QListView.Adjust)
# self.iconlist.itemDoubleClicked.connect(self.iconitemDoubleClicked) # self.iconlist.itemDoubleClicked.connect(self.iconitemDoubleClicked)
self.iconlist.itemClicked.connect(self.iconitemDoubleClicked) self.iconlist.itemClicked.connect(self.iconitemDoubleClicked)
self.iconlist.setStyleSheet("background-color:transparent; border: none;") self.iconlist.setStyleSheet(
"background-color:transparent; border: none;")
self.iconlist.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.iconlist.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# self.iconlist.setStyleSheet('border: none;') # self.iconlist.setStyleSheet('border: none;')
self.nextButton = QToolButton() self.nextButton = QToolButton()
...@@ -312,7 +319,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -312,7 +319,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.nextButton.setStyleSheet('border: none;') self.nextButton.setStyleSheet('border: none;')
self.nextButton.clicked.connect(self.openNextImg) self.nextButton.clicked.connect(self.openNextImg)
# self.nextButton.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) # self.nextButton.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
hlayout.addWidget(self.preButton) hlayout.addWidget(self.preButton)
hlayout.addWidget(self.iconlist) hlayout.addWidget(self.iconlist)
hlayout.addWidget(self.nextButton) hlayout.addWidget(self.nextButton)
...@@ -326,11 +333,12 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -326,11 +333,12 @@ class MainWindow(QMainWindow, WindowMixin):
# op = QGraphicsOpacityEffect() # op = QGraphicsOpacityEffect()
# op.setOpacity(0.5) # op.setOpacity(0.5)
# iconListContainer.setGraphicsEffect(op) # iconListContainer.setGraphicsEffect(op)
########### Canvas ########### ########### Canvas ###########
self.canvas = Canvas(parent=self) self.canvas = Canvas(parent=self)
self.canvas.zoomRequest.connect(self.zoomRequest) self.canvas.zoomRequest.connect(self.zoomRequest)
self.canvas.setDrawingShapeToSquare(settings.get(SETTING_DRAW_SQUARE, False)) self.canvas.setDrawingShapeToSquare(
settings.get(SETTING_DRAW_SQUARE, False))
scroll = QScrollArea() scroll = QScrollArea()
scroll.setWidget(self.canvas) scroll.setWidget(self.canvas)
...@@ -351,7 +359,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -351,7 +359,7 @@ class MainWindow(QMainWindow, WindowMixin):
centerLayout.setContentsMargins(0, 0, 0, 0) centerLayout.setContentsMargins(0, 0, 0, 0)
centerLayout.addWidget(scroll) centerLayout.addWidget(scroll)
#centerLayout.addWidget(self.icondock) #centerLayout.addWidget(self.icondock)
centerLayout.addWidget(iconListContainer,0,Qt.AlignCenter) centerLayout.addWidget(iconListContainer, 0, Qt.AlignCenter)
centercontainer = QWidget() centercontainer = QWidget()
centercontainer.setLayout(centerLayout) centercontainer.setLayout(centerLayout)
...@@ -363,12 +371,12 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -363,12 +371,12 @@ class MainWindow(QMainWindow, WindowMixin):
# tmpwidget = QWidget() # tmpwidget = QWidget()
# self.scrolldock.setTitleBarWidget(tmpwidget) # self.scrolldock.setTitleBarWidget(tmpwidget)
# del orititle # del orititle
self.setCentralWidget(centercontainer) #self.scrolldock self.setCentralWidget(centercontainer) #self.scrolldock
self.addDockWidget(Qt.RightDockWidgetArea, self.dock) self.addDockWidget(Qt.RightDockWidgetArea, self.dock)
# self.filedock.setFeatures(QDockWidget.DockWidgetFloatable) # self.filedock.setFeatures(QDockWidget.DockWidgetFloatable)
self.filedock.setFeatures(self.filedock.features() ^ QDockWidget.DockWidgetFloatable) self.filedock.setFeatures(self.filedock.features() ^
QDockWidget.DockWidgetFloatable)
self.dockFeatures = QDockWidget.DockWidgetClosable | QDockWidget.DockWidgetFloatable self.dockFeatures = QDockWidget.DockWidgetClosable | QDockWidget.DockWidgetFloatable
self.dock.setFeatures(self.dock.features() ^ self.dockFeatures) self.dock.setFeatures(self.dock.features() ^ self.dockFeatures)
...@@ -377,62 +385,118 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -377,62 +385,118 @@ class MainWindow(QMainWindow, WindowMixin):
###### Actions ####### ###### Actions #######
action = partial(newAction, self) action = partial(newAction, self)
quit = action(getStr('quit'), self.close, quit = action(
'Ctrl+Q', 'quit', getStr('quitApp')) getStr('quit'), self.close, 'Ctrl+Q', 'quit', getStr('quitApp'))
open = action(getStr('openFile'), self.openFile, open = action(
'Ctrl+O', 'open', getStr('openFileDetail')) getStr('openFile'), self.openFile, 'Ctrl+O', 'open',
getStr('openFileDetail'))
opendir = action(getStr('openDir'), self.openDirDialog,
'Ctrl+u', 'open', getStr('openDir')) opendir = action(
getStr('openDir'), self.openDirDialog, 'Ctrl+u', 'open',
openNextImg = action(getStr('nextImg'), self.openNextImg, getStr('openDir'))
'd', 'next', getStr('nextImgDetail'))
openNextImg = action(
openPrevImg = action(getStr('prevImg'), self.openPrevImg, getStr('nextImg'), self.openNextImg, 'd', 'next',
'a', 'prev', getStr('prevImgDetail')) getStr('nextImgDetail'))
verify = action(getStr('verifyImg'), self.verifyImg, openPrevImg = action(
'space', 'verify', getStr('verifyImgDetail')) getStr('prevImg'), self.openPrevImg, 'a', 'prev',
getStr('prevImgDetail'))
save = action(getStr('save'), self.saveFile,
'Ctrl+S', 'save', getStr('saveDetail'), enabled=False) verify = action(
getStr('verifyImg'), self.verifyImg, 'space', 'verify',
alcm = action(getStr('choosemodel'), self.autolcm, getStr('verifyImgDetail'))
'Ctrl+M', 'next', getStr('tipchoosemodel'))
save = action(
deleteImg = action(getStr('deleteImg'), self.deleteImg, 'Ctrl+D', 'close', getStr('deleteImgDetail'), getStr('save'),
enabled=True) self.saveFile,
'Ctrl+S',
resetAll = action(getStr('resetAll'), self.resetAll, None, 'resetall', getStr('resetAllDetail')) 'save',
getStr('saveDetail'),
color1 = action(getStr('boxLineColor'), self.chooseColor1, enabled=False)
'Ctrl+L', 'color_line', getStr('boxLineColorDetail'))
alcm = action(
createMode = action(getStr('crtBox'), self.setCreateMode, getStr('choosemodel'), self.autolcm, 'Ctrl+M', 'next',
'w', 'new', getStr('crtBoxDetail'), enabled=False) getStr('tipchoosemodel'))
editMode = action('&Edit\nRectBox', self.setEditMode,
'Ctrl+J', 'edit', u'Move and edit Boxs', enabled=False) deleteImg = action(
getStr('deleteImg'),
create = action(getStr('crtBox'), self.createShape, self.deleteImg,
'w', 'new', getStr('crtBoxDetail'), enabled=False) 'Ctrl+D',
'close',
delete = action(getStr('delBox'), self.deleteSelectedShape, getStr('deleteImgDetail'),
'Delete', 'delete', getStr('delBoxDetail'), enabled=False) enabled=True)
copy = action(getStr('dupBox'), self.copySelectedShape,
'Ctrl+D', 'copy', getStr('dupBoxDetail'), resetAll = action(
enabled=False) getStr('resetAll'), self.resetAll, None, 'resetall',
getStr('resetAllDetail'))
hideAll = action('&Hide\nRectBox', partial(self.togglePolygons, False),
'Ctrl+H', 'hide', getStr('hideAllBoxDetail'), color1 = action(
enabled=False) getStr('boxLineColor'), self.chooseColor1, 'Ctrl+L', 'color_line',
showAll = action('&Show\nRectBox', partial(self.togglePolygons, True), getStr('boxLineColorDetail'))
'Ctrl+A', 'hide', getStr('showAllBoxDetail'),
enabled=False) createMode = action(
getStr('crtBox'),
help = action(getStr('tutorial'), self.showTutorialDialog, None, 'help', getStr('tutorialDetail')) self.setCreateMode,
showInfo = action(getStr('info'), self.showInfoDialog, None, 'help', getStr('info')) 'w',
showSteps = action(getStr('steps'), self.showStepsDialog, None, 'help', getStr('steps')) 'new',
getStr('crtBoxDetail'),
enabled=False)
editMode = action(
'&Edit\nRectBox',
self.setEditMode,
'Ctrl+J',
'edit',
u'Move and edit Boxs',
enabled=False)
create = action(
getStr('crtBox'),
self.createShape,
'w',
'new',
getStr('crtBoxDetail'),
enabled=False)
delete = action(
getStr('delBox'),
self.deleteSelectedShape,
'Delete',
'delete',
getStr('delBoxDetail'),
enabled=False)
copy = action(
getStr('dupBox'),
self.copySelectedShape,
'Ctrl+D',
'copy',
getStr('dupBoxDetail'),
enabled=False)
hideAll = action(
getStr('hideBox'),
partial(self.togglePolygons, False),
'Ctrl+H',
'hide',
getStr('hideAllBoxDetail'),
enabled=False)
showAll = action(
getStr('showBox'),
partial(self.togglePolygons, True),
'Ctrl+A',
'hide',
getStr('showAllBoxDetail'),
enabled=False)
help = action(
getStr('tutorial'), self.showTutorialDialog, None, 'help',
getStr('tutorialDetail'))
showInfo = action(
getStr('info'), self.showInfoDialog, None, 'help', getStr('info'))
showSteps = action(
getStr('steps'), self.showStepsDialog, None, 'help',
getStr('steps'))
zoom = QWidgetAction(self) zoom = QWidgetAction(self)
zoom.setDefaultWidget(self.zoomWidget) zoom.setDefaultWidget(self.zoomWidget)
...@@ -442,21 +506,46 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -442,21 +506,46 @@ class MainWindow(QMainWindow, WindowMixin):
fmtShortcut("Ctrl+Wheel"))) fmtShortcut("Ctrl+Wheel")))
self.zoomWidget.setEnabled(False) self.zoomWidget.setEnabled(False)
zoomIn = action(getStr('zoomin'), partial(self.addZoom, 10), zoomIn = action(
'Ctrl++', 'zoom-in', getStr('zoominDetail'), enabled=False) getStr('zoomin'),
zoomOut = action(getStr('zoomout'), partial(self.addZoom, -10), partial(self.addZoom, 10),
'Ctrl+-', 'zoom-out', getStr('zoomoutDetail'), enabled=False) 'Ctrl++',
zoomOrg = action(getStr('originalsize'), partial(self.setZoom, 100), 'zoom-in',
'Ctrl+=', 'zoom', getStr('originalsizeDetail'), enabled=False) getStr('zoominDetail'),
fitWindow = action(getStr('fitWin'), self.setFitWindow, enabled=False)
'Ctrl+F', 'fit-window', getStr('fitWinDetail'), zoomOut = action(
checkable=True, enabled=False) getStr('zoomout'),
fitWidth = action(getStr('fitWidth'), self.setFitWidth, partial(self.addZoom, -10),
'Ctrl+Shift+F', 'fit-width', getStr('fitWidthDetail'), 'Ctrl+-',
checkable=True, enabled=False) 'zoom-out',
getStr('zoomoutDetail'),
enabled=False)
zoomOrg = action(
getStr('originalsize'),
partial(self.setZoom, 100),
'Ctrl+=',
'zoom',
getStr('originalsizeDetail'),
enabled=False)
fitWindow = action(
getStr('fitWin'),
self.setFitWindow,
'Ctrl+F',
'fit-window',
getStr('fitWinDetail'),
checkable=True,
enabled=False)
fitWidth = action(
getStr('fitWidth'),
self.setFitWidth,
'Ctrl+Shift+F',
'fit-width',
getStr('fitWidthDetail'),
checkable=True,
enabled=False)
# Group zoom controls into a list for easier toggling. # Group zoom controls into a list for easier toggling.
zoomActions = (self.zoomWidget, zoomIn, zoomOut, zoomActions = (self.zoomWidget, zoomIn, zoomOut, zoomOrg, fitWindow,
zoomOrg, fitWindow, fitWidth) fitWidth)
self.zoomMode = self.MANUAL_ZOOM self.zoomMode = self.MANUAL_ZOOM
self.scalers = { self.scalers = {
self.FIT_WINDOW: self.scaleFitWindow, self.FIT_WINDOW: self.scaleFitWindow,
...@@ -465,22 +554,46 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -465,22 +554,46 @@ class MainWindow(QMainWindow, WindowMixin):
self.MANUAL_ZOOM: lambda: 1, self.MANUAL_ZOOM: lambda: 1,
} }
edit = action(getStr('editLabel'), self.editLabel, edit = action(
'Ctrl+E', 'edit', getStr('editLabelDetail'), getStr('editLabel'),
enabled=False) self.editLabel,
'Ctrl+E',
'edit',
getStr('editLabelDetail'),
enabled=False)
######## New actions ####### ######## New actions #######
AutoRec = action(getStr('autoRecognition'), self.autoRecognition, AutoRec = action(
'Ctrl+Shift+A', 'Auto', getStr('autoRecognition'), enabled=False) getStr('autoRecognition'),
self.autoRecognition,
reRec = action(getStr('reRecognition'), self.reRecognition, 'Ctrl+Shift+A',
'Ctrl+Shift+R', 'reRec', getStr('reRecognition'), enabled=False) 'Auto',
getStr('autoRecognition'),
createpoly = action(getStr('creatPolygon'), self.createPolygon, enabled=False)
'p', 'new', 'Creat Polygon', enabled=True)
reRec = action(
saveRec = action(getStr('saveRec'), self.saveRecResult, getStr('reRecognition'),
'', 'saveRec', getStr('saveRec'), enabled=False) self.reRecognition,
'Ctrl+Shift+R',
'reRec',
getStr('reRecognition'),
enabled=False)
createpoly = action(
getStr('creatPolygon'),
self.createPolygon,
'p',
'new',
'Creat Polygon',
enabled=True)
saveRec = action(
getStr('saveRec'),
self.saveRecResult,
'',
'saveRec',
getStr('saveRec'),
enabled=False)
self.editButton.setDefaultAction(edit) self.editButton.setDefaultAction(edit)
self.newButton.setDefaultAction(create) self.newButton.setDefaultAction(create)
...@@ -511,12 +624,18 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -511,12 +624,18 @@ class MainWindow(QMainWindow, WindowMixin):
zoomContainer.setLayout(zoomLayout) zoomContainer.setLayout(zoomLayout)
zoomContainer.setGeometry(0, 0, 30, 150) zoomContainer.setGeometry(0, 0, 30, 150)
shapeLineColor = action(getStr('shapeLineColor'), self.chshapeLineColor, shapeLineColor = action(
icon='color_line', tip=getStr('shapeLineColorDetail'), getStr('shapeLineColor'),
enabled=False) self.chshapeLineColor,
shapeFillColor = action(getStr('shapeFillColor'), self.chshapeFillColor, icon='color_line',
icon='color', tip=getStr('shapeFillColorDetail'), tip=getStr('shapeLineColorDetail'),
enabled=False) enabled=False)
shapeFillColor = action(
getStr('shapeFillColor'),
self.chshapeFillColor,
icon='color',
tip=getStr('shapeFillColorDetail'),
enabled=False)
# labels = self.dock.toggleViewAction() # labels = self.dock.toggleViewAction()
# labels.setText(getStr('showHide')) # labels.setText(getStr('showHide'))
...@@ -527,92 +646,112 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -527,92 +646,112 @@ class MainWindow(QMainWindow, WindowMixin):
addActions(labelMenu, (edit, delete)) addActions(labelMenu, (edit, delete))
self.labelList.setContextMenuPolicy(Qt.CustomContextMenu) self.labelList.setContextMenuPolicy(Qt.CustomContextMenu)
self.labelList.customContextMenuRequested.connect( self.labelList.customContextMenuRequested.connect(self.popLabelListMenu)
self.popLabelListMenu)
# Draw squares/rectangles # Draw squares/rectangles
self.drawSquaresOption = QAction(getStr('drawSquares'), self) self.drawSquaresOption = QAction(getStr('drawSquares'), self)
self.drawSquaresOption.setShortcut('Ctrl+Shift+R') self.drawSquaresOption.setShortcut('Ctrl+Shift+R')
self.drawSquaresOption.setCheckable(True) self.drawSquaresOption.setCheckable(True)
self.drawSquaresOption.setChecked(settings.get(SETTING_DRAW_SQUARE, False)) self.drawSquaresOption.setChecked(
settings.get(SETTING_DRAW_SQUARE, False))
self.drawSquaresOption.triggered.connect(self.toogleDrawSquare) self.drawSquaresOption.triggered.connect(self.toogleDrawSquare)
# Store actions for further handling. # Store actions for further handling.
self.actions = struct(save=save, open=open, resetAll=resetAll, deleteImg=deleteImg, self.actions = struct(
lineColor=color1, create=create, delete=delete, edit=edit, copy=copy, save=save,
saveRec=saveRec, open=open,
createMode=createMode, editMode=editMode, resetAll=resetAll,
shapeLineColor=shapeLineColor, shapeFillColor=shapeFillColor, deleteImg=deleteImg,
zoom=zoom, zoomIn=zoomIn, zoomOut=zoomOut, zoomOrg=zoomOrg, lineColor=color1,
fitWindow=fitWindow, fitWidth=fitWidth, create=create,
zoomActions=zoomActions, delete=delete,
fileMenuActions=( edit=edit,
open, opendir, save, resetAll, quit), copy=copy,
beginner=(), advanced=(), saveRec=saveRec,
editMenu=(createpoly, edit, copy, delete, createMode=createMode,
None, color1, self.drawSquaresOption), editMode=editMode,
beginnerContext=(create, edit, copy, delete), shapeLineColor=shapeLineColor,
advancedContext=(createMode, editMode, edit, copy, shapeFillColor=shapeFillColor,
delete, shapeLineColor, shapeFillColor), zoom=zoom,
onLoadActive=( zoomIn=zoomIn,
create, createMode, editMode), zoomOut=zoomOut,
onShapesPresent=(hideAll, showAll)) zoomOrg=zoomOrg,
fitWindow=fitWindow,
fitWidth=fitWidth,
zoomActions=zoomActions,
fileMenuActions=(open, opendir, save, resetAll, quit),
beginner=(),
advanced=(),
editMenu=(createpoly, edit, copy, delete, None, color1,
self.drawSquaresOption),
beginnerContext=(create, edit, copy, delete),
advancedContext=(createMode, editMode, edit, copy, delete,
shapeLineColor, shapeFillColor),
onLoadActive=(create, createMode, editMode),
onShapesPresent=(hideAll, showAll))
# menus # menus
self.menus = struct( self.menus = struct(
file=self.menu('&'+getStr('mfile')), file=self.menu('&' + getStr('mfile')),
edit=self.menu('&'+getStr('medit')), edit=self.menu('&' + getStr('medit')),
view=self.menu('&'+getStr('mview')), view=self.menu('&' + getStr('mview')),
autolabel=self.menu('&PaddleOCR'), autolabel=self.menu('&PaddleOCR'),
help=self.menu('&'+getStr('mhelp')), help=self.menu('&' + getStr('mhelp')),
recentFiles=QMenu('Open &Recent'), recentFiles=QMenu('Open &Recent'),
labelList=labelMenu) labelList=labelMenu)
# Sync single class mode from PR#106 # Sync single class mode from PR#106
self.singleClassMode = QAction(getStr('singleClsMode'), self) self.singleClassMode = QAction(getStr('singleClsMode'), self)
self.singleClassMode.setShortcut("Ctrl+Shift+S") self.singleClassMode.setShortcut("Ctrl+Shift+S")
self.singleClassMode.setCheckable(True) self.singleClassMode.setCheckable(True)
self.singleClassMode.setChecked(settings.get(SETTING_SINGLE_CLASS, False)) self.singleClassMode.setChecked(
settings.get(SETTING_SINGLE_CLASS, False))
self.lastLabel = None self.lastLabel = None
# Add option to enable/disable labels being displayed at the top of bounding boxes # Add option to enable/disable labels being displayed at the top of bounding boxes
self.displayLabelOption = QAction(getStr('displayLabel'), self) self.displayLabelOption = QAction(getStr('displayLabel'), self)
self.displayLabelOption.setShortcut("Ctrl+Shift+P") self.displayLabelOption.setShortcut("Ctrl+Shift+P")
self.displayLabelOption.setCheckable(True) self.displayLabelOption.setCheckable(True)
self.displayLabelOption.setChecked(settings.get(SETTING_PAINT_LABEL, False)) self.displayLabelOption.setChecked(
settings.get(SETTING_PAINT_LABEL, False))
self.displayLabelOption.triggered.connect(self.togglePaintLabelsOption) self.displayLabelOption.triggered.connect(self.togglePaintLabelsOption)
addActions(self.menus.file, addActions(self.menus.file,
(opendir, None, save, resetAll, deleteImg, quit)) (opendir, None, save, resetAll, deleteImg, quit))
addActions(self.menus.help, (showSteps, showInfo)) addActions(self.menus.help, (showSteps, showInfo))
addActions(self.menus.view, ( addActions(
self.displayLabelOption, # labels, self.menus.view,
None, (
hideAll, showAll, None, self.displayLabelOption, # labels,
zoomIn, zoomOut, zoomOrg, None, None,
fitWindow, fitWidth)) hideAll,
showAll,
addActions(self.menus.autolabel, (saveRec, None, help)) # alcm, None,
zoomIn,
zoomOut,
zoomOrg,
None,
fitWindow,
fitWidth))
addActions(self.menus.autolabel, (alcm, saveRec, None, help)) #
self.menus.file.aboutToShow.connect(self.updateFileMenu) self.menus.file.aboutToShow.connect(self.updateFileMenu)
# Custom context menu for the canvas widget: # Custom context menu for the canvas widget:
addActions(self.canvas.menus[0], self.actions.beginnerContext) addActions(self.canvas.menus[0], self.actions.beginnerContext)
addActions(self.canvas.menus[1], ( addActions(self.canvas.menus[1], (action('&Copy here', self.copyShape),
action('&Copy here', self.copyShape), action('&Move here', self.moveShape)))
action('&Move here', self.moveShape)))
# self.tools = self.toolbar('Tools') # self.tools = self.toolbar('Tools')
self.actions.beginner = ( self.actions.beginner = (open, opendir, openNextImg, openPrevImg,
open, opendir, openNextImg, openPrevImg, verify, save, None, create, copy, delete, None, verify, save, None, create, copy, delete, None,
zoomIn, zoom, zoomOut, fitWindow, fitWidth) zoomIn, zoom, zoomOut, fitWindow, fitWidth)
self.actions.advanced = ( self.actions.advanced = (open, opendir, openNextImg, openPrevImg, save,
open, opendir, openNextImg, openPrevImg, save, None, None, createMode, editMode, None, hideAll,
createMode, editMode, None, showAll)
hideAll, showAll)
self.statusBar().showMessage('%s started.' % __appname__) self.statusBar().showMessage('%s started.' % __appname__)
self.statusBar().show() self.statusBar().show()
...@@ -636,7 +775,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -636,7 +775,8 @@ class MainWindow(QMainWindow, WindowMixin):
recentFileQStringList = settings.get(SETTING_RECENT_FILES) recentFileQStringList = settings.get(SETTING_RECENT_FILES)
self.recentFiles = [ustr(i) for i in recentFileQStringList] self.recentFiles = [ustr(i) for i in recentFileQStringList]
else: else:
self.recentFiles = recentFileQStringList = settings.get(SETTING_RECENT_FILES) self.recentFiles = recentFileQStringList = settings.get(
SETTING_RECENT_FILES)
size = settings.get(SETTING_WIN_SIZE, QSize(1200, 800)) size = settings.get(SETTING_WIN_SIZE, QSize(1200, 800))
...@@ -644,7 +784,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -644,7 +784,8 @@ class MainWindow(QMainWindow, WindowMixin):
saved_position = settings.get(SETTING_WIN_POSE, position) saved_position = settings.get(SETTING_WIN_POSE, position)
# Fix the multiple monitors issue # Fix the multiple monitors issue
for i in range(QApplication.desktop().screenCount()): for i in range(QApplication.desktop().screenCount()):
if QApplication.desktop().availableGeometry(i).contains(saved_position): if QApplication.desktop().availableGeometry(i).contains(
saved_position):
position = saved_position position = saved_position
break break
self.resize(size) self.resize(size)
...@@ -653,13 +794,14 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -653,13 +794,14 @@ class MainWindow(QMainWindow, WindowMixin):
self.lastOpenDir = ustr(settings.get(SETTING_LAST_OPEN_DIR, None)) self.lastOpenDir = ustr(settings.get(SETTING_LAST_OPEN_DIR, None))
self.restoreState(settings.get(SETTING_WIN_STATE, QByteArray())) self.restoreState(settings.get(SETTING_WIN_STATE, QByteArray()))
Shape.line_color = self.lineColor = QColor(settings.get(SETTING_LINE_COLOR, DEFAULT_LINE_COLOR)) Shape.line_color = self.lineColor = QColor(
Shape.fill_color = self.fillColor = QColor(settings.get(SETTING_FILL_COLOR, DEFAULT_FILL_COLOR)) settings.get(SETTING_LINE_COLOR, DEFAULT_LINE_COLOR))
Shape.fill_color = self.fillColor = QColor(
settings.get(SETTING_FILL_COLOR, DEFAULT_FILL_COLOR))
self.canvas.setDrawingColor(self.lineColor) self.canvas.setDrawingColor(self.lineColor)
# Add chris # Add chris
Shape.difficult = self.difficult Shape.difficult = self.difficult
# ADD: # ADD:
# Populate the File menu dynamically. # Populate the File menu dynamically.
self.updateFileMenu() self.updateFileMenu()
...@@ -692,19 +834,18 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -692,19 +834,18 @@ class MainWindow(QMainWindow, WindowMixin):
# Draw rectangle if Ctrl is pressed # Draw rectangle if Ctrl is pressed
self.canvas.setDrawingShapeToSquare(True) self.canvas.setDrawingShapeToSquare(True)
def noShapes(self): def noShapes(self):
return not self.itemsToShapes return not self.itemsToShapes
def populateModeActions(self): def populateModeActions(self):
self.canvas.menus[0].clear() self.canvas.menus[0].clear()
addActions(self.canvas.menus[0], self.actions.beginnerContext) addActions(self.canvas.menus[0], self.actions.beginnerContext)
self.menus.edit.clear() self.menus.edit.clear()
actions = (self.actions.create,) # if self.beginner() else (self.actions.createMode, self.actions.editMode) actions = (
self.actions.create,
) # if self.beginner() else (self.actions.createMode, self.actions.editMode)
addActions(self.menus.edit, actions + self.actions.editMenu) addActions(self.menus.edit, actions + self.actions.editMenu)
def setDirty(self): def setDirty(self):
self.dirty = True self.dirty = True
self.actions.save.setEnabled(True) self.actions.save.setEnabled(True)
...@@ -783,11 +924,12 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -783,11 +924,12 @@ class MainWindow(QMainWindow, WindowMixin):
def showInfoDialog(self): def showInfoDialog(self):
from libs.__init__ import __version__ from libs.__init__ import __version__
msg = u'Name:{0} \nApp Version:{1} \n{2} '.format(__appname__, __version__, sys.version_info) msg = u'Name:{0} \nApp Version:{1} \n{2} '.format(
__appname__, __version__, sys.version_info)
QMessageBox.information(self, u'Information', msg) QMessageBox.information(self, u'Information', msg)
def showStepsDialog(self): def showStepsDialog(self):
msg = steps() msg = stepsInfo(self.lang)
QMessageBox.information(self, u'Information', msg) QMessageBox.information(self, u'Information', msg)
def createShape(self): def createShape(self):
...@@ -834,12 +976,11 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -834,12 +976,11 @@ class MainWindow(QMainWindow, WindowMixin):
menu = self.menus.recentFiles menu = self.menus.recentFiles
menu.clear() menu.clear()
files = [f for f in self.recentFiles if f != files = [f for f in self.recentFiles if f != currFilePath and exists(f)]
currFilePath and exists(f)]
for i, f in enumerate(files): for i, f in enumerate(files):
icon = newIcon('labels') icon = newIcon('labels')
action = QAction( action = QAction(icon, '&%d %s' % (i + 1, QFileInfo(f).fileName()),
icon, '&%d %s' % (i + 1, QFileInfo(f).fileName()), self) self)
action.triggered.connect(partial(self.loadRecent, f)) action.triggered.connect(partial(self.loadRecent, f))
menu.addAction(action) menu.addAction(action)
...@@ -890,16 +1031,21 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -890,16 +1031,21 @@ class MainWindow(QMainWindow, WindowMixin):
try: try:
text_list = eval(text) text_list = eval(text)
except: except:
msg_box = QMessageBox(QMessageBox.Warning, 'Warning', 'Please enter the correct format') msg_box = QMessageBox(QMessageBox.Warning, 'Warning',
'Please enter the correct format')
msg_box.exec_() msg_box.exec_()
return return
if len(text_list) < 4: if len(text_list) < 4:
msg_box = QMessageBox(QMessageBox.Warning, 'Warning', 'Please enter the coordinates of 4 points') msg_box = QMessageBox(
QMessageBox.Warning, 'Warning',
'Please enter the coordinates of 4 points')
msg_box.exec_() msg_box.exec_()
return return
for box in text_list: for box in text_list:
if box[0] > width or box[0] < 0 or box[1] > height or box[1] < 0: if box[0] > width or box[0] < 0 or box[1] > height or box[
msg_box = QMessageBox(QMessageBox.Warning, 'Warning', 'Out of picture size') 1] < 0:
msg_box = QMessageBox(QMessageBox.Warning, 'Warning',
'Out of picture size')
msg_box.exec_() msg_box.exec_()
return return
...@@ -918,15 +1064,15 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -918,15 +1064,15 @@ class MainWindow(QMainWindow, WindowMixin):
def indexTo5Files(self, currIndex): def indexTo5Files(self, currIndex):
if currIndex < 2: if currIndex < 2:
return self.mImgList[:5] return self.mImgList[:5]
elif currIndex > len(self.mImgList)-3: elif currIndex > len(self.mImgList) - 3:
return self.mImgList[-5:] return self.mImgList[-5:]
else: else:
return self.mImgList[currIndex - 2 : currIndex + 3] return self.mImgList[currIndex - 2:currIndex + 3]
# Tzutalin 20160906 : Add file list and dock to move faster # Tzutalin 20160906 : Add file list and dock to move faster
def fileitemDoubleClicked(self, item=None): def fileitemDoubleClicked(self, item=None):
self.currIndex = self.mImgList.index(ustr(os.path.join(os.path.abspath(self.dirname), item.text()))) self.currIndex = self.mImgList.index(
ustr(os.path.join(os.path.abspath(self.dirname), item.text())))
filename = self.mImgList[self.currIndex] filename = self.mImgList[self.currIndex]
if filename: if filename:
self.mImgList5 = self.indexTo5Files(self.currIndex) self.mImgList5 = self.indexTo5Files(self.currIndex)
...@@ -943,7 +1089,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -943,7 +1089,8 @@ class MainWindow(QMainWindow, WindowMixin):
def CanvasSizeChange(self): def CanvasSizeChange(self):
if len(self.mImgList) > 0: if len(self.mImgList) > 0:
self.zoomWidget.setValue(self.zoomWidgetValue + self.imgsplider.value()) self.zoomWidget.setValue(self.zoomWidgetValue +
self.imgsplider.value())
# Add chris # Add chris
def btnstate(self, item=None): def btnstate(self, item=None):
...@@ -968,7 +1115,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -968,7 +1115,8 @@ class MainWindow(QMainWindow, WindowMixin):
shape.difficult = difficult shape.difficult = difficult
self.setDirty() self.setDirty()
else: # User probably changed item visibility else: # User probably changed item visibility
self.canvas.setShapeVisible(shape, item.checkState() == Qt.Checked) self.canvas.setShapeVisible(shape,
item.checkState() == Qt.Checked)
except: except:
pass pass
...@@ -1001,7 +1149,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1001,7 +1149,8 @@ class MainWindow(QMainWindow, WindowMixin):
# print('item in add label is ',[(p.x(), p.y()) for p in shape.points], shape.label) # print('item in add label is ',[(p.x(), p.y()) for p in shape.points], shape.label)
# ADD for box # ADD for box
item = HashableQListWidgetItem(str([(int(p.x()), int(p.y())) for p in shape.points])) item = HashableQListWidgetItem(
str([(int(p.x()), int(p.y())) for p in shape.points]))
# item = QListWidgetItem(str([(p.x(), p.y()) for p in shape.points])) # item = QListWidgetItem(str([(p.x(), p.y()) for p in shape.points]))
item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Checked) item.setCheckState(Qt.Checked)
...@@ -1062,7 +1211,10 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1062,7 +1211,10 @@ class MainWindow(QMainWindow, WindowMixin):
def updateComboBox(self): def updateComboBox(self):
# Get the unique labels and add them to the Combobox. # Get the unique labels and add them to the Combobox.
itemsTextList = [str(self.labelList.item(i).text()) for i in range(self.labelList.count())] itemsTextList = [
str(self.labelList.item(i).text())
for i in range(self.labelList.count())
]
uniqueTextList = list(set(itemsTextList)) uniqueTextList = list(set(itemsTextList))
# Add a null row for showing all the labels # Add a null row for showing all the labels
...@@ -1079,12 +1231,13 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1079,12 +1231,13 @@ class MainWindow(QMainWindow, WindowMixin):
def format_shape(s): def format_shape(s):
# print('s in saveLabels is ',s) # print('s in saveLabels is ',s)
return dict(label=s.label, # str return dict(
line_color=s.line_color.getRgb(), label=s.label, # str
fill_color=s.fill_color.getRgb(), line_color=s.line_color.getRgb(),
points=[(p.x(), p.y()) for p in s.points], # QPonitF fill_color=s.fill_color.getRgb(),
# add chris points=[(p.x(), p.y()) for p in s.points], # QPonitF
difficult=s.difficult) # bool # add chris
difficult=s.difficult) # bool
shapes = [] if mode == 'Auto' else \ shapes = [] if mode == 'Auto' else \
[format_shape(shape) for shape in self.canvas.shapes] [format_shape(shape) for shape in self.canvas.shapes]
...@@ -1092,7 +1245,11 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1092,7 +1245,11 @@ class MainWindow(QMainWindow, WindowMixin):
if self.model == 'paddle': if self.model == 'paddle':
for box in self.result_dic: for box in self.result_dic:
trans_dic = {"label": box[1][0], "points": box[0], 'difficult': False} trans_dic = {
"label": box[1][0],
"points": box[0],
'difficult': False
}
if trans_dic["label"] is "" and mode == 'Auto': if trans_dic["label"] is "" and mode == 'Auto':
continue continue
shapes.append(trans_dic) shapes.append(trans_dic)
...@@ -1100,7 +1257,11 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1100,7 +1257,11 @@ class MainWindow(QMainWindow, WindowMixin):
try: try:
trans_dic = [] trans_dic = []
for box in shapes: for box in shapes:
trans_dic.append({"transcription": box['label'], "points": box['points'], 'difficult': False}) trans_dic.append({
"transcription": box['label'],
"points": box['points'],
'difficult': False
})
self.PPlabel[annotationFilePath] = trans_dic self.PPlabel[annotationFilePath] = trans_dic
if mode == 'Auto': if mode == 'Auto':
...@@ -1120,7 +1281,6 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1120,7 +1281,6 @@ class MainWindow(QMainWindow, WindowMixin):
# fix copy and delete # fix copy and delete
self.shapeSelectionChanged(True) self.shapeSelectionChanged(True)
def labelSelectionChanged(self): def labelSelectionChanged(self):
item = self.currentItem() item = self.currentItem()
if item and self.canvas.editing(): if item and self.canvas.editing():
...@@ -1156,8 +1316,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1156,8 +1316,7 @@ class MainWindow(QMainWindow, WindowMixin):
position MUST be in global coordinates. position MUST be in global coordinates.
""" """
if len(self.labelHist) > 0: if len(self.labelHist) > 0:
self.labelDialog = LabelDialog( self.labelDialog = LabelDialog(parent=self, listItem=self.labelHist)
parent=self, listItem=self.labelHist)
# Sync single class mode from PR#106 # Sync single class mode from PR#106
if self.singleClassMode.isChecked() and self.lastLabel: if self.singleClassMode.isChecked() and self.lastLabel:
...@@ -1171,7 +1330,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1171,7 +1330,8 @@ class MainWindow(QMainWindow, WindowMixin):
if text is not None: if text is not None:
self.prevLabelText = self.stringBundle.getString('tempLabel') self.prevLabelText = self.stringBundle.getString('tempLabel')
# generate_color = generateColorByText(text) # generate_color = generateColorByText(text)
shape = self.canvas.setLastLabel(text, None, None)#generate_color, generate_color shape = self.canvas.setLastLabel(
text, None, None) #generate_color, generate_color
self.addLabel(shape) self.addLabel(shape)
if self.beginner(): # Switch to edit mode. if self.beginner(): # Switch to edit mode.
self.canvas.setEditing(True) self.canvas.setEditing(True)
...@@ -1185,7 +1345,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1185,7 +1345,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.canvas.resetAllLines() self.canvas.resetAllLines()
def scrollRequest(self, delta, orientation): def scrollRequest(self, delta, orientation):
units = - delta / (8 * 15) units = -delta / (8 * 15)
bar = self.scrollBars[orientation] bar = self.scrollBars[orientation]
bar.setValue(bar.value() + bar.singleStep() * units) bar.setValue(bar.value() + bar.singleStep() * units)
...@@ -1296,7 +1456,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1296,7 +1456,7 @@ class MainWindow(QMainWindow, WindowMixin):
titem = self.iconlist.item(i) titem = self.iconlist.item(i)
titem.setSelected(True) titem.setSelected(True)
self.iconlist.scrollToItem(titem) self.iconlist.scrollToItem(titem)
break break
else: else:
self.fileListWidget.clear() self.fileListWidget.clear()
self.mImgList.clear() self.mImgList.clear()
...@@ -1304,16 +1464,16 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1304,16 +1464,16 @@ class MainWindow(QMainWindow, WindowMixin):
# if unicodeFilePath and self.iconList.count() > 0: # if unicodeFilePath and self.iconList.count() > 0:
# if unicodeFilePath in self.mImgList: # if unicodeFilePath in self.mImgList:
if unicodeFilePath and os.path.exists(unicodeFilePath): if unicodeFilePath and os.path.exists(unicodeFilePath):
if LabelFile.isLabelFile(unicodeFilePath): if LabelFile.isLabelFile(unicodeFilePath):
try: try:
self.labelFile = LabelFile(unicodeFilePath) self.labelFile = LabelFile(unicodeFilePath)
except LabelFileError as e: except LabelFileError as e:
self.errorMessage(u'Error opening file', self.errorMessage(u'Error opening file', (
(u"<p><b>%s</b></p>" u"<p><b>%s</b></p>"
u"<p>Make sure <i>%s</i> is a valid label file.") u"<p>Make sure <i>%s</i> is a valid label file.") %
% (e, unicodeFilePath)) (e, unicodeFilePath))
self.status("Error reading %s" % unicodeFilePath) self.status("Error reading %s" % unicodeFilePath)
return False return False
self.imageData = self.labelFile.imageData self.imageData = self.labelFile.imageData
...@@ -1329,8 +1489,10 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1329,8 +1489,10 @@ class MainWindow(QMainWindow, WindowMixin):
image = QImage.fromData(self.imageData) image = QImage.fromData(self.imageData)
if image.isNull(): if image.isNull():
self.errorMessage(u'Error opening file', self.errorMessage(
u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath) u'Error opening file',
u"<p>Make sure <i>%s</i> is a valid image file." %
unicodeFilePath)
self.status("Error reading %s" % unicodeFilePath) self.status("Error reading %s" % unicodeFilePath)
return False return False
self.status("Loaded %s" % os.path.basename(unicodeFilePath)) self.status("Loaded %s" % os.path.basename(unicodeFilePath))
...@@ -1351,32 +1513,33 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1351,32 +1513,33 @@ class MainWindow(QMainWindow, WindowMixin):
self.addRecentFile(self.filePath) self.addRecentFile(self.filePath)
self.toggleActions(True) self.toggleActions(True)
self.showBoundingBoxFromPPlabel(filePath) self.showBoundingBoxFromPPlabel(filePath)
self.setWindowTitle(__appname__ + ' ' + filePath) self.setWindowTitle(__appname__ + ' ' + filePath)
# Default : select last item if there is at least one item # Default : select last item if there is at least one item
if self.labelList.count(): if self.labelList.count():
self.labelList.setCurrentItem(self.labelList.item(self.labelList.count() - 1)) self.labelList.setCurrentItem(
self.labelList.item(self.labelList.count() - 1).setSelected(True) self.labelList.item(self.labelList.count() - 1))
self.labelList.item(self.labelList.count() - 1).setSelected(
True)
self.canvas.setFocus(True) self.canvas.setFocus(True)
return True return True
return False return False
def showBoundingBoxFromPPlabel(self, filePath): def showBoundingBoxFromPPlabel(self, filePath):
imgidx = self.getImglabelidx(filePath) imgidx = self.getImglabelidx(filePath)
if imgidx not in self.PPlabel.keys(): if imgidx not in self.PPlabel.keys():
return return
shapes = [] shapes = []
for box in self.PPlabel[imgidx]: for box in self.PPlabel[imgidx]:
shapes.append((box['transcription'], box['points'], None, None, box['difficult'])) shapes.append((box['transcription'], box['points'], None, None,
box['difficult']))
print(shapes) print(shapes)
self.loadLabels(shapes) self.loadLabels(shapes)
self.canvas.verified = False self.canvas.verified = False
def validFilestate(self, filePath): def validFilestate(self, filePath):
if filePath not in self.fileStatedict.keys(): if filePath not in self.fileStatedict.keys():
return None return None
...@@ -1405,7 +1568,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1405,7 +1568,7 @@ class MainWindow(QMainWindow, WindowMixin):
"""Figure out the size of the pixmap in order to fit the main widget.""" """Figure out the size of the pixmap in order to fit the main widget."""
e = 2.0 # So that no scrollbars are generated. e = 2.0 # So that no scrollbars are generated.
w1 = self.centralWidget().width() - e w1 = self.centralWidget().width() - e
h1 = self.centralWidget().height() - e -110 h1 = self.centralWidget().height() - e - 110
a1 = w1 / h1 a1 = w1 / h1
# Calculate a new scale value based on the pixmap's aspect ratio. # Calculate a new scale value based on the pixmap's aspect ratio.
w2 = self.canvas.pixmap.width() - 0.0 w2 = self.canvas.pixmap.width() - 0.0
...@@ -1425,7 +1588,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1425,7 +1588,8 @@ class MainWindow(QMainWindow, WindowMixin):
settings = self.settings settings = self.settings
# If it loads images from dir, don't load it at the begining # If it loads images from dir, don't load it at the begining
if self.dirname is None: if self.dirname is None:
settings[SETTING_FILENAME] = self.filePath if self.filePath else '' settings[
SETTING_FILENAME] = self.filePath if self.filePath else ''
else: else:
settings[SETTING_FILENAME] = '' settings[SETTING_FILENAME] = ''
...@@ -1461,7 +1625,10 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1461,7 +1625,10 @@ class MainWindow(QMainWindow, WindowMixin):
self.loadFile(filename) self.loadFile(filename)
def scanAllImages(self, folderPath): def scanAllImages(self, folderPath):
extensions = ['.%s' % fmt.data().decode("ascii").lower() for fmt in QImageReader.supportedImageFormats()] extensions = [
'.%s' % fmt.data().decode("ascii").lower()
for fmt in QImageReader.supportedImageFormats()
]
images = [] images = []
for file in os.listdir(folderPath): for file in os.listdir(folderPath):
...@@ -1472,8 +1639,6 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1472,8 +1639,6 @@ class MainWindow(QMainWindow, WindowMixin):
natural_sort(images, key=lambda x: x.lower()) natural_sort(images, key=lambda x: x.lower())
return images return images
def openDirDialog(self, _value=False, dirpath=None, silent=False): def openDirDialog(self, _value=False, dirpath=None, silent=False):
if not self.mayContinue(): if not self.mayContinue():
return return
...@@ -1482,18 +1647,20 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1482,18 +1647,20 @@ class MainWindow(QMainWindow, WindowMixin):
if self.lastOpenDir and os.path.exists(self.lastOpenDir): if self.lastOpenDir and os.path.exists(self.lastOpenDir):
defaultOpenDirPath = self.lastOpenDir defaultOpenDirPath = self.lastOpenDir
else: else:
defaultOpenDirPath = os.path.dirname(self.filePath) if self.filePath else '.' defaultOpenDirPath = os.path.dirname(
self.filePath) if self.filePath else '.'
if silent != True: if silent != True:
targetDirPath = ustr(QFileDialog.getExistingDirectory(self, targetDirPath = ustr(
'%s - Open Directory' % __appname__, QFileDialog.getExistingDirectory(
defaultOpenDirPath, self, '%s - Open Directory' % __appname__,
QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)) defaultOpenDirPath, QFileDialog.ShowDirsOnly |
QFileDialog.DontResolveSymlinks))
else: else:
targetDirPath = ustr(defaultOpenDirPath) targetDirPath = ustr(defaultOpenDirPath)
self.lastOpenDir = targetDirPath self.lastOpenDir = targetDirPath
self.importDirImages(targetDirPath) self.importDirImages(targetDirPath)
def importDirImages(self, dirpath, isDelete = False): def importDirImages(self, dirpath, isDelete=False):
if not self.mayContinue() or not dirpath: if not self.mayContinue() or not dirpath:
return return
if self.defaultSaveDir and self.defaultSaveDir != dirpath: if self.defaultSaveDir and self.defaultSaveDir != dirpath:
...@@ -1502,7 +1669,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1502,7 +1669,7 @@ class MainWindow(QMainWindow, WindowMixin):
if not isDelete: if not isDelete:
self.loadFilestate(dirpath) self.loadFilestate(dirpath)
self.PPlabelpath = dirpath+ '/Label.txt' self.PPlabelpath = dirpath + '/Label.txt'
self.PPlabel = self.loadLabelFile(self.PPlabelpath) self.PPlabel = self.loadLabelFile(self.PPlabelpath)
self.Cachelabelpath = dirpath + '/Cache.cach' self.Cachelabelpath = dirpath + '/Cache.cach'
self.Cachelabel = self.loadLabelFile(self.Cachelabelpath) self.Cachelabel = self.loadLabelFile(self.Cachelabelpath)
...@@ -1511,10 +1678,10 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1511,10 +1678,10 @@ class MainWindow(QMainWindow, WindowMixin):
self.lastOpenDir = dirpath self.lastOpenDir = dirpath
self.dirname = dirpath self.dirname = dirpath
self.defaultSaveDir = dirpath self.defaultSaveDir = dirpath
self.statusBar().showMessage('%s started. Annotation will be saved to %s' % self.statusBar().showMessage(
(__appname__, self.defaultSaveDir)) '%s started. Annotation will be saved to %s' %
(__appname__, self.defaultSaveDir))
self.statusBar().show() self.statusBar().show()
self.filePath = None self.filePath = None
...@@ -1564,7 +1731,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1564,7 +1731,7 @@ class MainWindow(QMainWindow, WindowMixin):
if self.filePath is None: if self.filePath is None:
return return
currIndex = self.mImgList.index(self.filePath) currIndex = self.mImgList.index(self.filePath)
self.mImgList5 = self.mImgList[:5] self.mImgList5 = self.mImgList[:5]
if currIndex - 1 >= 0: if currIndex - 1 >= 0:
...@@ -1592,16 +1759,22 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1592,16 +1759,22 @@ class MainWindow(QMainWindow, WindowMixin):
else: else:
self.mImgList5 = self.indexTo5Files(currIndex) self.mImgList5 = self.indexTo5Files(currIndex)
if filename: if filename:
print('file name in openNext is ',filename) print('file name in openNext is ', filename)
self.loadFile(filename) self.loadFile(filename)
def openFile(self, _value=False): def openFile(self, _value=False):
if not self.mayContinue(): if not self.mayContinue():
return return
path = os.path.dirname(ustr(self.filePath)) if self.filePath else '.' path = os.path.dirname(ustr(self.filePath)) if self.filePath else '.'
formats = ['*.%s' % fmt.data().decode("ascii").lower() for fmt in QImageReader.supportedImageFormats()] formats = [
filters = "Image & Label files (%s)" % ' '.join(formats + ['*%s' % LabelFile.suffix]) '*.%s' % fmt.data().decode("ascii").lower()
filename = QFileDialog.getOpenFileName(self, '%s - Choose Image or Label file' % __appname__, path, filters) for fmt in QImageReader.supportedImageFormats()
]
filters = "Image & Label files (%s)" % ' '.join(
formats + ['*%s' % LabelFile.suffix])
filename = QFileDialog.getOpenFileName(
self, '%s - Choose Image or Label file' % __appname__, path,
filters)
if filename: if filename:
if isinstance(filename, (tuple, list)): if isinstance(filename, (tuple, list)):
filename = filename[0] filename = filename[0]
...@@ -1623,7 +1796,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1623,7 +1796,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.fileListWidget.addItem(filename) self.fileListWidget.addItem(filename)
self.additems5(None) self.additems5(None)
print('opened image is', filename) print('opened image is', filename)
def updateFileListIcon(self, filename): def updateFileListIcon(self, filename):
pass pass
...@@ -1638,8 +1811,10 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1638,8 +1811,10 @@ class MainWindow(QMainWindow, WindowMixin):
imgFileName = os.path.basename(self.filePath) imgFileName = os.path.basename(self.filePath)
savedFileName = os.path.splitext(imgFileName)[0] savedFileName = os.path.splitext(imgFileName)[0]
savedPath = os.path.join(imgFileDir, savedFileName) savedPath = os.path.join(imgFileDir, savedFileName)
self._saveFile(savedPath if self.labelFile self._saveFile(
else self.saveFileDialog(removeExt=False), mode=mode) savedPath
if self.labelFile else self.saveFileDialog(removeExt=False),
mode=mode)
def saveFileAs(self, _value=False): def saveFileAs(self, _value=False):
assert not self.image.isNull(), "cannot save empty image" assert not self.image.isNull(), "cannot save empty image"
...@@ -1658,23 +1833,26 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1658,23 +1833,26 @@ class MainWindow(QMainWindow, WindowMixin):
if dlg.exec_(): if dlg.exec_():
fullFilePath = ustr(dlg.selectedFiles()[0]) fullFilePath = ustr(dlg.selectedFiles()[0])
if removeExt: if removeExt:
return os.path.splitext(fullFilePath)[0] # Return file path without the extension. return os.path.splitext(fullFilePath)[
0] # Return file path without the extension.
else: else:
return fullFilePath return fullFilePath
return '' return ''
def _saveFile(self, annotationFilePath, mode='Manual'): def _saveFile(self, annotationFilePath, mode='Manual'):
if mode == 'Manual': if mode == 'Manual':
if annotationFilePath and self.saveLabels(annotationFilePath, mode=mode): if annotationFilePath and self.saveLabels(
annotationFilePath, mode=mode):
self.setClean() self.setClean()
self.statusBar().showMessage('Saved to %s' % annotationFilePath) self.statusBar().showMessage('Saved to %s' %
annotationFilePath)
self.statusBar().show() self.statusBar().show()
currIndex = self.mImgList.index(self.filePath) currIndex = self.mImgList.index(self.filePath)
item = self.fileListWidget.item(currIndex) item = self.fileListWidget.item(currIndex)
item.setIcon(newIcon('done')) item.setIcon(newIcon('done'))
self.fileStatedict[self.filePath] = 1 self.fileStatedict[self.filePath] = 1
if len(self.fileStatedict)%self.autoSaveNum ==0: if len(self.fileStatedict) % self.autoSaveNum == 0:
self.saveFilestate() self.saveFilestate()
self.savePPlabel(mode='Auto') self.savePPlabel(mode='Auto')
...@@ -1683,10 +1861,12 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1683,10 +1861,12 @@ class MainWindow(QMainWindow, WindowMixin):
self.actions.saveRec.setEnabled(True) self.actions.saveRec.setEnabled(True)
elif mode == 'Auto': elif mode == 'Auto':
if annotationFilePath and self.saveLabels(annotationFilePath, mode=mode): if annotationFilePath and self.saveLabels(
annotationFilePath, mode=mode):
self.setClean() self.setClean()
self.statusBar().showMessage('Saved to %s' % annotationFilePath) self.statusBar().showMessage('Saved to %s' %
annotationFilePath)
self.statusBar().show() self.statusBar().show()
def closeFile(self, _value=False): def closeFile(self, _value=False):
...@@ -1705,9 +1885,10 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1705,9 +1885,10 @@ class MainWindow(QMainWindow, WindowMixin):
if deleteInfo == QMessageBox.Yes: if deleteInfo == QMessageBox.Yes:
if platform.system() == 'Windows': if platform.system() == 'Windows':
from win32com.shell import shell, shellcon from win32com.shell import shell, shellcon
shell.SHFileOperation((0, shellcon.FO_DELETE, deletePath, None, shell.SHFileOperation(
shellcon.FOF_SILENT | shellcon.FOF_ALLOWUNDO | shellcon.FOF_NOCONFIRMATION, (0, shellcon.FO_DELETE, deletePath, None,
None, None)) shellcon.FOF_SILENT | shellcon.FOF_ALLOWUNDO |
shellcon.FOF_NOCONFIRMATION, None, None))
# linux # linux
elif platform.system() == 'Linux': elif platform.system() == 'Linux':
cmd = 'trash ' + deletePath cmd = 'trash ' + deletePath
...@@ -1715,9 +1896,13 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1715,9 +1896,13 @@ class MainWindow(QMainWindow, WindowMixin):
# macOS # macOS
elif platform.system() == 'Darwin': elif platform.system() == 'Darwin':
import subprocess import subprocess
absPath = os.path.abspath(deletePath).replace('\\', '\\\\').replace('"', '\\"') absPath = os.path.abspath(deletePath).replace(
cmd = ['osascript', '-e', '\\', '\\\\').replace('"', '\\"')
'tell app "Finder" to move {the POSIX file "' + absPath + '"} to trash'] cmd = [
'osascript', '-e',
'tell app "Finder" to move {the POSIX file "' + absPath
+ '"} to trash'
]
print(cmd) print(cmd)
subprocess.call(cmd, stdout=open(os.devnull, 'w')) subprocess.call(cmd, stdout=open(os.devnull, 'w'))
...@@ -1741,7 +1926,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1741,7 +1926,7 @@ class MainWindow(QMainWindow, WindowMixin):
proc.startDetached(os.path.abspath(__file__)) proc.startDetached(os.path.abspath(__file__))
def mayContinue(self): # def mayContinue(self): #
if not self.dirty: if not self.dirty:
return True return True
else: else:
discardChanges = self.discardChangesDialog() discardChanges = self.discardChangesDialog()
...@@ -1766,8 +1951,8 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1766,8 +1951,8 @@ class MainWindow(QMainWindow, WindowMixin):
return os.path.dirname(self.filePath) if self.filePath else '.' return os.path.dirname(self.filePath) if self.filePath else '.'
def chooseColor1(self): def chooseColor1(self):
color = self.colorDialog.getColor(self.lineColor, u'Choose line color', color = self.colorDialog.getColor(
default=DEFAULT_LINE_COLOR) self.lineColor, u'Choose line color', default=DEFAULT_LINE_COLOR)
if color: if color:
self.lineColor = color self.lineColor = color
Shape.line_color = color Shape.line_color = color
...@@ -1783,16 +1968,16 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1783,16 +1968,16 @@ class MainWindow(QMainWindow, WindowMixin):
action.setEnabled(False) action.setEnabled(False)
def chshapeLineColor(self): def chshapeLineColor(self):
color = self.colorDialog.getColor(self.lineColor, u'Choose line color', color = self.colorDialog.getColor(
default=DEFAULT_LINE_COLOR) self.lineColor, u'Choose line color', default=DEFAULT_LINE_COLOR)
if color: if color:
self.canvas.selectedShape.line_color = color self.canvas.selectedShape.line_color = color
self.canvas.update() self.canvas.update()
self.setDirty() self.setDirty()
def chshapeFillColor(self): def chshapeFillColor(self):
color = self.colorDialog.getColor(self.fillColor, u'Choose fill color', color = self.colorDialog.getColor(
default=DEFAULT_FILL_COLOR) self.fillColor, u'Choose fill color', default=DEFAULT_FILL_COLOR)
if color: if color:
self.canvas.selectedShape.fill_color = color self.canvas.selectedShape.fill_color = color
self.canvas.update() self.canvas.update()
...@@ -1817,7 +2002,6 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1817,7 +2002,6 @@ class MainWindow(QMainWindow, WindowMixin):
else: else:
self.labelHist.append(line) self.labelHist.append(line)
def togglePaintLabelsOption(self): def togglePaintLabelsOption(self):
for shape in self.canvas.shapes: for shape in self.canvas.shapes:
shape.paintLabel = self.displayLabelOption.isChecked() shape.paintLabel = self.displayLabelOption.isChecked()
...@@ -1830,8 +2014,10 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1830,8 +2014,10 @@ class MainWindow(QMainWindow, WindowMixin):
pix = QPixmap(file) pix = QPixmap(file)
_, filename = os.path.split(file) _, filename = os.path.split(file)
filename, _ = os.path.splitext(filename) filename, _ = os.path.splitext(filename)
item = QListWidgetItem(QIcon(pix.scaled(100, 100, Qt.IgnoreAspectRatio, Qt.FastTransformation)), item = QListWidgetItem(
filename[:10]) QIcon(
pix.scaled(100, 100, Qt.IgnoreAspectRatio,
Qt.FastTransformation)), filename[:10])
item.setToolTip(file) item.setToolTip(file)
self.iconlist.addItem(item) self.iconlist.addItem(item)
...@@ -1846,7 +2032,10 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1846,7 +2032,10 @@ class MainWindow(QMainWindow, WindowMixin):
prelen = lentoken // 2 prelen = lentoken // 2
bfilename = prelen * " " + pfilename + (lentoken - prelen) * " " bfilename = prelen * " " + pfilename + (lentoken - prelen) * " "
# item = QListWidgetItem(QIcon(pix.scaled(100, 100, Qt.KeepAspectRatio, Qt.SmoothTransformation)),filename[:10]) # item = QListWidgetItem(QIcon(pix.scaled(100, 100, Qt.KeepAspectRatio, Qt.SmoothTransformation)),filename[:10])
item = QListWidgetItem(QIcon(pix.scaled(100, 100, Qt.IgnoreAspectRatio, Qt.FastTransformation)),pfilename) item = QListWidgetItem(
QIcon(
pix.scaled(100, 100, Qt.IgnoreAspectRatio,
Qt.FastTransformation)), pfilename)
# item.setForeground(QBrush(Qt.white)) # item.setForeground(QBrush(Qt.white))
item.setToolTip(file) item.setToolTip(file)
self.iconlist.addItem(item) self.iconlist.addItem(item)
...@@ -1858,7 +2047,7 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1858,7 +2047,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.iconlist.setMinimumWidth(owidth + 50) self.iconlist.setMinimumWidth(owidth + 50)
def getImglabelidx(self, filePath): def getImglabelidx(self, filePath):
if platform.system()=='Windows': if platform.system() == 'Windows':
spliter = '\\' spliter = '\\'
else: else:
spliter = '/' spliter = '/'
...@@ -1869,17 +2058,22 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1869,17 +2058,22 @@ class MainWindow(QMainWindow, WindowMixin):
assert self.mImgList is not None assert self.mImgList is not None
print('Using model from ', self.model) print('Using model from ', self.model)
uncheckedList = [i for i in self.mImgList if i not in self.fileStatedict.keys()] uncheckedList = [
self.autoDialog = AutoDialog(parent=self, ocr=self.ocr, mImgList=uncheckedList, lenbar=len(uncheckedList)) i for i in self.mImgList if i not in self.fileStatedict.keys()
]
self.autoDialog = AutoDialog(
parent=self,
ocr=self.ocr,
mImgList=uncheckedList,
lenbar=len(uncheckedList))
self.autoDialog.popUp() self.autoDialog.popUp()
self.currIndex=len(self.mImgList) self.currIndex = len(self.mImgList)
self.loadFile(self.filePath) # ADD self.loadFile(self.filePath) # ADD
self.haveAutoReced = True self.haveAutoReced = True
self.AutoRecognition.setEnabled(False) self.AutoRecognition.setEnabled(False)
self.setDirty() self.setDirty()
self.saveCacheLabel() self.saveCacheLabel()
def reRecognition(self): def reRecognition(self):
img = cv2.imread(self.filePath) img = cv2.imread(self.filePath)
# org_box = [dic['points'] for dic in self.PPlabel[self.getImglabelidx(self.filePath)]] # org_box = [dic['points'] for dic in self.PPlabel[self.getImglabelidx(self.filePath)]]
...@@ -1908,16 +2102,74 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1908,16 +2102,74 @@ class MainWindow(QMainWindow, WindowMixin):
self.saveFile(mode='Auto') self.saveFile(mode='Auto')
self.loadFile(self.filePath) self.loadFile(self.filePath)
self.setDirty() self.setDirty()
elif len(self.result_dic) == len(self.canvas.shapes) and rec_flag == 0: elif len(self.result_dic) == len(
QMessageBox.information(self, "Information", "The recognition result remains unchanged!") self.canvas.shapes) and rec_flag == 0:
QMessageBox.information(
self, "Information",
"The recognition result remains unchanged!")
else: else:
print('Can not recgonise in ', self.filePath) print('Can not recgonise in ', self.filePath)
else: else:
QMessageBox.information(self, "Information", "Draw a box!") QMessageBox.information(self, "Information", "Draw a box!")
def autolcm(self): def autolcm(self):
print('autolabelchoosemodel') vbox = QVBoxLayout()
hbox = QHBoxLayout()
self.panel = QLabel()
self.panel.setText(self.stringBundle.getString('choseModelLg'))
self.panel.setAlignment(Qt.AlignLeft)
self.comboBox = QComboBox()
self.comboBox.setObjectName("comboBox")
self.comboBox.addItems([
'Chinese & English', 'English', 'French', 'German', 'Korean',
'Japanese'
])
# self.comboBox_lg = QComboBox()
# self.comboBox_lg.setObjectName("comboBox_language")
vbox.addWidget(self.panel)
vbox.addWidget(self.comboBox)
self.dialog = QDialog()
self.dialog.resize(300, 100)
self.okBtn = QPushButton(self.stringBundle.getString('ok'))
self.cancelBtn = QPushButton(self.stringBundle.getString('cancel'))
self.okBtn.clicked.connect(self.modelChoose)
self.cancelBtn.clicked.connect(self.cancel)
self.dialog.setWindowTitle(self.stringBundle.getString('choseModelLg'))
hbox.addWidget(self.okBtn)
hbox.addWidget(self.cancelBtn)
vbox.addWidget(self.panel)
vbox.addLayout(hbox)
self.dialog.setLayout(vbox)
self.dialog.setWindowModality(Qt.ApplicationModal)
self.dialog.exec_()
if self.filePath:
self.AutoRecognition.setEnabled(True)
def modelChoose(self):
print(self.comboBox.currentText())
lg_idx = {
'Chinese & English': 'ch',
'English': 'en',
'French': 'french',
'German': 'german',
'Korean': 'korean',
'Japanese': 'japan'
}
del self.ocr
self.ocr = PaddleOCR(
use_pdserving=False,
use_angle_cls=True,
det=True,
cls=True,
use_gpu=False,
lang=lg_idx[self.comboBox.currentText()])
self.dialog.close()
def cancel(self):
self.dialog.close()
def loadFilestate(self, saveDir): def loadFilestate(self, saveDir):
self.fileStatepath = saveDir + '/fileState.txt' self.fileStatepath = saveDir + '/fileState.txt'
...@@ -1931,14 +2183,12 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1931,14 +2183,12 @@ class MainWindow(QMainWindow, WindowMixin):
file, state = each.split('\t') file, state = each.split('\t')
self.fileStatedict[file] = 1 self.fileStatedict[file] = 1
def saveFilestate(self): def saveFilestate(self):
with open(self.fileStatepath, 'w', encoding='utf-8') as f: with open(self.fileStatepath, 'w', encoding='utf-8') as f:
for key in self.fileStatedict: for key in self.fileStatedict:
f.write(key + '\t') f.write(key + '\t')
f.write(str(self.fileStatedict[key]) + '\n') f.write(str(self.fileStatedict[key]) + '\n')
def loadLabelFile(self, labelpath): def loadLabelFile(self, labelpath):
labeldict = {} labeldict = {}
if not os.path.exists(labelpath): if not os.path.exists(labelpath):
...@@ -1956,24 +2206,27 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1956,24 +2206,27 @@ class MainWindow(QMainWindow, WindowMixin):
labeldict[file] = [] labeldict[file] = []
return labeldict return labeldict
def savePPlabel(self, mode='Manual'):
def savePPlabel(self,mode='Manual'):
savedfile = [self.getImglabelidx(i) for i in self.fileStatedict.keys()] savedfile = [self.getImglabelidx(i) for i in self.fileStatedict.keys()]
with open(self.PPlabelpath, 'w', encoding='utf-8') as f: with open(self.PPlabelpath, 'w', encoding='utf-8') as f:
for key in self.PPlabel: for key in self.PPlabel:
if key in savedfile: if key in savedfile:
f.write(key + '\t') f.write(key + '\t')
f.write(json.dumps(self.PPlabel[key], ensure_ascii=False) + '\n') f.write(
json.dumps(
self.PPlabel[key], ensure_ascii=False) + '\n')
if mode=='Manual': if mode == 'Manual':
msg = 'Images that have been checked are saved in '+ self.PPlabelpath msg = 'Images that have been checked are saved in ' + self.PPlabelpath
QMessageBox.information(self, "Information", msg) QMessageBox.information(self, "Information", msg)
def saveCacheLabel(self): def saveCacheLabel(self):
with open(self.Cachelabelpath, 'w', encoding='utf-8') as f: with open(self.Cachelabelpath, 'w', encoding='utf-8') as f:
for key in self.Cachelabel: for key in self.Cachelabel:
f.write(key + '\t') f.write(key + '\t')
f.write(json.dumps(self.Cachelabel[key], ensure_ascii=False) + '\n') f.write(
json.dumps(
self.Cachelabel[key], ensure_ascii=False) + '\n')
def saveRecResult(self): def saveRecResult(self):
if None in [self.PPlabelpath, self.PPlabel, self.fileStatedict]: if None in [self.PPlabelpath, self.PPlabel, self.fileStatedict]:
...@@ -1990,16 +2243,21 @@ class MainWindow(QMainWindow, WindowMixin): ...@@ -1990,16 +2243,21 @@ class MainWindow(QMainWindow, WindowMixin):
idx = self.getImglabelidx(key) idx = self.getImglabelidx(key)
for i, label in enumerate(self.PPlabel[idx]): for i, label in enumerate(self.PPlabel[idx]):
img = cv2.imread(key) img = cv2.imread(key)
img_crop = get_rotate_crop_image(img, np.array(label['points'], np.float32)) img_crop = get_rotate_crop_image(
img_name = os.path.splitext(os.path.basename(idx))[0] + '_crop_'+str(i)+'.jpg' img, np.array(label['points'], np.float32))
cv2.imwrite(crop_img_dir+img_name, img_crop) img_name = os.path.splitext(os.path.basename(idx))[
f.write('crop_img/'+ img_name + '\t') 0] + '_crop_' + str(i) + '.jpg'
cv2.imwrite(crop_img_dir + img_name, img_crop)
f.write('crop_img/' + img_name + '\t')
f.write(label['transcription'] + '\n') f.write(label['transcription'] + '\n')
QMessageBox.information(self, "Information", "Cropped images has been saved in "+str(crop_img_dir)) QMessageBox.information(
self, "Information",
"Cropped images has been saved in " + str(crop_img_dir))
def inverted(color): def inverted(color):
return QColor(*[255 - v for v in color.getRgb()]) return QColor(* [255 - v for v in color.getRgb()])
def read(filename, default=None): def read(filename, default=None):
...@@ -2020,18 +2278,17 @@ def get_main_app(argv=[]): ...@@ -2020,18 +2278,17 @@ def get_main_app(argv=[]):
app.setWindowIcon(newIcon("app")) app.setWindowIcon(newIcon("app"))
# Tzutalin 201705+: Accept extra agruments to change predefined class file # Tzutalin 201705+: Accept extra agruments to change predefined class file
argparser = argparse.ArgumentParser() argparser = argparse.ArgumentParser()
argparser.add_argument("image_dir", nargs="?") argparser.add_argument("--lang", default='ch', nargs="?")
argparser.add_argument("language", default='zh-CN',nargs="?") argparser.add_argument(
argparser.add_argument("predefined_classes_file", "--predefined_classes_file",
default=os.path.join(os.path.dirname(__file__), "data", "predefined_classes.txt"), default=os.path.join(
nargs="?") os.path.dirname(__file__), "data", "predefined_classes.txt"),
argparser.add_argument("save_dir", nargs="?") nargs="?")
args = argparser.parse_args(argv[1:]) args = argparser.parse_args(argv[1:])
# Usage : labelImg.py image predefClassFile saveDir # Usage : labelImg.py image predefClassFile saveDir
win = MainWindow(args.image_dir, win = MainWindow(
args.predefined_classes_file, lang=args.lang,
args.save_dir, defaultPrefdefClassFile=args.predefined_classes_file, )
args.language)
win.show() win.show()
return app, win return app, win
...@@ -2043,7 +2300,7 @@ def main(): ...@@ -2043,7 +2300,7 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
resource_file = './libs/resources.py' resource_file = './libs/resources.py'
if not os.path.exists(resource_file): if not os.path.exists(resource_file):
output = os.system('pyrcc5 -o libs/resources.py resources.qrc') output = os.system('pyrcc5 -o libs/resources.py resources.qrc')
......
# PPOCRLabel
PPOCRLabel is a semi-automatic graphic annotation tool suitable for OCR field. It is written in python3 and pyqt5. Support rectangular frame labeling and four-point labeling mode. Annotations can be directly used for the training of PPOCR detection and recognition models.
<img src="./data/gif/steps.gif" width="100%"/>
## Installation
### 1. Install PaddleOCR
Refer to [PaddleOCR installation document](https://github.com/PaddlePaddle/PaddleOCR/blob/develop/doc/doc_ch/installation.md) to prepare PaddleOCR
### 2. Install PPOCRLabel
#### Windows + Anaconda
Download and install [Anaconda](https://www.anaconda.com/download/#download) (Python 3+)
```
conda install pyqt=5
cd ./PPOCRLabel # Change the directory to the PPOCRLabel folder
pyrcc5 -o libs/resources.py resources.qrc
python PPOCRLabel.py
```
#### Ubuntu Linux
```
sudo apt-get install pyqt5-dev-tools
sudo apt-get install trash-cli
cd ./PPOCRLabel # Change the directory to the PPOCRLabel folder
sudo pip3 install -r requirements/requirements-linux-python3.txt
make qt5py3
python3 PPOCRLabel.py
```
#### macOS
```
pip3 install pyqt5
pip3 uninstall opencv-python # Uninstall opencv manually as it conflicts with pyqt
pip3 install opencv-contrib-python-headless # Install the headless version of opencv
cd ./PPOCRLabel # Change the directory to the PPOCRLabel folder
make qt5py3
python3 PPOCRLabel.py
```
## Usage
### Steps
1. Build and launch using the instructions above.
2. Click 'Open Dir' in Menu/File to select the folder of the picture.<sup>[1]</sup>
3. Click 'Auto recognition', use PPOCR model to automatically annotate images which marked with 'X' <sup>[2]</sup>before the file name.
4. Create Box:
4.1 Click 'Create RectBox' or press 'W' in English keyboard mode to draw a new rectangle detection box. Click and release left mouse to select a region to annotate the text area.
4.2 Press 'P' to enter four-point labeling mode which enables you to create any four-point shape by clicking four points with the left mouse button in succession and DOUBLE CLICK the left mouse as the signal of labeling completion.
5. After the marking frame is drawn, the user clicks "OK", and the detection frame will be pre-assigned a "TEMPORARY" label.
6. Click 're-Recognition', model will rewrite ALL recognition results in ALL detection box<sup>[3]</sup>.
7. Double click the result in 'recognition result' list to manually change inaccurate recognition results.
8. Click "Save", the image status will switch to "√",then the program automatically jump to the next.
9. Click "Delete Image" and the image will be deleted to the recycle bin.
10. Labeling result: After closing the application or switching the file path, the manually saved label will be stored in *Label.txt* under the opened picture folder.
Click "PaddleOCR"-"Save Recognition Results" in the menu bar, the recognition training data of such pictures will be saved in the *crop_img* folder, and the recognition label will be saved in *rec_gt.txt*<sup>[4]</sup>.
### Note
[1] PPOCRLabel uses the opened folder as the project. After opening the image folder, the picture will not be displayed in the dialog. Instead, the pictures under the folder will be directly imported into the program after clicking "Open Dir".
[2] The image status indicates whether the user has saved the image manually. If it has not been saved manually it is "X", otherwise it is "√", PPOCRLabel will not relabel pictures with a status of "√".
[3] After clicking "Re-recognize", the model will overwrite ALL recognition results in the picture.
Therefore, if the recognition result has been manually changed before, it may change after re-recognition.
[4] The files produced by PPOCRLabel include the following, please do not manually change the contents, otherwise it will cause the program to be abnormal.
| File name | Description |
| :-----------: | :----------------------------------------------------------: |
| Label.txt | The detection label file can be directly used for PPOCR detection model training. After the user saves 10 label results, the file will be automatically saved. It will also be written when the user closes the application or changes the file folder. |
| fileState.txt | The picture status file save the image in the current folder that has been manually confirmed by the user. |
| Cache.cach | Cache files to save the results of model recognition. |
| rec_gt.txt | The recognition label file, which can be directly used for PPOCR identification model training, is generated after the user clicks on the menu bar "PaddleOCR"-"Save recognition result". |
| crop_img | The recognition data, generated at the same time with *rec_gt.txt* |
## Related
1.[Tzutalin. LabelImg. Git code (2015)](https://github.com/tzutalin/labelImg)
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -29,7 +29,7 @@ except ImportError: ...@@ -29,7 +29,7 @@ except ImportError:
def newIcon(icon, iconSize=None): def newIcon(icon, iconSize=None):
if iconSize is not None: if iconSize is not None:
return QIcon(QIcon(':/' + icon).pixmap(iconSize,iconSize)) return QIcon(QIcon(':/' + icon).pixmap(iconSize, iconSize))
else: else:
return QIcon(':/' + icon) return QIcon(':/' + icon)
...@@ -43,8 +43,15 @@ def newButton(text, icon=None, slot=None): ...@@ -43,8 +43,15 @@ def newButton(text, icon=None, slot=None):
return b return b
def newAction(parent, text, slot=None, shortcut=None, icon=None, def newAction(parent,
tip=None, checkable=False, enabled=True, iconSize=None): text,
slot=None,
shortcut=None,
icon=None,
tip=None,
checkable=False,
enabled=True,
iconSize=None):
"""Create a new action and assign callbacks, shortcuts, etc.""" """Create a new action and assign callbacks, shortcuts, etc."""
a = QAction(text, parent) a = QAction(text, parent)
if icon is not None: if icon is not None:
...@@ -83,7 +90,6 @@ def labelValidator(): ...@@ -83,7 +90,6 @@ def labelValidator():
class struct(object): class struct(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.__dict__.update(kwargs) self.__dict__.update(kwargs)
...@@ -101,24 +107,29 @@ def generateColorByText(text): ...@@ -101,24 +107,29 @@ def generateColorByText(text):
s = ustr(text) s = ustr(text)
hashCode = int(hashlib.sha256(s.encode('utf-8')).hexdigest(), 16) hashCode = int(hashlib.sha256(s.encode('utf-8')).hexdigest(), 16)
r = int((hashCode / 255) % 255) r = int((hashCode / 255) % 255)
g = int((hashCode / 65025) % 255) g = int((hashCode / 65025) % 255)
b = int((hashCode / 16581375) % 255) b = int((hashCode / 16581375) % 255)
return QColor(r, g, b, 100) return QColor(r, g, b, 100)
def have_qstring(): def have_qstring():
'''p3/qt5 get rid of QString wrapper as py3 has native unicode str type''' '''p3/qt5 get rid of QString wrapper as py3 has native unicode str type'''
return not (sys.version_info.major >= 3 or QT_VERSION_STR.startswith('5.')) return not (sys.version_info.major >= 3 or QT_VERSION_STR.startswith('5.'))
def util_qt_strlistclass(): def util_qt_strlistclass():
return QStringList if have_qstring() else list return QStringList if have_qstring() else list
def natural_sort(list, key=lambda s:s):
def natural_sort(list, key=lambda s: s):
""" """
Sort the list into natural alphanumeric order. Sort the list into natural alphanumeric order.
""" """
def get_alphanum_key_func(key): def get_alphanum_key_func(key):
convert = lambda text: int(text) if text.isdigit() else text convert = lambda text: int(text) if text.isdigit() else text
return lambda s: [convert(c) for c in re.split('([0-9]+)', key(s))] return lambda s: [convert(c) for c in re.split('([0-9]+)', key(s))]
sort_key = get_alphanum_key_func(key) sort_key = get_alphanum_key_func(key)
list.sort(key=sort_key) list.sort(key=sort_key)
...@@ -150,18 +161,34 @@ def get_rotate_crop_image(img, points): ...@@ -150,18 +161,34 @@ def get_rotate_crop_image(img, points):
except Exception as e: except Exception as e:
print(e) print(e)
def steps():
msg = "1. 安装与运行:使用上述命令安装与运行程序。\n" \ def stepsInfo(lang='en'):
"2. 打开文件夹:在菜单栏点击 “文件” - 打开目录 选择待标记图片的文件夹.\n"\ if lang == 'ch':
"3. 自动标注:点击 ”自动标注“,使用PPOCR超轻量模型对图片文件名前图片状态为 “X” 的图片进行自动标注。\n" \ msg = "1. 安装与运行:使用上述命令安装与运行程序。\n" \
"4. 手动标注:点击 “矩形标注”(推荐直接在英文模式下点击键盘中的 “W”),用户可对当前图片中模型未检出的部分进行手动" \ "2. 打开文件夹:在菜单栏点击 “文件” - 打开目录 选择待标记图片的文件夹.\n"\
"绘制标记框。点击键盘P,则使用四点标注模式(或点击“编辑” - “四点标注”),用户依次点击4个点后,双击左键表示标注完成。\n" \ "3. 自动标注:点击 ”自动标注“,使用PPOCR超轻量模型对图片文件名前图片状态为 “X” 的图片进行自动标注。\n" \
"5. 标记框绘制完成后,用户点击 “确认”,检测框会先被预分配一个 “待识别” 标签。\n" \ "4. 手动标注:点击 “矩形标注”(推荐直接在英文模式下点击键盘中的 “W”),用户可对当前图片中模型未检出的部分进行手动" \
"6. 重新识别:将图片中的所有检测画绘制/调整完成后,点击 “重新识别”,PPOCR模型会对当前图片中的**所有检测框**重新识别。\n" \ "绘制标记框。点击键盘P,则使用四点标注模式(或点击“编辑” - “四点标注”),用户依次点击4个点后,双击左键表示标注完成。\n" \
"7. 内容更改:双击识别结果,对不准确的识别结果进行手动更改。\n" \ "5. 标记框绘制完成后,用户点击 “确认”,检测框会先被预分配一个 “待识别” 标签。\n" \
"8. 保存:点击 “保存”,图片状态切换为 “√”,跳转至下一张。\n" \ "6. 重新识别:将图片中的所有检测画绘制/调整完成后,点击 “重新识别”,PPOCR模型会对当前图片中的**所有检测框**重新识别。\n" \
"9. 删除:点击 “删除图像”,图片将会被删除至回收站。\n" \ "7. 内容更改:双击识别结果,对不准确的识别结果进行手动更改。\n" \
"10. 标注结果:关闭应用程序或切换文件路径后,手动保存过的标签将会被存放在所打开图片文件夹下的" \ "8. 保存:点击 “保存”,图片状态切换为 “√”,跳转至下一张。\n" \
"*Label.txt*中。在菜单栏点击 “PaddleOCR” - 保存识别结果后,会将此类图片的识别训练数据保存在*crop_img*文件夹下," \ "9. 删除:点击 “删除图像”,图片将会被删除至回收站。\n" \
"识别标签保存在*rec_gt.txt*中。\n" "10. 标注结果:关闭应用程序或切换文件路径后,手动保存过的标签将会被存放在所打开图片文件夹下的" \
return msg "*Label.txt*中。在菜单栏点击 “PaddleOCR” - 保存识别结果后,会将此类图片的识别训练数据保存在*crop_img*文件夹下," \
\ No newline at end of file "识别标签保存在*rec_gt.txt*中。\n"
else:
msg = "1. Build and launch using the instructions above.\n" \
"2. Click 'Open Dir' in Menu/File to select the folder of the picture.\n"\
"3. Click 'Auto recognition', use PPOCR model to automatically annotate images which marked with 'X' before the file name."\
"4. Create Box:\n"\
"4.1 Click 'Create RectBox' or press 'W' in English keyboard mode to draw a new rectangle detection box. Click and release left mouse to select a region to annotate the text area.\n"\
"4.2 Press 'P' to enter four-point labeling mode which enables you to create any four-point shape by clicking four points with the left mouse button in succession and DOUBLE CLICK the left mouse as the signal of labeling completion.\n"\
"5. After the marking frame is drawn, the user clicks 'OK', and the detection frame will be pre-assigned a TEMPORARY label.\n"\
"6. Click re-Recognition, model will rewrite ALL recognition results in ALL detection box.\n"\
"7. Double click the result in 'recognition result' list to manually change inaccurate recognition results.\n"\
"8. Click 'Save', the image status will switch to '√',then the program automatically jump to the next.\n"\
"9. Click 'Delete Image' and the image will be deleted to the recycle bin.\n"\
"10. Labeling result: After closing the application or switching the file path, the manually saved label will be stored in *Label.txt* under the opened picture folder.\n"\
" Click PaddleOCR-Save Recognition Results in the menu bar, the recognition training data of such pictures will be saved in the *crop_img* folder, and the recognition label will be saved in *rec_gt.txt*.\n"
return msg
...@@ -87,4 +87,10 @@ creatPolygon=四点标注 ...@@ -87,4 +87,10 @@ creatPolygon=四点标注
drawSquares=正方形标注 drawSquares=正方形标注
saveRec=保存识别结果 saveRec=保存识别结果
tempLabel=待识别 tempLabel=待识别
steps=操作步骤 steps=操作步骤
\ No newline at end of file choseModelLg=选择模型语言
cancel=取消
ok=确认
autolabeling=自动标注中
hideBox=隐藏所有标注
showBox=显示所有标注
\ No newline at end of file
...@@ -76,10 +76,10 @@ ImageResize=Image Resize ...@@ -76,10 +76,10 @@ ImageResize=Image Resize
IR=Image Resize IR=Image Resize
autoRecognition=Auto Recognition autoRecognition=Auto Recognition
reRecognition=Re-recognition reRecognition=Re-recognition
mfile=file mfile=File
medit=eidt medit=Eidt
mview=view mview=View
mhelp=help mhelp=Help
iconList=Icon List iconList=Icon List
detectionBoxposition=Detection box position detectionBoxposition=Detection box position
recognitionResult=Recognition result recognitionResult=Recognition result
...@@ -87,4 +87,10 @@ creatPolygon=Create Quadrilateral ...@@ -87,4 +87,10 @@ creatPolygon=Create Quadrilateral
drawSquares=Draw Squares drawSquares=Draw Squares
saveRec=Save Recognition Result saveRec=Save Recognition Result
tempLabel=TEMPORARY tempLabel=TEMPORARY
setps=Steps steps=Steps
\ No newline at end of file choseModelLg=Choose Model Language
cancel=Cancel
ok=OK
autolabeling=Automatic Labeling
hideBox=Hide All Box
showBox=Show All Box
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册