Skip to content

Commit

Permalink
fix ocr
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiramei committed Dec 22, 2023
1 parent f64924e commit 8ab2038
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 49 deletions.
116 changes: 77 additions & 39 deletions gui/components/expand/arenaShopPriority.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,84 @@
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton
from qfluentwidgets import FlowLayout, CheckBox, LineEdit
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout
from qfluentwidgets import ComboBox

from gui.util.config_set import ConfigSet


class Layout(QWidget, ConfigSet):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setFixedHeight(120)

self.goods = self.get(key='TacticalChallengeShopList')

layout = FlowLayout(self, needAni=True)
layout.setContentsMargins(30, 30, 30, 30)
layout.setVerticalSpacing(20)
layout.setHorizontalSpacing(10)

self.setFixedSize(720, 200)
self.setStyleSheet('Demo{background: white} QPushButton{padding: 5px 10px; font:15px "Microsoft YaHei"}')
self.label = QLabel('刷新次数', self)
self.input = LineEdit(self)
self.input.setValidator(QIntValidator(0, 5))
self.input.setText(self.get('TacticalChallengeShopRefreshTime'))
self.accept = QPushButton('确定', self)
self.boxes = []
for i in range(13):
t_cbx = CheckBox(self)
t_cbx.setChecked(self.goods[i] == 1)
ccs = QLabel(f"商品{i + 1}", self)
ccs.setFixedWidth(80)
layout.addWidget(ccs)
layout.addWidget(t_cbx)
t_cbx.stateChanged.connect(lambda x, index=i: self.alter_status(index))
self.boxes.append(t_cbx)
layout.addWidget(self.label)
layout.addWidget(self.input)
layout.addWidget(self.accept)
self.accept.clicked.connect(self.__accept)
def alter_status(self, index):
self.boxes[index].setChecked(self.boxes[index].isChecked())
self.set(key='TacticalChallengeShopList', value=[1 if self.boxes[i].isChecked() else 0 for i in range(13)])

def __accept(self, input_content=None):
self.set('TacticalChallengeShopRefreshTime', self.input.text())

self.hBoxLayout = QVBoxLayout(self)

self.lay1 = QHBoxLayout(self)

self.option_1 = QHBoxLayout(self)
self.option_2 = QHBoxLayout(self)
self.option_3 = QHBoxLayout(self)

self.label_1_0 = QLabel('高架公路', self)
self.label_2_0 = QLabel('沙漠铁路', self)
self.label_3_0 = QLabel('讲堂', self)

self.input_1_2 = ComboBox(self)
self.input_2_2 = ComboBox(self)
self.input_3_2 = ComboBox(self)

selection = [str(i) for i in range(1, 13)]

self.input_1_2.addItems(selection)
self.input_2_2.addItems(selection)
self.input_3_2.addItems(selection)

self.option_1.addWidget(self.label_1_0, 0, Qt.AlignLeft)
self.option_1.addStretch(1)
self.option_1.addWidget(self.input_1_2, 0, Qt.AlignRight)

self.option_2.addWidget(self.label_2_0, 0, Qt.AlignLeft)
self.option_2.addStretch(1)
self.option_2.addWidget(self.input_2_2, 0, Qt.AlignRight)

self.option_3.addWidget(self.label_3_0, 0, Qt.AlignLeft)
self.option_3.addStretch(1)
self.option_3.addWidget(self.input_3_2, 0, Qt.AlignRight)

self.label = QLabel('请在下拉框中选择相应悬赏委托的次数:', self)

_set_main = self.get('rewarded_task_times')
self.count = [int(x) for x in _set_main.split(',')]

self.input_1_2.setCurrentIndex(self.count[0] - 1)
self.input_2_2.setCurrentIndex(self.count[1] - 1)
self.input_3_2.setCurrentIndex(self.count[2] - 1)

self.input_1_2.currentIndexChanged.connect(self._commit)
self.input_2_2.currentIndexChanged.connect(self._commit)
self.input_3_2.currentIndexChanged.connect(self._commit)

self.setFixedHeight(200)

self.lay1.setContentsMargins(10, 0, 0, 10)
self.option_1.setContentsMargins(10, 0, 0, 10)
self.option_2.setContentsMargins(10, 0, 0, 10)
self.option_3.setContentsMargins(10, 0, 0, 10)

self.lay1.addWidget(self.label, 0, Qt.AlignLeft)

self.lay1.addStretch(1)
self.lay1.setAlignment(Qt.AlignCenter)

self.hBoxLayout.addSpacing(16)
self.hBoxLayout.setAlignment(Qt.AlignCenter)

self.hBoxLayout.addLayout(self.lay1)
self.hBoxLayout.addLayout(self.option_1)
self.hBoxLayout.addLayout(self.option_2)
self.hBoxLayout.addLayout(self.option_3)

