Skip to content

Commit

Permalink
Merge branch 'dygraph' into dygraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Topdu committed Aug 17, 2021
2 parents 8227ad1 + a81b88a commit adc62fc
Show file tree
Hide file tree
Showing 152 changed files with 23,069 additions and 12,344 deletions.
9 changes: 5 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
include LICENSE.txt
include LICENSE
include README.md

recursive-include ppocr/utils *.txt utility.py logging.py
recursive-include ppocr/data/ *.py
recursive-include ppocr/utils *.txt utility.py logging.py network.py
recursive-include ppocr/data *.py
recursive-include ppocr/postprocess *.py
recursive-include tools/infer *.py
recursive-include ppocr/utils/e2e_utils/ *.py
recursive-include ppocr/utils/e2e_utils *.py
recursive-include ppstructure *.py
129 changes: 105 additions & 24 deletions PPOCRLabel/PPOCRLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
import cv2



__dir__ = os.path.dirname(os.path.abspath(__file__))

import numpy as np


sys.path.append(__dir__)
sys.path.append(os.path.abspath(os.path.join(__dir__, '../..')))
sys.path.append("..")
Expand Down Expand Up @@ -78,7 +83,7 @@ def menu(self, title, actions=None):
addActions(menu, actions)
return menu

def toolbar(self, title, actions=None):
def toolbar(self, title, actions=None):
toolbar = ToolBar(title)
toolbar.setObjectName(u'%sToolBar' % title)
# toolbar.setOrientation(Qt.Vertical)
Expand All @@ -98,7 +103,7 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla

# Load setting in the main thread
self.settings = Settings()
self.settings.load()
self.settings.load()
settings = self.settings
self.lang = lang
# Load string bundle for i18n
Expand Down Expand Up @@ -159,7 +164,7 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
filelistLayout = QVBoxLayout()
filelistLayout.setContentsMargins(0, 0, 0, 0)
filelistLayout.addWidget(self.fileListWidget)

self.AutoRecognition = QToolButton()
self.AutoRecognition.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.AutoRecognition.setIcon(newIcon('Auto'))
Expand All @@ -176,7 +181,7 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
self.filedock.setObjectName(getStr('files'))
self.filedock.setWidget(fileListContainer)
self.addDockWidget(Qt.LeftDockWidgetArea, self.filedock)

######## Right area ##########
listLayout = QVBoxLayout()
listLayout.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -250,7 +255,7 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
self.imgsplider.setMaximum(150)
self.imgsplider.setSingleStep(1)
self.imgsplider.setTickPosition(QSlider.TicksBelow)
self.imgsplider.setTickInterval(1)
self.imgsplider.setTickInterval(1)
op = QGraphicsOpacityEffect()
op.setOpacity(0.2)
self.imgsplider.setGraphicsEffect(op)
Expand All @@ -266,7 +271,9 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
self.zoomWidget = ZoomWidget()
self.colorDialog = ColorDialog(parent=self)
self.zoomWidgetValue = self.zoomWidget.value()


self.msgBox = QMessageBox()

########## thumbnail #########
hlayout = QHBoxLayout()
m = (0, 0, 0, 0)
Expand Down Expand Up @@ -294,7 +301,7 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
self.nextButton.setStyleSheet('border: none;')
self.nextButton.clicked.connect(self.openNextImg)
self.nextButton.setShortcut('d')

hlayout.addWidget(self.preButton)
hlayout.addWidget(self.iconlist)
hlayout.addWidget(self.nextButton)
Expand All @@ -303,7 +310,7 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
iconListContainer = QWidget()
iconListContainer.setLayout(hlayout)
iconListContainer.setFixedHeight(100)

########### Canvas ###########
self.canvas = Canvas(parent=self)
self.canvas.zoomRequest.connect(self.zoomRequest)
Expand Down Expand Up @@ -360,6 +367,9 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
opendir = action(getStr('openDir'), self.openDirDialog,
'Ctrl+u', 'open', getStr('openDir'))

open_dataset_dir = action(getStr('openDatasetDir'), self.openDatasetDirDialog,
'Ctrl+p', 'open', getStr('openDatasetDir'), enabled=False)

save = action(getStr('save'), self.saveFile,
'Ctrl+V', 'verify', getStr('saveDetail'), enabled=False)

Expand Down Expand Up @@ -398,6 +408,7 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
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'))
showKeys = action(getStr('keys'), self.showKeysDialog, None, 'help', getStr('keys'))

zoom = QWidgetAction(self)
zoom.setDefaultWidget(self.zoomWidget)
Expand Down Expand Up @@ -438,7 +449,7 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
AutoRec = action(getStr('autoRecognition'), self.autoRecognition,
'', 'Auto', getStr('autoRecognition'), enabled=False)

