wip: DeviceV2AutoRois support

This commit is contained in:
283375 2023-09-01 04:02:58 +08:00
parent e1bc52a3ae
commit 93bea4b88a
3 changed files with 52 additions and 15 deletions

View File

@ -27,6 +27,13 @@
<string>deviceSelector.title</string> <string>deviceSelector.title</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="deviceUseAutoFactorCheckBox">
<property name="text">
<string>deviceSelector.useAutoFactor</string>
</property>
</widget>
</item>
<item> <item>
<widget class="FileSelector" name="deviceFileSelector" native="true"/> <widget class="FileSelector" name="deviceFileSelector" native="true"/>
</item> </item>

View File

@ -3,7 +3,7 @@
################################################################################ ################################################################################
## Form generated from reading UI file 'tabOcr_Device.ui' ## Form generated from reading UI file 'tabOcr_Device.ui'
## ##
## Created by: Qt User Interface Compiler version 6.5.1 ## Created by: Qt User Interface Compiler version 6.5.2
## ##
## WARNING! All changes made in this file will be lost when recompiling UI file! ## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################ ################################################################################
@ -15,8 +15,9 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon, QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter, QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform) QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QGroupBox, QHBoxLayout, QPushButton, from PySide6.QtWidgets import (QApplication, QCheckBox, QGroupBox, QHBoxLayout,
QSizePolicy, QStackedWidget, QVBoxLayout, QWidget) QPushButton, QSizePolicy, QStackedWidget, QVBoxLayout,
QWidget)
from ui.implements.components.devicesComboBox import DevicesComboBox from ui.implements.components.devicesComboBox import DevicesComboBox
from ui.implements.components.fileSelector import FileSelector from ui.implements.components.fileSelector import FileSelector
@ -39,6 +40,11 @@ class Ui_TabOcr_Device(object):
self.groupBox.setObjectName(u"groupBox") self.groupBox.setObjectName(u"groupBox")
self.verticalLayout = QVBoxLayout(self.groupBox) self.verticalLayout = QVBoxLayout(self.groupBox)
self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setObjectName(u"verticalLayout")
self.deviceUseAutoFactorCheckBox = QCheckBox(self.groupBox)
self.deviceUseAutoFactorCheckBox.setObjectName(u"deviceUseAutoFactorCheckBox")
self.verticalLayout.addWidget(self.deviceUseAutoFactorCheckBox)
self.deviceFileSelector = FileSelector(self.groupBox) self.deviceFileSelector = FileSelector(self.groupBox)
self.deviceFileSelector.setObjectName(u"deviceFileSelector") self.deviceFileSelector.setObjectName(u"deviceFileSelector")
@ -140,6 +146,7 @@ class Ui_TabOcr_Device(object):
def retranslateUi(self, TabOcr_Device): def retranslateUi(self, TabOcr_Device):
self.openWizardButton.setText(QCoreApplication.translate("TabOcr_Device", u"openWizardButton", None)) self.openWizardButton.setText(QCoreApplication.translate("TabOcr_Device", u"openWizardButton", None))
self.groupBox.setTitle(QCoreApplication.translate("TabOcr_Device", u"deviceSelector.title", None)) self.groupBox.setTitle(QCoreApplication.translate("TabOcr_Device", u"deviceSelector.title", None))
self.deviceUseAutoFactorCheckBox.setText(QCoreApplication.translate("TabOcr_Device", u"deviceSelector.useAutoFactor", None))
self.groupBox_6.setTitle(QCoreApplication.translate("TabOcr_Device", u"knnModelSelector.title", None)) self.groupBox_6.setTitle(QCoreApplication.translate("TabOcr_Device", u"knnModelSelector.title", None))
self.groupBox_4.setTitle(QCoreApplication.translate("TabOcr_Device", u"tesseractSelector.title", None)) self.groupBox_4.setTitle(QCoreApplication.translate("TabOcr_Device", u"tesseractSelector.title", None))
self.groupBox_5.setTitle(QCoreApplication.translate("TabOcr_Device", u"siftDatabaseSelector.title", None)) self.groupBox_5.setTitle(QCoreApplication.translate("TabOcr_Device", u"siftDatabaseSelector.title", None))

View File

