Add save label in menu

This commit is contained in:
Leif 2020-12-11 21:53:01 +08:00
parent 4c4cad8bd5
commit a14fce5bdf
9 changed files with 4895 additions and 5016 deletions

View File

@ -373,11 +373,11 @@ class MainWindow(QMainWindow, WindowMixin):
openPrevImg = action(getStr('prevImg'), self.openPrevImg,
'a', 'prev', getStr('prevImgDetail'))
verify = action(getStr('verifyImg'), self.verifyImg,
'space', 'verify', getStr('verifyImgDetail'))
# verify = action(getStr('verifyImg'), self.verifyImg,
# 'space', 'verify', getStr('verifyImgDetail'))
save = action(getStr('save'), self.saveFile,
'Ctrl+S', 'save', getStr('saveDetail'), enabled=False)
'Ctrl+S', 'verify', getStr('saveDetail'), enabled=False)
alcm = action(getStr('choosemodel'), self.autolcm,
'Ctrl+M', 'next', getStr('tipchoosemodel'))
@ -463,6 +463,9 @@ class MainWindow(QMainWindow, WindowMixin):
saveRec = action(getStr('saveRec'), self.saveRecResult,
'', 'saveRec', getStr('saveRec'), enabled=False)
saveLabel = action(getStr('saveLabel'), self.saveLabelFile, #
'', 'save', getStr('saveLabel'), enabled=False)
self.editButton.setDefaultAction(edit)
self.newButton.setDefaultAction(create)
self.DelButton.setDefaultAction(deleteImg)
@ -526,9 +529,9 @@ class MainWindow(QMainWindow, WindowMixin):
shapeLineColor=shapeLineColor, shapeFillColor=shapeFillColor,
zoom=zoom, zoomIn=zoomIn, zoomOut=zoomOut, zoomOrg=zoomOrg,
fitWindow=fitWindow, fitWidth=fitWidth,
zoomActions=zoomActions,
zoomActions=zoomActions, saveLabel=saveLabel,
fileMenuActions=(
open, opendir, save, resetAll, quit),
open, opendir, saveLabel, resetAll, quit),
beginner=(), advanced=(),
editMenu=(createpoly, edit, copy, delete,
None, color1, self.drawSquaresOption),
@ -564,7 +567,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.displayLabelOption.triggered.connect(self.togglePaintLabelsOption)
addActions(self.menus.file,
(opendir, None, save, resetAll, deleteImg, quit))
(opendir, None, saveLabel, saveRec, None, resetAll, deleteImg, quit))
addActions(self.menus.help, (showSteps, showInfo))
addActions(self.menus.view, (
@ -574,7 +577,7 @@ class MainWindow(QMainWindow, WindowMixin):
zoomIn, zoomOut, zoomOrg, None,
fitWindow, fitWidth))
addActions(self.menus.autolabel, (alcm, saveRec, None, help)) #
addActions(self.menus.autolabel, (alcm, None, help)) #
self.menus.file.aboutToShow.connect(self.updateFileMenu)
@ -586,14 +589,14 @@ class MainWindow(QMainWindow, WindowMixin):
# self.tools = self.toolbar('Tools')
self.actions.beginner = (
open, opendir, openNextImg, openPrevImg, verify, save, None, create, copy, delete, None,
zoomIn, zoom, zoomOut, fitWindow, fitWidth)
self.actions.advanced = (
open, opendir, openNextImg, openPrevImg, save, None,
createMode, editMode, None,
hideAll, showAll)
# self.actions.beginner = (
# open, opendir, openNextImg, openPrevImg, verify, save, None, create, copy, delete, None,
# zoomIn, zoom, zoomOut, fitWindow, fitWidth)
#
# self.actions.advanced = (
# open, opendir, openNextImg, openPrevImg, save, None,
# createMode, editMode, None,
# hideAll, showAll)
self.statusBar().showMessage('%s started.' % __appname__)
self.statusBar().show()
@ -1400,8 +1403,7 @@ class MainWindow(QMainWindow, WindowMixin):
settings[SETTING_DRAW_SQUARE] = self.drawSquaresOption.isChecked()
settings.save()
try:
self.saveFilestate()
self.savePPlabel()
self.saveLabelFile()
except:
pass
@ -1446,8 +1448,7 @@ class MainWindow(QMainWindow, WindowMixin):
if not self.mayContinue() or not dirpath:
return
if self.defaultSaveDir and self.defaultSaveDir != dirpath:
self.saveFilestate()
self.savePPlabel()
self.saveLabelFile()
if not isDelete:
self.loadFilestate(dirpath)
@ -1488,6 +1489,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.haveAutoReced = False
self.AutoRecognition.setEnabled(True)
self.reRecogButton.setEnabled(True)
self.actions.saveLabel.setEnabled(True)
def verifyImg(self, _value=False):
# Proceding next image without dialog if having any label
@ -1967,6 +1969,10 @@ class MainWindow(QMainWindow, WindowMixin):
f.write(key + '\t')
f.write(json.dumps(self.Cachelabel[key], ensure_ascii=False) + '\n')
def saveLabelFile(self):
self.saveFilestate()
self.savePPlabel()
def saveRecResult(self):
if None in [self.PPlabelpath, self.PPlabel, self.fileStatedict]:
QMessageBox.information(self, "Information", "Save file first")
@ -2013,7 +2019,7 @@ def get_main_app(argv=[]):
app.setWindowIcon(newIcon("app"))
# Tzutalin 201705+: Accept extra agruments to change predefined class file
argparser = argparse.ArgumentParser()
argparser.add_argument("--lang", default='ch', nargs="?")
argparser.add_argument("--lang", default='en', nargs="?")
argparser.add_argument("--predefined_classes_file",
default=os.path.join(os.path.dirname(__file__), "data", "predefined_classes.txt"),
nargs="?")

