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_MAJOR 5)
set(VERSION_MINOR 56) set(VERSION_MINOR 56)
set(VERSION_PATCH 4) set(VERSION_PATCH 5)
include(${CMAKE_CURRENT_LIST_DIR}/version/generate_product_version.cmake) 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 **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 --> <!-- tabs:end -->

View File

@ -25,8 +25,6 @@ class commonbase:
_setting_dict = None _setting_dict = None
typename = None typename = None
ocr_cant_auto = False
def langmap(self): def langmap(self):
return {} return {}
@ -37,8 +35,6 @@ class commonbase:
@property @property
def srclang(self): def srclang(self):
l = self.srclang_1 l = self.srclang_1
if self.ocr_cant_auto and (l == "auto"):
raise Exception(_TR("当前OCR引擎不支持设置语言为自动"))
return self.langmap_.get(l, l) return self.langmap_.get(l, l)
@property @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.utils import getlanguagespace
from myutils.commonbase import commonbase from myutils.commonbase import commonbase
@ -107,6 +107,11 @@ class baseocr(commonbase):
return lines return lines
######################################################## ########################################################
def raise_cant_be_auto_lang(self):
l = self.srclang_1
if l == "auto":
raise Exception(_TR("当前OCR引擎不支持设置语言为自动"))
def level2init(self): def level2init(self):
self.needinit = True self.needinit = True
try: try:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -812,5 +812,7 @@
"应用密钥": "Appliquer la clé", "应用密钥": "Appliquer la clé",
"无": "Aucun", "无": "Aucun",
"向上": "Vers le Haut", "向上": "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", "应用密钥": "Chiave dell'applicazione",
"无": "niente", "无": "niente",
"向上": "Su", "向上": "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", "应用密钥": "Toepassingssleutel",
"无": "niets", "无": "niets",
"向上": "Naar boven", "向上": "Naar boven",
"向下": "omlaag" "向下": "omlaag",
"无可用模型": "Geen beschikbare modellen",
"无可用语言": "Geen beschikbare talen"
} }

View File

@ -812,5 +812,7 @@
"应用密钥": "Klucz aplikacji", "应用密钥": "Klucz aplikacji",
"无": "nic", "无": "nic",
"向上": "W górę", "向上": "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", "应用密钥": "Chave da aplicação",
"无": "nada", "无": "nada",
"向上": "Subir", "向上": "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", "应用密钥": "Programnyckel",
"无": "ingenting", "无": "ingenting",
"向上": "Upp", "向上": "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ı", "应用密钥": "Uygulama anahtarı",
"无": "Hiçbir şey yok.", "无": "Hiçbir şey yok.",
"向上": "Yukarı", "向上": "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óa ứng dụng",
"无": "Không", "无": "Không",
"向上": "Lên trên", "向上": "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 @@
"应用密钥": "", "应用密钥": "",
"无": "", "无": "",
"向上": "", "向上": "",
"向下": "" "向下": "",
"无可用模型": "",
"无可用语言": ""
} }