mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 12:26:26 +00:00
refactor: TabOcr_B30
This commit is contained in:
28
ui/extends/ocr/dependencies.py
Normal file
28
ui/extends/ocr/dependencies.py
Normal file
@ -0,0 +1,28 @@
|
||||
import cv2
|
||||
from arcaea_offline_ocr.phash_db import ImagePhashDatabase
|
||||
|
||||
|
||||
def getCv2StatModelStatusText(model: cv2.ml.StatModel):
|
||||
if not isinstance(model, cv2.ml.StatModel):
|
||||
return '<font color="red">ERROR</font>'
|
||||
|
||||
varCount = model.getVarCount()
|
||||
if varCount != 81:
|
||||
return f'<font color="darkorange">WARN</font>, varCount {varCount}'
|
||||
else:
|
||||
return f'<font color="green">OK</font>, varCount {varCount}'
|
||||
|
||||
|
||||
def getPhashDatabaseStatusText(db: ImagePhashDatabase):
|
||||
if not isinstance(db, ImagePhashDatabase):
|
||||
return '<font color="red">ERROR</font>'
|
||||
|
||||
jacketCount = len(db.jacket_hashes)
|
||||
partnerIconCount = len(db.partner_icon_hashes)
|
||||
|
||||
statusText = f"J{jacketCount} PI{partnerIconCount}"
|
||||
|
||||
if partnerIconCount <= 0:
|
||||
return f'<font color="darkorange">WARN</font>, {statusText}'
|
||||
else:
|
||||
return f'<font color="green">OK</font>, {statusText}'
|
@ -1,28 +0,0 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
from PySide6.QtGui import QImage
|
||||
|
||||
|
||||
def cv2BgrMatToQImage(mat) -> QImage:
|
||||
arr = np.ascontiguousarray(mat)
|
||||
return QImage(
|
||||
arr.data,
|
||||
arr.shape[1],
|
||||
arr.shape[0],
|
||||
arr.strides[0],
|
||||
QImage.Format.Format_RGB888,
|
||||
).rgbSwapped()
|
||||
|
||||
|
||||
def qImageToCvMatBgr(qImg: QImage):
|
||||
# from Bing AI, references
|
||||
# 1: https://stackoverflow.com/q/384759/16484891 | CC BY-SA 4.0
|
||||
# 2: https://stackoverflow.com/q/37552924/16484891 | CC BY-SA 3.0
|
||||
qImg = qImg.convertToFormat(QImage.Format.Format_RGB888)
|
||||
qImg = qImg.copy().rgbSwapped()
|
||||
return np.ndarray(
|
||||
(qImg.height(), qImg.width(), 3),
|
||||
buffer=qImg.constBits(),
|
||||
strides=[qImg.bytesPerLine(), 3, 1],
|
||||
dtype=np.uint8,
|
||||
)
|
Reference in New Issue
Block a user