This commit is contained in:
恍兮惚兮 2024-11-08 17:51:17 +08:00
parent e61ecabd16
commit 8782024408
28 changed files with 135 additions and 67 deletions

View File

@ -1,6 +1,6 @@
set(VERSION_MAJOR 5)
set(VERSION_MINOR 56)
set(VERSION_PATCH 4)
set(VERSION_PATCH 5)
include(${CMAKE_CURRENT_LIST_DIR}/version/generate_product_version.cmake)

View File

@ -176,7 +176,7 @@
**model** https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Fm2vrveyu
!> **API Key**请使用百度智能云IAM的Access Key、Secret Key来生成接口的BearerToken后作为**API Key**填入,或者按照`{Access Key}:{Secret Key}`的格式直接将两者一起填入**API Key**中。注意,而非千帆ModelBuilder的旧版v1版本接口的API Key、Secret Key两者不能通用。
!> **API Key**请使用百度智能云IAM的Access Key、Secret Key来生成接口的BearerToken后作为**API Key**填入,或者按照`{Access Key}:{Secret Key}`的格式直接将两者一起填入**API Key**中。注意,不是千帆ModelBuilder的旧版v1版本接口的API Key、Secret Key两者不能通用。
<!-- tabs:end -->

View File

@ -25,8 +25,6 @@ class commonbase:
_setting_dict = None
typename = None
ocr_cant_auto = False
def langmap(self):
return {}
@ -37,8 +35,6 @@ class commonbase:
@property
def srclang(self):
l = self.srclang_1
if self.ocr_cant_auto and (l == "auto"):
raise Exception(_TR("当前OCR引擎不支持设置语言为自动"))
return self.langmap_.get(l, l)
@property

View File

@ -1,4 +1,4 @@
from myutils.config import globalconfig, ocrsetting, ocrerrorfix
from myutils.config import globalconfig, ocrsetting, ocrerrorfix, _TR
from myutils.utils import getlanguagespace
from myutils.commonbase import commonbase
@ -107,6 +107,11 @@ class baseocr(commonbase):
return lines
########################################################
def raise_cant_be_auto_lang(self):
l = self.srclang_1
if l == "auto":
raise Exception(_TR("当前OCR引擎不支持设置语言为自动"))
def level2init(self):
self.needinit = True
try:

View File

@ -158,7 +158,6 @@ def question(dialog: QDialog):
class OCR(baseocr):
ocr_cant_auto = True
def langmap(self):
return {"cht": "cht"}
@ -168,31 +167,50 @@ class OCR(baseocr):
self._savelang = None
self.checkchange()
def checkchange(self):
if self._savelang == self.srclang:
return
self._ocr = None
path = "./files/ocr/{}".format(self.srclang)
if not (
def checklangvalid(self, langcode):
path = "./files/ocr/{}".format(langcode)
return (
os.path.exists(path + "/det.onnx")
and os.path.exists(path + "/rec.onnx")
and os.path.exists(path + "/dict.txt")
):
raise Exception(
_TR("未添加")
+ ' "'
+ _TR(getlang_inner2show(self.srclang))
+ '" '
+ _TR("的OCR模型")
+ "\n"
+ _TR("当前支持的语言")
+ ": "
+ ", ".join([_TR(getlang_inner2show(f)) for f in getallsupports()])
)
)
def checkchange(self):
if self._savelang == self.srclang:
return
if self.srclang == "auto":
validlangs = []
for lang in os.listdir("./files/ocr"):
if self.checklangvalid(lang):
validlangs.append(lang)
if len(validlangs) == 1:
uselang = validlangs[0]
elif len(validlangs) == 0:
raise Exception(_TR("无可用模型"))
else:
self.raise_cant_be_auto_lang()
else:
if self.checklangvalid(self.srclang):
uselang = self.srclang
else:
raise Exception(
_TR("未添加")
+ ' "'
+ _TR(getlang_inner2show(self.srclang))
+ '" '
+ _TR("的OCR模型")
+ "\n"
+ _TR("当前支持的语言")
+ ": "
+ ", ".join([_TR(getlang_inner2show(f)) for f in getallsupports()])
)
self._ocr = None
path = "./files/ocr/{}".format(uselang)
self._ocr = ocrwrapper(
path + "/det.onnx", path + "/rec.onnx", path + "/dict.txt"
)
self._savelang = self.srclang
self._savelang = uselang
def ocr(self, imagebinary):
self.checkchange()

