Skip to content

Commit

Permalink
fix: ocr problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiramei committed Dec 21, 2023
1 parent 531e032 commit 81f7214
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 70 deletions.
4 changes: 2 additions & 2 deletions gui/components/expand/expandTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, configItems: Union[list[ConfigItem], list[dict]], parent=None
currentKey = cfg.key
inputComponent = ComboBox(self)
inputComponent.addItems(cfg.selection)
inputComponent.setCurrentIndex(int(self.get(currentKey)) - 1)
inputComponent.setCurrentIndex(cfg.selection.index(self.get(currentKey)))
inputComponent.currentIndexChanged.connect(
partial(self._commit, currentKey, inputComponent, labelComponent))
elif cfg.type == 'button':
Expand All @@ -61,7 +61,7 @@ def __init__(self, configItems: Union[list[ConfigItem], list[dict]], parent=None
currentKey = cfg.key
inputComponent = LineEdit(self)
confirmButton = PushButton('确定', self)
confirmButton.click.connect(partial(self._commit, currentKey, inputComponent, labelComponent))
confirmButton.clicked.connect(partial(self._commit, currentKey, inputComponent, labelComponent))
elif cfg.type == 'label':
inputComponent = QLabel(cfg.selection, self)
else:
Expand Down
105 changes: 40 additions & 65 deletions gui/components/expand/serverConfig.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,45 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout, QHBoxLayout
from qfluentwidgets import LineEdit, ComboBox, InfoBar, InfoBarIcon, InfoBarPosition
import cv2
from main import Main
from .expandTemplate import TemplateLayout

from gui.util.config_set import ConfigSet

def screenshot():
main = Main()
test_img = main.get_screenshot_array()
cv2.imshow('Test Screenshot', test_img)
cv2.waitKey(-1)

class Layout(QWidget, ConfigSet):
""" Folder item """

class Layout(TemplateLayout):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.info_widget = self.parent().parent().parent()
self.folderLabel = QLabel('请选择您的服务器', self)
self.serverLabel = QLabel('请填写您的adb端口号', self)
self.port_note = QLabel('常用端口:MuMu:7555;蓝叠/雷电:5555;夜神:62001或59865;', self)
self.port_note_ = QLabel('Mumu12:16384;逍遥:21503;多开请自行查询端口。', self)
server_type = ['官服', 'B服', '国际服']
self.portBox = LineEdit(self)
self.combo = ComboBox(self)
self.combo.addItems(server_type)
self.combo.setCurrentIndex(0)

self.portBox.setValidator(QIntValidator(0, 65535, self))
self.portBox.setText(self.get('adbPort'))
self.combo.setCurrentText(self.get('server'))

self.portBox.editingFinished.connect(self._save_port)
self.combo.currentTextChanged.connect(self._save_server)

self.vBoxLayout = QVBoxLayout(self)
self.vBoxLayout.setContentsMargins(48, 10, 60, 10)


self.lay1 = QHBoxLayout(self.vBoxLayout.widget())
self.note = QVBoxLayout(self.vBoxLayout.widget())
self.lay2 = QHBoxLayout(self.vBoxLayout.widget())

self.note.addWidget(self.port_note, 0, Qt.AlignLeft)
self.note.addWidget(self.port_note_, 0, Qt.AlignLeft)
self.note.setAlignment(Qt.AlignVCenter)

self.lay1.addWidget(self.folderLabel, 17, Qt.AlignLeft)
self.lay1.addWidget(self.combo, 0, Qt.AlignRight)
self.lay1.setAlignment(Qt.AlignVCenter)

self.lay2.addWidget(self.serverLabel, 17, Qt.AlignLeft)
self.lay2.addWidget(self.portBox, 0, Qt.AlignRight)
self.lay2.setAlignment(Qt.AlignVCenter)

self.vBoxLayout.addLayout(self.lay1)
self.vBoxLayout.addLayout(self.note)
self.vBoxLayout.addLayout(self.lay2)

def _save_port(self):
self.set('adbPort', self.portBox.text())
w = InfoBar(
icon=InfoBarIcon.SUCCESS,
title='设置成功',
content=f'你的端口号已经被设置为:{self.portBox.text()}',
orient=Qt.Vertical,
position=InfoBarPosition.TOP_RIGHT,
duration=800,
parent=self.info_widget
)
w.show()

def _save_server(self):
self.set('server', self.combo.currentText())
configItems = [
{
'label': '请选择您的服务器',
'type': 'combo',
'key': 'server',
'selection': ['官服', 'B服', '国际服']
},
{
'label': '常用端口号一览,请根据你的模拟器设置端口,多开请自行查询。',
'type': 'label'
},
{
'label': 'MuMu:7555;蓝叠/雷电:5555;夜神:62001或59865;',
'type': 'label'
},
{
'label': 'Mumu12:16384;逍遥:21503;',
'type': 'label'
},
{
'label': '请填写您的adb端口号',
'type': 'text',
'key': 'adbPort'
},
{
'label': '截图测试',
'type': 'button',
'selection': screenshot
}
]
super().__init__(parent=parent, configItems=configItems)
4 changes: 3 additions & 1 deletion gui/util/config_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@

class ConfigSet:
def __init__(self):
super().__init__()
self.config = None
self._init_config()

def _init_config(self):
with open('./config/config.json', 'r', encoding='utf-8') as f:
self.config = json.load(f)

def get(self, key):
self._init_config()
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
8 changes: 6 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,20 @@ 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(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',
rec_model_fp='src/ocr_models/en_number_mobile_v2.0_rec_infer.onnx',
det_model_fp='src/ocr_models/en_PP-OCRv3_rec_infer.onnx',
context='gpu')
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',
rec_model_name='number-densenet_lite_136-fc')
rec_model_name='number-densenet_lite_136-fc',
det_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/cn_densenet_lite_136.onnx
Binary file not shown.
Binary file added src/ocr_models/en_PP-OCRv3_rec_infer.onnx
Binary file not shown.
Binary file not shown.
Binary file added src/ocr_models/number-densenet_lite_136.onnx
Binary file not shown.

0 comments on commit 81f7214

Please sign in to comment.