diff --git a/Cache.cach b/Cache.cach new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Label.txt b/Label.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/PPOCRLabel/PPOCRLabel.py b/PPOCRLabel/PPOCRLabel.py index 6477ea0702..0e030742ce 100644 --- a/PPOCRLabel/PPOCRLabel.py +++ b/PPOCRLabel/PPOCRLabel.py @@ -61,7 +61,7 @@ from combobox import ComboBox from libs.constants import * from libs.utils import * from libs.settings import Settings -from libs.shape import Shape, DEFAULT_LINE_COLOR, DEFAULT_FILL_COLOR +from libs.shape import Shape, DEFAULT_LINE_COLOR, DEFAULT_FILL_COLOR,DEFAULT_LOCK_COLOR from libs.stringBundle import StringBundle from libs.canvas import Canvas from libs.zoomWidget import ZoomWidget @@ -395,6 +395,7 @@ class MainWindow(QMainWindow, WindowMixin): delete = action(getStr('delBox'), self.deleteSelectedShape, 'backspace', 'delete', getStr('delBoxDetail'), enabled=False) + copy = action(getStr('dupBox'), self.copySelectedShape, 'Ctrl+C', 'copy', getStr('dupBoxDetail'), enabled=False) @@ -405,6 +406,7 @@ class MainWindow(QMainWindow, WindowMixin): 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')) @@ -476,6 +478,10 @@ class MainWindow(QMainWindow, WindowMixin): undo = action(getStr("undo"), self.undoShapeEdit, 'Ctrl+Z', "undo", getStr("undo"), enabled=False) + + lock = action(getStr("lockBox"), self.lockSelectedShape, + None, "lock", getStr("lockBoxDetail"), + enabled=False) self.editButton.setDefaultAction(edit) self.newButton.setDefaultAction(create) @@ -538,13 +544,13 @@ class MainWindow(QMainWindow, WindowMixin): fitWindow=fitWindow, fitWidth=fitWidth, zoomActions=zoomActions, saveLabel=saveLabel, undo=undo, undoLastPoint=undoLastPoint,open_dataset_dir=open_dataset_dir, - rotateLeft=rotateLeft,rotateRight=rotateRight, + rotateLeft=rotateLeft,rotateRight=rotateRight,lock=lock, fileMenuActions=( opendir, open_dataset_dir, saveLabel, resetAll, quit), beginner=(), advanced=(), editMenu=(createpoly, edit, copy, delete,singleRere,None, undo, undoLastPoint, - None, rotateLeft, rotateRight, None, color1, self.drawSquaresOption), - beginnerContext=(create, edit, copy, delete, singleRere, rotateLeft, rotateRight,), + None, rotateLeft, rotateRight, None, color1, self.drawSquaresOption,lock), + beginnerContext=(create, edit, copy, delete, singleRere, rotateLeft, rotateRight,lock), advancedContext=(createMode, editMode, edit, copy, delete, shapeLineColor, shapeFillColor), onLoadActive=( @@ -998,6 +1004,7 @@ class MainWindow(QMainWindow, WindowMixin): self.actions.delete.setEnabled(n_selected) self.actions.copy.setEnabled(n_selected) self.actions.edit.setEnabled(n_selected == 1) + self.actions.lock.setEnabled(n_selected) def addLabel(self, shape): shape.paintLabel = self.displayLabelOption.isChecked() @@ -1041,7 +1048,7 @@ class MainWindow(QMainWindow, WindowMixin): def loadLabels(self, shapes): s = [] for label, points, line_color, fill_color, difficult in shapes: - shape = Shape(label=label) + shape = Shape(label=label,line_color=line_color) for x, y in points: # Ensure the labels are within the bounds of the image. If not, fix them. @@ -1065,8 +1072,10 @@ class MainWindow(QMainWindow, WindowMixin): # shape.fill_color = generateColorByText(label) self.addLabel(shape) + self.updateComboBox() self.canvas.loadShapes(s) + def singleLabel(self, shape): if shape is None: @@ -1322,6 +1331,7 @@ class MainWindow(QMainWindow, WindowMixin): ### self.iconlist.clear() self.additems5(None) + for i in range(5): item_tooltip = self.iconlist.item(i).toolTip() # print(i,"---",item_tooltip) @@ -1340,7 +1350,6 @@ class MainWindow(QMainWindow, WindowMixin): if unicodeFilePath and os.path.exists(unicodeFilePath): self.canvas.verified = False - cvimg = cv2.imdecode(np.fromfile(unicodeFilePath, dtype=np.uint8), 1) height, width, depth = cvimg.shape cvimg = cv2.cvtColor(cvimg, cv2.COLOR_BGR2RGB) @@ -1367,6 +1376,7 @@ class MainWindow(QMainWindow, WindowMixin): self.paintCanvas() self.addRecentFile(self.filePath) self.toggleActions(True) + self.showBoundingBoxFromPPlabel(filePath) self.setWindowTitle(__appname__ + ' ' + filePath) @@ -1380,15 +1390,18 @@ class MainWindow(QMainWindow, WindowMixin): return True return False - def showBoundingBoxFromPPlabel(self, filePath): + width, height = self.image.width(), self.image.height() imgidx = self.getImglabelidx(filePath) - if imgidx not in self.PPlabel.keys(): - return - shapes = [] - for box in self.PPlabel[imgidx]: - shapes.append((box['transcription'], box['points'], None, None, box['difficult'])) - + shapes =[] + #box['ratio'] of the shapes saved in lockedShapes contains the ratio of the + # four corner coordinates of the shapes to the height and width of the image + for box in self.canvas.lockedShapes: + shapes.append(("锁定框:待识别", [[s[0]*width,s[1]*height]for s in box['ratio']],DEFAULT_LOCK_COLOR, None, box['difficult'])) + if imgidx in self.PPlabel.keys(): + for box in self.PPlabel[imgidx]: + # print(box) + shapes.append((box['transcription'], box['points'], None, None, box['difficult'])) self.loadLabels(shapes) self.canvas.verified = False @@ -2107,6 +2120,34 @@ class MainWindow(QMainWindow, WindowMixin): self.labelList.clearSelection() self._noSelectionSlot = False self.canvas.loadShapes(shapes, replace=replace) + print("loadShapes")#1 + + + def lockSelectedShape(self): + width, height = self.image.width(), self.image.height() + def format_shape(s): + return dict(label=s.label, # str + line_color=s.line_color.getRgb(), + fill_color=s.fill_color.getRgb(), + ratio=[[int(p.x())/width, int(p.y())/height] for p in s.points], # QPonitF + # add chris + difficult=s.difficult) # bool + #lock + if len(self.canvas.lockedShapes) == 0: + for s in self.canvas.selectedShapes: + s.line_color=DEFAULT_LOCK_COLOR + shapes=[format_shape(shape) for shape in self.canvas.selectedShapes] + trans_dic = [] + for box in shapes: + trans_dic.append({"transcription": box['label'], "ratio": box['ratio'], 'difficult': box['difficult']}) + self.canvas.lockedShapes = trans_dic + # print("self.canvas.lockedShapes:",self.canvas.lockedShapes) + #unlock + else: + for s in self.canvas.shapes: + s.line_color=DEFAULT_LINE_COLOR + trans_dic = [] + self.canvas.lockedShapes = trans_dic def inverted(color): diff --git a/PPOCRLabel/data/Cache.cach b/PPOCRLabel/data/Cache.cach new file mode 100644 index 0000000000..dcb2482134 --- /dev/null +++ b/PPOCRLabel/data/Cache.cach @@ -0,0 +1 @@ +data/paddle.png [{"transcription": "1/j飞浆", "points": [[27.0, 17.0], [158.0, 20.0], [158.0, 64.0], [27.0, 61.0]], "difficult": false}] diff --git a/PPOCRLabel/data/Label.txt b/PPOCRLabel/data/Label.txt new file mode 100644 index 0000000000..1ad8a19278 --- /dev/null +++ b/PPOCRLabel/data/Label.txt @@ -0,0 +1 @@ +data/paddle.png [{"transcription": "1/j飞浆", "points": [[27, 17], [158, 20], [160, 61], [27, 61]], "difficult": false}] diff --git a/PPOCRLabel/data/fileState.txt b/PPOCRLabel/data/fileState.txt new file mode 100644 index 0000000000..b37d8de725 --- /dev/null +++ b/PPOCRLabel/data/fileState.txt @@ -0,0 +1 @@ +/Users/mac/Downloads/PaddleOCR/PPOCRLabel/data/paddle.png 1 diff --git a/PPOCRLabel/libs/canvas.py b/PPOCRLabel/libs/canvas.py index 6ac1f28b85..9550594fc6 100644 --- a/PPOCRLabel/libs/canvas.py +++ b/PPOCRLabel/libs/canvas.py @@ -86,7 +86,7 @@ class Canvas(QWidget): #initialisation for panning self.pan_initial_pos = QPoint() - + self.lockedShapes = [] def setDrawingColor(self, qColor): self.drawingLineColor = qColor self.drawingRectColor = qColor diff --git a/PPOCRLabel/libs/resources.py b/PPOCRLabel/libs/resources.py index 70241e5d25..0a9f4c0835 100644 --- a/PPOCRLabel/libs/resources.py +++ b/PPOCRLabel/libs/resources.py @@ -11014,7 +11014,52 @@ qt_resource_data = b"\ \x00\x00\x0b\xe1\ \x89\ \x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\ -\x00\x00\x30\x00\x00\x00\x30\x08\x06\x00\x00\x00\x57\x02\xf9\x87\ +\x00\x00\x3c\x00\x00\x00\x3c\x08\x06\x00\x00\x00\x3a\xfc\xd9\x72\ +\x00\x00\x00\x06\x62\x4b\x47\x44\x00\xff\x00\xff\x00\xff\xa0\xbd\ +\xa7\x93\x00\x00\x00\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\ +\x0b\x13\x01\x00\x9a\x9c\x18\x00\x00\x00\x07\x74\x49\x4d\x45\x07\ +\xe2\x03\x02\x04\x34\x31\x97\x0c\xf9\x63\x00\x00\x00\x19\x74\x45\ +\x58\x74\x43\x6f\x6d\x6d\x65\x6e\x74\x00\x43\x72\x65\x61\x74\x65\ +\x64\x20\x77\x69\x74\x68\x20\x47\x49\x4d\x50\x57\x81\x0e\x17\x00\ +\x00\x02\x0b\x49\x44\x41\x54\x68\xde\xed\x98\xcd\x4b\x94\x51\x14\ +\xc6\x7f\x16\x96\x7d\x2c\xa2\x55\x1b\x3f\x90\xc0\x45\x60\x21\x6e\ +\x5b\x04\x15\x45\x14\x06\x23\xae\x5a\xbb\x90\x72\x21\x6d\x4a\xa5\ +\x76\x41\x7f\x41\xae\xda\x88\x91\xd2\x22\x17\x66\x10\xa2\x92\x50\ +\x18\x45\x05\x81\x04\xd9\x2a\x22\xa5\x60\x48\xc4\x84\x69\x73\x16\ +\x0f\x2f\x33\x13\xfa\x5e\x21\xc6\xe7\x07\x97\xfb\xce\x73\xce\x7d\ +\xee\xdc\x97\x73\xef\x65\x06\x8c\x31\xc6\x18\x63\x8c\x31\xc6\x18\ +\x63\x8c\x49\x4e\x0f\x50\x8a\x76\x26\xb5\xf9\x9e\xff\x70\xc1\xed\ +\xf2\xfc\x61\x37\x2d\xf8\x1b\xb0\xb2\x9b\x16\xfc\x7e\x27\xcc\xb7\ +\xb2\xe0\x59\xd9\x5b\xa7\x32\xb1\xe3\xc0\x9f\x88\x7d\x02\xf6\x49\ +\xac\x1e\xb8\x01\xbc\x04\x7e\x46\x9b\x03\x7a\xcb\xcc\x7f\x04\x68\ +\xaa\x50\xce\x5b\xf1\x49\xc2\x7d\x59\x70\x4f\x26\xf6\x48\x62\x67\ +\x45\xef\x00\xde\x4a\x2c\xdb\x9e\x03\x7b\x25\xff\xb4\xc4\xae\xe5\ +\xf0\x49\x42\xb7\x4c\x30\x2c\x7a\xa7\xe8\xe3\xa2\x9f\x00\xd6\x24\ +\x36\x0d\xdc\x01\x1e\x02\x9b\xa2\xdf\x94\x31\x7d\xa2\x9f\xcc\xe1\ +\x93\x84\x66\x31\x1f\x0d\xad\x0e\x78\x11\xda\x9a\x94\xe3\x81\x28\ +\xc9\x12\xb0\x01\x5c\xce\x78\x15\xc4\xeb\xb5\xe8\x0f\x42\xdb\x04\ +\xf6\xe7\xf0\x49\x42\x1d\xf0\x3d\xcc\x17\x43\xbb\x20\x13\xde\x92\ +\xdc\xeb\xa2\xdf\xae\xe0\xb5\x1a\xf1\xdf\xa2\x2f\x84\xf6\x31\xa7\ +\x4f\x32\x26\xc3\xbc\x18\x7b\xe6\x5d\x7c\xfe\x0c\x34\x48\xde\x94\ +\x7c\xd1\xd6\x32\x3e\xf5\x52\xa6\x5f\xe5\x00\x2d\x86\x36\x96\xc3\ +\x27\xe9\xb5\xf4\x2a\xfa\xc3\xc0\x80\xec\xb3\x7e\x60\x5d\xf2\x8e\ +\xc9\x73\xb1\x8c\xcf\x95\x28\x57\x80\x67\xd1\xb7\x84\xaf\x5e\x49\ +\xdb\xf1\x49\xca\x79\x79\xe3\x1b\xd1\x3f\x2d\x93\x37\x56\xa5\x14\ +\x3b\x81\x1f\x11\x5b\x05\x1a\x43\xef\x92\x31\x97\x72\xf8\x24\xe5\ +\x68\xe6\x3a\x58\xaf\x50\x6a\x85\x4c\xde\x13\x60\x08\x78\x2c\xf7\ +\x75\x09\xb8\x28\x63\x86\x45\x6f\xca\xe1\x93\x9c\x25\x99\xe8\x6e\ +\x95\xbc\x91\x2a\xf7\xe6\x97\x38\xf0\x94\x89\x88\xfd\x8a\xc3\x68\ +\xbb\x3e\x49\x69\x00\x96\x63\xb2\x65\xe0\xe0\x3f\x4e\xf5\x02\x30\ +\x13\x25\x57\x04\xde\x00\x83\xc0\xa1\x2a\x2f\x72\x3e\xa7\x4f\x52\ +\x06\xe5\xed\x5e\xad\xf5\xdf\xa9\xcd\x72\x05\x4c\x67\xca\xae\x26\ +\x99\x90\xd3\xb9\xad\xd6\x17\x7b\x4e\x4a\xf9\x9e\xff\x94\x31\xc6\ +\x18\x63\x8c\x31\xc6\x18\x63\x8c\x31\xc6\x98\x54\xfc\x05\x94\x34\ +\xe4\xeb\x87\xd7\x3b\x14\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\ +\x60\x82\ +\x00\x00\x04\x4e\ +\x89\ +\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\ +\x00\x00\x18\x00\x00\x00\x18\x08\x06\x00\x00\x00\xe0\x77\x3d\xf8\ \x00\x00\x00\x04\x67\x41\x4d\x41\x00\x00\xb1\x8f\x0b\xfc\x61\x05\ \x00\x00\x00\x20\x63\x48\x52\x4d\x00\x00\x7a\x26\x00\x00\x80\x84\ \x00\x00\xfa\x00\x00\x00\x80\xe8\x00\x00\x75\x30\x00\x00\xea\x60\ diff --git a/PPOCRLabel/libs/shape.py b/PPOCRLabel/libs/shape.py index ef8e09be06..434897cefc 100644 --- a/PPOCRLabel/libs/shape.py +++ b/PPOCRLabel/libs/shape.py @@ -30,6 +30,7 @@ DEFAULT_SELECT_LINE_COLOR = QColor(255, 255, 255) DEFAULT_SELECT_FILL_COLOR = QColor(0, 128, 255, 155) DEFAULT_VERTEX_FILL_COLOR = QColor(0, 255, 0, 255) DEFAULT_HVERTEX_FILL_COLOR = QColor(255, 0, 0) +DEFAULT_LOCK_COLOR = QColor(255, 0, 255) MIN_Y_LABEL = 10 diff --git a/PPOCRLabel/resources/icons/lock.png b/PPOCRLabel/resources/icons/lock.png new file mode 100644 index 0000000000..f4d50d70b4 Binary files /dev/null and b/PPOCRLabel/resources/icons/lock.png differ diff --git a/PPOCRLabel/resources/strings/strings-en.properties b/PPOCRLabel/resources/strings/strings-en.properties index 70036e6560..f59e43aa92 100644 --- a/PPOCRLabel/resources/strings/strings-en.properties +++ b/PPOCRLabel/resources/strings/strings-en.properties @@ -104,4 +104,6 @@ singleRe=Re-recognition RectBox labelDialogOption=Pop-up Label Input Dialog undo=Undo undoLastPoint=Undo Last Point -autoSaveMode=Auto Export Label Mode \ No newline at end of file +autoSaveMode=Auto Export Label Mode +lockBox=Lock selected box/Unlock all box +lockBoxDetail=Lock selected box/Unlock all box \ No newline at end of file diff --git a/PPOCRLabel/resources/strings/strings-zh-CN.properties b/PPOCRLabel/resources/strings/strings-zh-CN.properties index 1cd4da7611..d8bd9d4bff 100644 --- a/PPOCRLabel/resources/strings/strings-zh-CN.properties +++ b/PPOCRLabel/resources/strings/strings-zh-CN.properties @@ -104,4 +104,6 @@ singleRe=重识别此区块 labelDialogOption=弹出标记输入框 undo=撤销 undoLastPoint=撤销上个点 -autoSaveMode=自动导出标记结果 \ No newline at end of file +autoSaveMode=自动导出标记结果 +lockBox=锁定框/解除锁定框 +lockBoxDetail=若当前没有框处于锁定状态则锁定选中的框,若存在锁定框则解除所有锁定框的锁定状态 diff --git a/fileState.txt b/fileState.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ppocr/Cache.cach b/ppocr/Cache.cach new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ppocr/Label.txt b/ppocr/Label.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ppocr/fileState.txt b/ppocr/fileState.txt new file mode 100644 index 0000000000..e69de29bb2