View File

@ -3,7 +3,6 @@ from ocrengines.baseocrclass import baseocr
class OCR(baseocr):
ocr_cant_auto = True
def langmap(self):
return {
@ -19,6 +18,7 @@ class OCR(baseocr):
def ocr(self, imagebinary):
self.checkempty(["apikey"])
self.raise_cant_be_auto_lang()
apikey = self.config["apikey"]
if self.config["interface"] == 1:
base = "api.ocr.space"

View File

@ -48,7 +48,6 @@ def question(dialog: QDialog):
class OCR(baseocr):
ocr_cant_auto = True
def langmap(self):
return {"cht": "cht"}
@ -57,23 +56,35 @@ class OCR(baseocr):
self.supportmap = initsupports()
def ocr(self, imagebinary):
if self.srclang not in self.supportmap:
if len(self.supportmap) == 0:
_allsupport = initsupports()
idx = [_["code"] for _ in static_data["lang_list_all"]].index(self.srclang)
raise Exception(
_TR("系统未安装")
+ ' "'
+ _TR([_["zh"] for _ in static_data["lang_list_all"]][idx])
+ '" '
+ _TR("的OCR模型")
+ "\n"
+ _TR("当前支持的语言")
+ ": "
+ ", ".join([_TR(getlang_inner2show(f)) for f in _allsupport])
)
raise Exception(_TR("无可用语言"))
if self.srclang == "auto":
if len(self.supportmap) == 1:
uselang = list(self.supportmap.values())[0]
else:
self.raise_cant_be_auto_lang()
else:
if self.srclang not in self.supportmap:
ret = winrtutils.OCR_f(imagebinary, self.supportmap[self.srclang], self.space_1)
_allsupport = initsupports()
idx = [_["code"] for _ in static_data["lang_list_all"]].index(
self.srclang
)
raise Exception(
_TR("系统未安装")
+ ' "'
+ _TR([_["zh"] for _ in static_data["lang_list_all"]][idx])
+ '" '
+ _TR("的OCR模型")
+ "\n"
+ _TR("当前支持的语言")
+ ": "
+ ", ".join([_TR(getlang_inner2show(f)) for f in _allsupport])
)
else:
uselang = self.srclang
ret = winrtutils.OCR_f(imagebinary, self.supportmap[uselang], self.space_1)
boxs = [_[1:] for _ in ret]
texts = [_[0] for _ in ret]
return {"box": boxs, "text": texts}

View File

@ -11,11 +11,9 @@ import json
class OCR(baseocr):
ocr_cant_auto = True
def ocr(self, imagebinary):
self.checkempty(["APPId", "APISecret", "APIKey"])
self.raise_cant_be_auto_lang()
APPId = self.config["APPId"]
APISecret = self.config["APISecret"]
APIKey = self.config["APIKey"]

View File

@ -812,5 +812,7 @@
"应用密钥": "مفتاح التطبيق",
"无": "لا",
"向上": "صاعد",
"向下": "نزولا"
"向下": "نزولا",
"无可用模型": "لا يوجد نموذج المتاحة",
"无可用语言": "لا توجد لغة متاحة"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "應用金鑰",
"无": "無",
"向上": "向上",
"向下": "向下"
"向下": "向下",
"无可用模型": "無可用模型",
"无可用语言": "無可用語言"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Klíč aplikace",
"无": "nic",
"向上": "Nahoru",
"向下": "dolů"
"向下": "dolů",
"无可用模型": "Žádné dostupné modely",
"无可用语言": "Žádné dostupné jazyky"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Anwendungsschlüssel",
"无": "nichts",
"向上": "Nach oben",
"向下": "nach unten"
"向下": "nach unten",
"无可用模型": "Keine verfügbaren Modelle",
"无可用语言": "Keine verfügbaren Sprachen"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Application key",
"无": "nothing",
"向上": "Up",
"向下": "down"
"向下": "down",
"无可用模型": "No available models",
"无可用语言": "No available languages"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Clave de aplicación",
"无": "Ninguno",
"向上": "Arriba",
"向下": "Abajo"
"向下": "Abajo",
"无可用模型": "No hay modelos disponibles",
"无可用语言": "No hay idiomas disponibles"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Appliquer la clé",
"无": "Aucun",
"向上": "Vers le Haut",
"向下": "Vers le bas"
"向下": "Vers le bas",
"无可用模型": "Aucun modèle disponible",
"无可用语言": "Aucune langue disponible"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Chiave dell'applicazione",
"无": "niente",
"向上": "Su",
"向下": "giù"
"向下": "giù",
"无可用模型": "Nessun modello disponibile",
"无可用语言": "Nessuna lingua disponibile"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "キーの適用",
"无": "なし",
"向上": "上へ",
"向下": "下へ"
"向下": "下へ",
"无可用模型": "使用可能なモデルがありません",
"无可用语言": "使用可能な言語はありません"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "키 적용",
"无": "없음",
"向上": "상향",
"向下": "아래로"
"向下": "아래로",
"无可用模型": "사용 가능한 모델 없음",
"无可用语言": "사용 가능한 언어 없음"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Toepassingssleutel",
"无": "niets",
"向上": "Naar boven",
"向下": "omlaag"
"向下": "omlaag",
"无可用模型": "Geen beschikbare modellen",
"无可用语言": "Geen beschikbare talen"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Klucz aplikacji",
"无": "nic",
"向上": "W górę",
"向下": "w dół"
"向下": "w dół",
"无可用模型": "Brak dostępnych modeli",
"无可用语言": "Brak dostępnych języków"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Chave da aplicação",
"无": "nada",
"向上": "Subir",
"向下": "para baixo"
"向下": "para baixo",
"无可用模型": "Sem modelos disponíveis",
"无可用语言": "Sem línguas disponíveis"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Применить ключ",
"无": "Нет",
"向上": "Вверх",
"向下": "Вниз"
"向下": "Вниз",
"无可用模型": "Нет доступных моделей",
"无可用语言": "Нет доступных языков"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Programnyckel",
"无": "ingenting",
"向上": "Upp",
"向下": "ner"
"向下": "ner",
"无可用模型": "Inga tillgängliga modeller",
"无可用语言": "Inga tillgängliga språk"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "ใช้คีย์",
"无": "ไม่มี",
"向上": "ขึ้น",
"向下": "ลง"
"向下": "ลง",
"无可用模型": "ไม่มีรุ่น",
"无可用语言": "ไม่มีภาษา"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Uygulama anahtarı",
"无": "Hiçbir şey yok.",
"向上": "Yukarı",
"向下": "Aşağı"
"向下": "Aşağı",
"无可用模型": "Mevcut modeller yok",
"无可用语言": "Mevcut diller yok"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Ключ програми",
"无": "нічого",
"向上": "Вгору",
"向下": "вниз"
"向下": "вниз",
"无可用模型": "Немає доступних моделей",
"无可用语言": "Немає доступних мов"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "Khóa ứng dụng",
"无": "Không",
"向上": "Lên trên",
"向下": "Xuống"
"向下": "Xuống",
"无可用模型": "Không có mẫu",
"无可用语言": "Không có ngôn ngữ"
}

View File

@ -812,5 +812,7 @@
"应用密钥": "",
"无": "",
"向上": "",
"向下": ""
"向下": "",
"无可用模型": "",
"无可用语言": ""
}