View File

@ -12,13 +12,10 @@ PPOCRLabel是一款适用于OCR领域的半自动化图形标注工具使用p
### 2. 安装PPOCRLabel
#### Windows + Anaconda
下载安装[Anaconda](https://www.anaconda.com/download/#download) (Python 3+)
```
conda install pyqt=5
pip install pyqt5
cd ./PPOCRLabel # 将目录切换到PPOCRLabel文件夹下
pyrcc5 -o libs/resources.py resources.qrc
python PPOCRLabel.py
python PPOCRLabel.py --lang ch
```
#### Ubuntu Linux
@ -27,7 +24,7 @@ python PPOCRLabel.py
pip3 install pyqt5
pip3 install trash-cli
cd ./PPOCRLabel # 将目录切换到PPOCRLabel文件夹下
python3 PPOCRLabel.py
python3 PPOCRLabel.py --lang ch
```
#### macOS
@ -36,7 +33,7 @@ pip3 install pyqt5
pip3 uninstall opencv-python # 由于mac版本的opencv与pyqt有冲突需先手动卸载opencv
pip3 install opencv-contrib-python-headless # 安装headless版本的open-cv
cd ./PPOCRLabel # 将目录切换到PPOCRLabel文件夹下
python3 PPOCRLabel.py
python3 PPOCRLabel.py --lang ch
```
## 使用
@ -50,9 +47,9 @@ python3 PPOCRLabel.py
5. 标记框绘制完成后,用户点击 “确认”,检测框会先被预分配一个 “待识别” 标签。
6. 重新识别:将图片中的所有检测画绘制/调整完成后,点击 “重新识别”PPOCR模型会对当前图片中的**所有检测框**重新识别<sup>[3]</sup>
7. 内容更改:双击识别结果,对不准确的识别结果进行手动更改。
8. 确认结果:点击 “确认”,图片状态切换为 “√”,跳转至下一张。
8. 确认标记:点击 “确认”,图片状态切换为 “√”,跳转至下一张(此时不会直接将结果写入文件)
9. 删除:点击 “删除图像”,图片将会被删除至回收站。
10. 保存标注结果:关闭应用程序或切换文件路径后,手动确认过的标签将会被存放在所打开图片文件夹下的*Label.txt*中。在菜单栏点击 “PaddleOCR” - "保存识别结果"后,会将此类图片的识别训练数据保存在*crop_img*文件夹下,识别标签保存在*rec_gt.txt*中<sup>[4]</sup>
10. 保存结果:用户可以通过菜单中“文件-保存标记结果”手动保存同时程序也会在用户每确认10张图片后自动保存一次。手动确认过的标记将会被存放在所打开图片文件夹下的*Label.txt*中。在菜单栏点击 “文件” - "保存识别结果"后,会将此类图片的识别训练数据保存在*crop_img*文件夹下,识别标签保存在*rec_gt.txt*中<sup>[4]</sup>
### 注意
@ -62,14 +59,14 @@ python3 PPOCRLabel.py
[3] 点击“重新识别”后,模型会对图片中的识别结果进行覆盖。因此如果在此之前手动更改过识别结果,有可能在重新识别后产生变动。
[4] PPOCRLabel产生的文件均在标记图片的文件夹中,包括一下几种,请勿手动更改其中内容,否则会引起程序出现异常。
[4] PPOCRLabel产生的文件放置于标记图片文件夹下,包括一下几种,请勿手动更改其中内容,否则会引起程序出现异常。
| 文件名 | 说明 |
| :-----------: | :----------------------------------------------------------: |
| Label.txt | 检测标签可直接用于PPOCR检测模型训练。用户每保存10张检测结果后程序会进行自动写入。当用户关闭应用程序或切换文件路径后同样会进行写入。 |
| fileState.txt | 图片状态标记文件,保存当前文件夹下已经被用户手动确认过的图片名称。 |
| Cache.cach | 缓存文件,保存模型自动识别的结果。 |
| rec_gt.txt | 识别标签。可直接用于PPOCR识别模型训练。需用户手动点击菜单栏“PaddleOCR” - "保存识别结果"后产生。 |
| rec_gt.txt | 识别标签。可直接用于PPOCR识别模型训练。需用户手动点击菜单栏“文件” - "保存识别结果"后产生。 |
| crop_img | 识别数据。按照检测框切割后的图片。与rec_gt.txt同时产生。 |
## 说明
@ -94,6 +91,10 @@ python3 PPOCRLabel.py
```
pip install opencv-python==4.2.0.32
```
- 如果出现''Missing string id '开头的错误,需要重新编译资源:
```
pyrcc5 -o libs/resources.py resources.qrc
```
### 参考资料
1.[Tzutalin. LabelImg. Git code (2015)](https://github.com/tzutalin/labelImg)

View File

@ -2,7 +2,7 @@
PPOCRLabel is a semi-automatic graphic annotation tool suitable for OCR field. It is written in python3 and pyqt5, supporting rectangular box annotation and four-point annotation modes. Annotations can be directly used for the training of PPOCR detection and recognition models.
<img src="./data/gif/steps.gif" width="100%"/>
<img src="./data/gif/steps_en.gif" width="100%"/>
## Installation
@ -17,10 +17,9 @@ Refer to [PaddleOCR installation document](https://github.com/PaddlePaddle/Paddl
Download and install [Anaconda](https://www.anaconda.com/download/#download) (Python 3+)
```
conda install pyqt=5
pip install pyqt5
cd ./PPOCRLabel # Change the directory to the PPOCRLabel folder
pyrcc5 -o libs/resources.py resources.qrc
python PPOCRLabel.py --lang en
python PPOCRLabel.py
```
#### Ubuntu Linux
@ -29,7 +28,7 @@ python PPOCRLabel.py --lang en
pip3 install pyqt5
pip3 install trash-cli
cd ./PPOCRLabel # Change the directory to the PPOCRLabel folder
python3 PPOCRLabel.py --lang en
python3 PPOCRLabel.py
```
#### macOS
@ -38,7 +37,7 @@ 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
python3 PPOCRLabel.py --lang en
python3 PPOCRLabel.py
```
## Usage
@ -63,11 +62,11 @@ python3 PPOCRLabel.py --lang en
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.
8. Click "Check", the image status will switch to "√",then the program automatically jump to the next(The results will not be written directly to the file at this time).
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.
10. Labeling result: the user can save manually through the menu "File - Save Label", while the program will also save automatically after every 10 images confirmed by the user.the manually checked 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
@ -79,14 +78,14 @@ python3 PPOCRLabel.py --lang en
[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.
[4] The files produced by PPOCRLabel can be found under the opened picture folder including 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". |
| 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 "File"-"Save recognition result". |
| crop_img | The recognition data, generated at the same time with *rec_gt.txt* |
## Explanation
@ -115,7 +114,10 @@ For some data that are difficult to recognize, the recognition results will not
```
pip install opencv-python==4.2.0.32
```
- If you get an error starting with **Missing string id **,you need to recompile resources:
```
pyrcc5 -o libs/resources.py resources.qrc
```
### Related
1.[Tzutalin. LabelImg. Git code (2015)](https://github.com/tzutalin/labelImg)

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 MiB

View File

@ -45,7 +45,7 @@ class Worker(QThread):
chars = res[1][0]
cond = res[1][1]
posi = res[0]
self.listValue.emit("文字:" + chars + " 置信度:" + str(cond) + " 坐标:" + json.dumps(posi))
self.listValue.emit("Transcription: " + chars + " Probability: " + str(cond) + " Location: " + json.dumps(posi))
self.mainThread.result_dic = self.result_dic
self.mainThread.filePath = Imgpath
# 保存
@ -88,7 +88,7 @@ class AutoDialog(QDialog):
bb.button(BB.Ok).setEnabled(False)
self.setLayout(layout)
self.setWindowTitle("自动标注中")
# self.setWindowTitle("自动标注中")
self.setWindowModality(Qt.ApplicationModal)
# self.setWindowFlags(Qt.WindowCloseButtonHint)

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,6 @@
<file alias="resetall">resources/icons/resetall.png</file>
<file alias="verify">resources/icons/verify.png</file>
<file alias="strings">resources/strings/strings.properties</file>
<file alias="strings-zh-TW">resources/strings/strings-zh-TW.properties</file>
<file alias="strings-zh-CN">resources/strings/strings-zh-CN.properties</file>
</qresource>
</RCC>

View File

@ -27,7 +27,7 @@ boxLineColorDetail=选择线框颜色
originalsize=原始大小
resetAllDetail=重置所有设定
zoomoutDetail=放大画面
save=保存
save=确认
saveAs=另存为
fitWinDetail=缩放到当前窗口大小
openDir=打开目录
@ -93,4 +93,5 @@ cancel=取消
ok=确认
autolabeling=自动标注中
hideBox=隐藏所有标注
showBox=显示所有标注
showBox=显示所有标注
saveLabel=保存标记结果

View File

@ -14,7 +14,7 @@ prevImg=Prev Image
prevImgDetail=Open the previous Image
verifyImg=Verify Image
verifyImgDetail=Verify Image
save=Save
save=Check
saveDetail=Save the labels to a file
changeSaveFormat=Change save format
saveAs=Save As
@ -93,4 +93,5 @@ cancel=Cancel
ok=OK
autolabeling=Automatic Labeling
hideBox=Hide All Box
showBox=Show All Box
showBox=Show All Box
saveLabel=Save Label