def _commit(self):
self.count[0] = self.input_1_2.currentIndex() + 1
self.count[1] = self.input_2_2.currentIndex() + 1
self.count[2] = self.input_3_2.currentIndex() + 1
_formatted = ','.join([str(self.count[i]) for i in range(0, 3)])
self.set('rewarded_task_times', _formatted)
5 changes: 5 additions & 0 deletions gui/components/expand/expandTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ def __init__(self, configItems: Union[list[ConfigItem], list[dict]], parent=None
currentKey = cfg.key
inputComponent = SwitchButton(self)
inputComponent.setChecked(self.get(currentKey))
inputComponent.setChecked(self._get(currentKey))
inputComponent.checkedChanged.connect(partial(self._commit, currentKey, inputComponent, labelComponent))
elif cfg.type == 'combo':
currentKey = cfg.key
inputComponent = ComboBox(self)
inputComponent.addItems(cfg.selection)
inputComponent.setCurrentIndex(cfg.selection.index(self.get(currentKey)))
inputComponent.setCurrentIndex(cfg.selection.index(self._get(currentKey)))
inputComponent.currentIndexChanged.connect(
partial(self._commit, currentKey, inputComponent, labelComponent))
elif cfg.type == 'button':
Expand Down Expand Up @@ -92,3 +94,6 @@ def _commit(self, key, target, labelTarget):
.parent().parent().parent().parent().parent()
)
infoChanged.show()

def _get(self, key):
return self.get(key)
11 changes: 7 additions & 4 deletions gui/components/expand/specialDaily.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class Layout(QWidget, ConfigSet):
def __init__(self, parent=None):
super().__init__(parent=parent)

self.hBoxLayout = QVBoxLayout(self)

self.lay1 = QHBoxLayout(self)
Expand All @@ -24,9 +25,11 @@ def __init__(self, parent=None):
self.input_2_2 = ComboBox(self)
self.input_3_2 = ComboBox(self)

self.input_1_2.addItems(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
self.input_2_2.addItems(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
self.input_3_2.addItems(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
selection = [str(i) for i in range(1, 13)]

self.input_1_2.addItems(selection)
self.input_2_2.addItems(selection)
self.input_3_2.addItems(selection)

self.option_1.addWidget(self.label_1_0, 0, Qt.AlignLeft)
self.option_1.addStretch(1)
Expand Down Expand Up @@ -78,4 +81,4 @@ def _commit(self):
self.count[1] = self.input_2_2.currentIndex() + 1
self.count[2] = self.input_3_2.currentIndex() + 1
_formatted = ','.join([str(self.count[i]) for i in range(0, 3)])
self.set('specialPriority', _formatted)
self.set('rewarded_task_times', _formatted)
1 change: 0 additions & 1 deletion gui/util/config_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def get(self, key):
return self.config.get(key)

def set(self, key, value):
self._init_config()
self._init_config()
self.config[key] = value
with open('./config/config.json', 'w', encoding='utf-8') as f:
Expand Down
16 changes: 11 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,18 +453,24 @@ def init_ocr(self):
try:
self.logger.info("Start initializing OCR")
if self.server == 'CN':
self.ocrCN = CnOcr(rec_model_name='densenet_lite_114-fc',
self.ocrCN = CnOcr(det_model_name='ch_PP-OCRv3_det',
det_model_fp='src/ocr_models/ch_PP-OCRv3_det_infer.onnx',
rec_model_name='densenet_lite_114-fc',
rec_model_fp='src/ocr_models/cn_densenet_lite_136.onnx')
img_CN = cv2.imread('src/test_ocr/CN.png')
self.logger.info("Test ocrCN : " + self.ocrCN.ocr_for_single_line(img_CN)['text'])
elif self.server == 'Global':
self.ocrEN = CnOcr(det_model_name="en_PP-OCRv3_det", rec_model_name='en_number_mobile_v2.0',
context='gpu')
self.ocrEN = CnOcr(det_model_name="en_PP-OCRv3_det",
det_model_fp='src/ocr_models/en_PP-OCRv3_det_infer.onnx',
rec_model_name='en_number_mobile_v2.0',
rec_model_fp='src/ocr_models/en_number_mobile_v2.0_rec_infer.onnx',)
img_EN = cv2.imread('src/test_ocr/EN.png')
self.logger.info("Test ocrEN : " + self.ocrEN.ocr_for_single_line(img_EN)['text'])
self.ocrNUM = CnOcr(det_model_name='number-densenet_lite_136-fc',
self.ocrNUM = CnOcr(det_model_name='en_PP-OCRv3_det',
det_model_fp='src/ocr_models/en_PP-OCRv3_det_infer.onnx',
rec_model_name='number-densenet_lite_136-fc',
det_model_fp='src/ocr_models/number-densenet_lite_136.onnx')
rec_model_fp='src/ocr_models/number-densenet_lite_136.onnx')

img_NUM = cv2.imread('src/test_ocr/NUM.png')
self.logger.info("Test ocrNUM : " + self.ocrNUM.ocr_for_single_line(img_NUM)['text'])
self.logger.info("OCR initialization concluded")
Expand Down
Binary file added src/ocr_models/ch_PP-OCRv3_det_infer.onnx
Binary file not shown.
Binary file added src/ocr_models/en_PP-OCRv3_det_infer.onnx
Binary file not shown.

0 comments on commit 8ab2038

Please sign in to comment.