@ -6,13 +6,17 @@ import cv2
from arcaea_offline_ocr.device.v1.definition import DeviceV1 from arcaea_offline_ocr.device.v1.definition import DeviceV1
from arcaea_offline_ocr.device.v2.definition import DeviceV2 from arcaea_offline_ocr.device.v2.definition import DeviceV2
from arcaea_offline_ocr.sift_db import SIFTDatabase from arcaea_offline_ocr.sift_db import SIFTDatabase
from PySide6.QtCore import Slot from PySide6.QtCore import Qt, Slot
from PySide6.QtWidgets import QFileDialog, QWidget from PySide6.QtWidgets import QFileDialog, QWidget
from ui.designer.tabs.tabOcr.tabOcr_Device_ui import Ui_TabOcr_Device from ui.designer.tabs.tabOcr.tabOcr_Device_ui import Ui_TabOcr_Device
from ui.extends.components.ocrQueue import OcrQueueModel from ui.extends.components.ocrQueue import OcrQueueModel
from ui.extends.shared.settings import Settings from ui.extends.shared.settings import Settings
from ui.extends.tabs.tabOcr.tabOcr_Device import ScoreConverter, TabDeviceV2OcrRunnable from ui.extends.tabs.tabOcr.tabOcr_Device import (
ScoreConverter,
TabDeviceV2AutoRoisOcrRunnable,
TabDeviceV2OcrRunnable,
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -23,10 +27,6 @@ class TabOcr_Device(Ui_TabOcr_Device, QWidget):
self.setupUi(self) self.setupUi(self)
self.openWizardButton.setEnabled(False) self.openWizardButton.setEnabled(False)
self.deviceComboBox.currentIndexChanged.connect(
self.changeDeviceDepStackedWidget
)
self.deviceFileSelector.filesSelected.connect(self.deviceFileSelected) self.deviceFileSelector.filesSelected.connect(self.deviceFileSelected)
self.knnModelSelector.filesSelected.connect(self.knnModelFileSelected) self.knnModelSelector.filesSelected.connect(self.knnModelFileSelected)
self.tesseractFileSelector.filesSelected.connect( self.tesseractFileSelector.filesSelected.connect(
@ -52,6 +52,22 @@ class TabOcr_Device(Ui_TabOcr_Device, QWidget):
# wizard.open() # wizard.open()
pass pass
@Slot()
def on_deviceUseAutoFactorCheckBox_stateChanged(self):
checkState = self.deviceUseAutoFactorCheckBox.checkState()
if checkState == Qt.CheckState.Checked:
self.deviceDependenciesStackedWidget.setCurrentIndex(1)
self.deviceComboBox.setCurrentIndex(-1)
self.deviceFileSelector.setEnabled(False)
self.deviceComboBox.setEnabled(False)
else:
self.deviceFileSelector.setEnabled(True)
self.deviceComboBox.setEnabled(True)
@Slot()
def on_deviceComboBox_currentIndexChanged(self):
self.changeDeviceDepStackedWidget()
def changeDeviceDepStackedWidget(self): def changeDeviceDepStackedWidget(self):
device = self.deviceComboBox.currentData() device = self.deviceComboBox.currentData()
if isinstance(device, (DeviceV1, DeviceV2)): if isinstance(device, (DeviceV1, DeviceV2)):
@ -92,6 +108,13 @@ class TabOcr_Device(Ui_TabOcr_Device, QWidget):
for row in range(self.ocrQueueModel.rowCount()): for row in range(self.ocrQueueModel.rowCount()):
index = self.ocrQueueModel.index(row, 0) index = self.ocrQueueModel.index(row, 0)
imagePath = index.data(OcrQueueModel.ImagePathRole) imagePath = index.data(OcrQueueModel.ImagePathRole)
if self.deviceUseAutoFactorCheckBox.checkState() == Qt.CheckState.Checked:
runnable = TabDeviceV2AutoRoisOcrRunnable(
imagePath,
self.knnModel,
self.siftDatabase,
)
else:
runnable = TabDeviceV2OcrRunnable( runnable = TabDeviceV2OcrRunnable(
imagePath, imagePath,
self.deviceComboBox.currentData(), self.deviceComboBox.currentData(),