wip: b30 ocr tab

This commit is contained in:
2023-08-19 01:21:23 +08:00
parent 9eab7ffc63
commit 38a08a4b17
20 changed files with 726 additions and 97 deletions

View File

@ -0,0 +1,51 @@
import logging
from arcaea_offline.database import Database
from arcaea_offline.models import Chart, ScoreInsert
from arcaea_offline_ocr.b30.chieri.v4.ocr import ChieriBotV4Ocr
from arcaea_offline_ocr.b30.shared import B30OcrResultItem
from PySide6.QtGui import QImage
logger = logging.getLogger(__name__)
from ui.extends.components.ocrQueue import OcrRunnable
class ChieriV4OcrRunnable(OcrRunnable):
def __init__(self, ocr: ChieriBotV4Ocr, component):
super().__init__()
self.ocr = ocr
self.component = component.copy()
def run(self):
try:
result = self.ocr.ocr_component(self.component)
self.signals.resultReady.emit(result)
except Exception:
logger.exception("ChieriV4 ocr component error")
finally:
self.signals.finished.emit()
def b30ResultToScoreInsert(_, qImage: QImage, result: B30OcrResultItem):
if not result.song_id and not result.title:
raise ValueError("no title or song_id")
db = Database()
if not result.song_id:
song_id = db.fuzzy_search_song_id(result.title)[0][0]
else:
song_id = result.song_id
chart = Chart.from_db_row(db.get_chart(song_id, result.rating_class))
score = ScoreInsert(
song_id=song_id,
rating_class=result.rating_class,
score=result.score,
time=1485014400,
pure=result.pure,
far=result.far,
lost=result.lost,
)
return (chart, score)

View File

@ -3,7 +3,7 @@ import logging
from typing import Tuple
from arcaea_offline.database import Database
from arcaea_offline.models import ScoreInsert, Chart
from arcaea_offline.models import Chart, ScoreInsert
from arcaea_offline_ocr.device.shared import DeviceOcrResult
from arcaea_offline_ocr.device.v2.ocr import DeviceV2Ocr
from arcaea_offline_ocr.device.v2.rois import DeviceV2Rois
@ -52,7 +52,9 @@ def getImageDate(imagePath: str) -> QDateTime:
class ScoreInsertConverter:
@staticmethod
def deviceV2(imagePath: str, result: DeviceOcrResult) -> Tuple[Chart, ScoreInsert]:
def deviceV2(
imagePath: str, _, result: DeviceOcrResult
) -> Tuple[Chart, ScoreInsert]:
db = Database()
scoreInsert = ScoreInsert(
song_id=result.song_id,