reRec = action(getStr('reRecognition'), self.reRecognition,
reRec = action(getStr('reRecognition'), self.reRecognition,
'Ctrl+Shift+R', 'reRec', getStr('reRecognition'), enabled=False)

singleRere = action(getStr('singleRe'), self.singleRerecognition,
Expand All @@ -456,6 +467,12 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
undoLastPoint = action(getStr("undoLastPoint"), self.canvas.undoLastPoint,
'Ctrl+Z', "undo", getStr("undoLastPoint"), enabled=False)

rotateLeft = action(getStr("rotateLeft"), partial(self.rotateImgAction,1),
'Ctrl+Alt+L', "rotateLeft", getStr("rotateLeft"), enabled=False)

rotateRight = action(getStr("rotateRight"), partial(self.rotateImgAction,-1),
'Ctrl+Alt+R', "rotateRight", getStr("rotateRight"), enabled=False)

undo = action(getStr("undo"), self.undoShapeEdit,
'Ctrl+Z', "undo", getStr("undo"), enabled=False)

Expand Down Expand Up @@ -519,13 +536,14 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
zoom=zoom, zoomIn=zoomIn, zoomOut=zoomOut, zoomOrg=zoomOrg,
fitWindow=fitWindow, fitWidth=fitWidth,
zoomActions=zoomActions, saveLabel=saveLabel,
undo=undo, undoLastPoint=undoLastPoint,
undo=undo, undoLastPoint=undoLastPoint,open_dataset_dir=open_dataset_dir,
rotateLeft=rotateLeft,rotateRight=rotateRight,
fileMenuActions=(
opendir, saveLabel, resetAll, quit),
opendir, open_dataset_dir, saveLabel, resetAll, quit),
beginner=(), advanced=(),
editMenu=(createpoly, edit, copy, delete,singleRere,None, undo, undoLastPoint,
None, color1, self.drawSquaresOption),
beginnerContext=(create, edit, copy, delete, singleRere),
None, rotateLeft, rotateRight, None, color1, self.drawSquaresOption),
beginnerContext=(create, edit, copy, delete, singleRere, rotateLeft, rotateRight,),
advancedContext=(createMode, editMode, edit, copy,
delete, shapeLineColor, shapeFillColor),
onLoadActive=(
Expand Down Expand Up @@ -563,9 +581,9 @@ def __init__(self, lang="ch", gpu=False, defaultFilename=None, defaultPrefdefCla
self.autoSaveOption.triggered.connect(self.autoSaveFunc)

addActions(self.menus.file,
(opendir, None, saveLabel, saveRec, self.autoSaveOption, None, resetAll, deleteImg, quit))
(opendir, open_dataset_dir, None, saveLabel, saveRec, self.autoSaveOption, None, resetAll, deleteImg, quit))

addActions(self.menus.help, (showSteps, showInfo))
addActions(self.menus.help, (showKeys,showSteps, showInfo))
addActions(self.menus.view, (
self.displayLabelOption, self.labelDialogOption,
None,
Expand Down Expand Up @@ -760,6 +778,10 @@ def showStepsDialog(self):
msg = stepsInfo(self.lang)
QMessageBox.information(self, u'Information', msg)

def showKeysDialog(self):
msg = keysInfo(self.lang)
QMessageBox.information(self, u'Information', msg)

def createShape(self):
assert self.beginner()
self.canvas.setEditing(False)
Expand All @@ -773,6 +795,38 @@ def createPolygon(self):
self.actions.create.setEnabled(False)
self.actions.undoLastPoint.setEnabled(True)

def rotateImg(self, filename, k, _value):

self.actions.rotateRight.setEnabled(_value)
pix = cv2.imread(filename)
pix = np.rot90(pix, k)
cv2.imwrite(filename, pix)
self.canvas.update()
self.loadFile(filename)

def rotateImgWarn(self):
if self.lang == 'ch':
self.msgBox.warning (self, "提示", "\n 该图片已经有标注框,旋转操作会打乱标注,建议清除标注框后旋转。")
else:
self.msgBox.warning (self, "Warn", "\n The picture already has a label box, and rotation will disrupt the label.\
It is recommended to clear the label box and rotate it.")

def rotateImgAction(self, k=1, _value=False):

filename = self.mImgList[self.currIndex]

if os.path.exists(filename):
if self.itemsToShapesbox:
self.rotateImgWarn()
else:
self.saveFile()
self.dirty = False
self.rotateImg(filename=filename, k=k, _value=True)
else:
self.rotateImgWarn()
self.actions.rotateRight.setEnabled(False)
self.actions.rotateLeft.setEnabled(False)

def toggleDrawingSensitive(self, drawing=True):
"""In the middle of drawing, toggling between modes should be disabled."""
self.actions.editMode.setEnabled(not drawing)
Expand Down Expand Up @@ -880,7 +934,12 @@ def editBox(self): # ADD
self.updateComboBox()

def updateBoxlist(self):
for shape in self.canvas.selectedShapes+[self.canvas.hShape]:
self.canvas.selectedShapes_hShape = []
if self.canvas.hShape != None:
self.canvas.selectedShapes_hShape = self.canvas.selectedShapes + [self.canvas.hShape]
else:
self.canvas.selectedShapes_hShape = self.canvas.selectedShapes
for shape in self.canvas.selectedShapes_hShape:
item = self.shapesToItemsbox[shape] # listitem
text = [(int(p.x()), int(p.y())) for p in shape.points]
item.setText(str(text))
Expand Down Expand Up @@ -1269,15 +1328,15 @@ def loadFile(self, filePath=None):
titem = self.iconlist.item(i)
titem.setSelected(True)
self.iconlist.scrollToItem(titem)
break
break
else:
self.fileListWidget.clear()
self.mImgList.clear()
self.iconlist.clear()

# if unicodeFilePath and self.iconList.count() > 0:
# if unicodeFilePath in self.mImgList:

if unicodeFilePath and os.path.exists(unicodeFilePath):
self.canvas.verified = False

Expand Down Expand Up @@ -1308,7 +1367,7 @@ def loadFile(self, filePath=None):
self.addRecentFile(self.filePath)
self.toggleActions(True)
self.showBoundingBoxFromPPlabel(filePath)

self.setWindowTitle(__appname__ + ' ' + filePath)

# Default : select last item if there is at least one item
Expand All @@ -1320,7 +1379,7 @@ def loadFile(self, filePath=None):
return True
return False


def showBoundingBoxFromPPlabel(self, filePath):
imgidx = self.getImglabelidx(filePath)
if imgidx not in self.PPlabel.keys():
Expand Down Expand Up @@ -1413,6 +1472,7 @@ def closeEvent(self, event):

def loadRecent(self, filename):
if self.mayContinue():
print(filename,"======")
self.loadFile(filename)

def scanAllImages(self, folderPath):
Expand Down Expand Up @@ -1448,6 +1508,23 @@ def openDirDialog(self, _value=False, dirpath=None, silent=False):
self.lastOpenDir = targetDirPath
self.importDirImages(targetDirPath)

def openDatasetDirDialog(self,):
if self.lastOpenDir and os.path.exists(self.lastOpenDir):
if platform.system() == 'Windows':
os.startfile(self.lastOpenDir)
else:
os.system('open ' + os.path.normpath(self.lastOpenDir))
defaultOpenDirPath = self.lastOpenDir

else:
if self.lang == 'ch':
self.msgBox.warning(self, "提示", "\n 原文件夹已不存在,请从新选择数据集路径!")
else:
self.msgBox.warning(self, "Warn", "\n The original folder no longer exists, please choose the data set path again!")

self.actions.open_dataset_dir.setEnabled(False)
defaultOpenDirPath = os.path.dirname(self.filePath) if self.filePath else '.'

def importDirImages(self, dirpath, isDelete = False):
if not self.mayContinue() or not dirpath:
return
Expand Down Expand Up @@ -1495,6 +1572,10 @@ def importDirImages(self, dirpath, isDelete = False):
self.reRecogButton.setEnabled(True)
self.actions.AutoRec.setEnabled(True)
self.actions.reRec.setEnabled(True)
self.actions.open_dataset_dir.setEnabled(True)
self.actions.rotateLeft.setEnabled(True)
self.actions.rotateRight.setEnabled(True)



def openPrevImg(self, _value=False):
Expand All @@ -1503,7 +1584,7 @@ def openPrevImg(self, _value=False):

if self.filePath is None:
return

currIndex = self.mImgList.index(self.filePath)
self.mImgList5 = self.mImgList[:5]
if currIndex - 1 >= 0:
Expand Down Expand Up @@ -1533,7 +1614,7 @@ def openNextImg(self, _value=False):
if filename:
print('file name in openNext is ',filename)
self.loadFile(filename)

def updateFileListIcon(self, filename):
pass

Expand Down Expand Up @@ -1645,7 +1726,7 @@ def resetAll(self):
proc.startDetached(os.path.abspath(__file__))

def mayContinue(self): #
if not self.dirty:
if not self.dirty:
return True
else:
discardChanges = self.discardChangesDialog()
Expand Down Expand Up @@ -2072,7 +2153,7 @@ def main():


if __name__ == '__main__':

resource_file = './libs/resources.py'
if not os.path.exists(resource_file):
output = os.system('pyrcc5 -o libs/resources.py resources.qrc')
Expand Down
Loading

0 comments on commit adc62fc

Please sign in to comment.