revert: 回滚charOCR

This commit is contained in:
MistEO
2022-12-12 23:33:02 +08:00
parent accddb04bf
commit cf1ce8dc22
13 changed files with 9298 additions and 9140 deletions

View File

@@ -0,0 +1 @@
en_PP-OCRv3_det_infer

View File

@@ -0,0 +1,95 @@
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/

View File

@@ -0,0 +1 @@
en_PP-OCRv3_rec_infer

File diff suppressed because it is too large Load Diff

View File

@@ -372,6 +372,7 @@ namespace asst
OcrTaskInfo& operator=(OcrTaskInfo&&) noexcept = default;
std::vector<std::string> text; // 文字的容器,匹配到这里面任一个,就算匹配上了
bool full_match = false; // 是否需要全匹配,否则搜索到子串就算匹配上了
bool is_ascii = false; // 是否启用字符数字模型
bool without_det = false; // 是否不使用检测模型
std::unordered_map<std::string, std::string>
replace_map; // 部分文字容易识别错字符串强制replace之后再进行匹配

View File

@@ -53,4 +53,9 @@ namespace asst
{
friend class SingletonHolder<WordOcr>;
};
class CharOcr final : public SingletonHolder<CharOcr>, public OcrPack
{
friend class SingletonHolder<CharOcr>;
};
}

View File

@@ -65,7 +65,7 @@ bool asst::ResourceLoader::load(const std::filesystem::path& path)
/* load 3rd parties resource */
LoadResourceAndCheckRet(TilePack, "Arknights-Tile-Pos"_p / "levels.json"_p);
LoadResourceAndCheckRet(WordOcr, "PaddleOCR"_p);
// LoadResourceAndCheckRet(CharOcr, "PaddleCharOCR"_p);
LoadResourceAndCheckRet(CharOcr, "PaddleCharOCR"_p);
m_loaded = true;

View File

@@ -395,6 +395,7 @@ asst::TaskData::taskptr_t asst::TaskData::generate_ocr_task_info([[maybe_unused]
#endif
ocr_task_info_ptr->full_match = task_json.get("fullMatch", default_ptr->full_match);
ocr_task_info_ptr->is_ascii = task_json.get("isAscii", default_ptr->is_ascii);
ocr_task_info_ptr->without_det = task_json.get("withoutDet", default_ptr->without_det);
if (auto opt = task_json.find<json::array>("ocrReplace")) {
for (const json::value& rep : opt.value()) {
@@ -533,6 +534,7 @@ std::shared_ptr<asst::OcrTaskInfo> asst::TaskData::_default_ocr_task_info()
{
auto ocr_task_info_ptr = std::make_shared<OcrTaskInfo>();
ocr_task_info_ptr->full_match = false;
ocr_task_info_ptr->is_ascii = false;
ocr_task_info_ptr->without_det = false;
return ocr_task_info_ptr;

View File

@@ -1,9 +1,9 @@
#include "DrGrandetTaskPlugin.h"
#include "Config/TaskData.h"
#include "Controller.h"
#include "Utils/Logger.hpp"
#include "Vision/OcrImageAnalyzer.h"
#include "Config/TaskData.h"
#include "Utils/Logger.hpp"
#include <regex>
@@ -52,6 +52,8 @@ int asst::DrGrandetTaskPlugin::analyze_time_left()
OcrImageAnalyzer analyzer(ctrler()->get_image());
analyzer.set_task_info("DrGrandetUseOriginiums");
analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
// 这里是汉字和数字混合的用不了单独的en模型
analyzer.set_use_char_model(false);
if (!analyzer.analyze()) {
return -1;
@@ -72,4 +74,4 @@ int asst::DrGrandetTaskPlugin::analyze_time_left()
Log.info("Time left ms:", millisec);
return millisec;
}
}

View File

@@ -60,17 +60,15 @@ bool asst::OcrImageAnalyzer::analyze()
m_roi = correct_rect(m_roi, m_image);
// OcrPack* ocr_ptr = nullptr;
// if (m_use_char_model) {
// ocr_ptr = &CharOcr::get_instance();
// }
// else {
// ocr_ptr = &WordOcr::get_instance();
// }
// m_ocr_result = ocr_ptr->recognize(m_image, m_roi, all_pred, m_without_det);
// ocr_ptr = nullptr;
m_ocr_result = WordOcr::get_instance().recognize(m_image, m_roi, all_pred, m_without_det);
OcrPack* ocr_ptr = nullptr;
if (m_use_char_model) {
ocr_ptr = &CharOcr::get_instance();
}
else {
ocr_ptr = &WordOcr::get_instance();
}
m_ocr_result = ocr_ptr->recognize(m_image, m_roi, all_pred, m_without_det);
ocr_ptr = nullptr;
// log.trace("ocr result", m_ocr_result);
return !m_ocr_result.empty();
@@ -109,6 +107,7 @@ void asst::OcrImageAnalyzer::set_task_info(OcrTaskInfo task_info) noexcept
m_full_match = task_info.full_match;
m_replace = std::move(task_info.replace_map);
m_use_cache = task_info.cache;
m_use_char_model = task_info.is_ascii;
if (m_use_cache && !m_region_of_appeared.empty()) {
m_roi = m_region_of_appeared;
@@ -144,6 +143,11 @@ void asst::OcrImageAnalyzer::set_region_of_appeared(Rect region) noexcept
}
}
void asst::OcrImageAnalyzer::set_use_char_model(bool enable) noexcept
{
m_use_char_model = enable;
}
void asst::OcrImageAnalyzer::set_pred(const TextRectProc& pred)
{
m_pred = pred;

View File

@@ -32,6 +32,7 @@ namespace asst
virtual void set_use_cache(bool is_use) noexcept;
virtual void set_region_of_appeared(Rect region) noexcept;
virtual void set_use_char_model(bool enable) noexcept;
void set_pred(const TextRectProc& pred);
virtual const std::vector<TextRect>& get_result() const noexcept;
@@ -48,5 +49,6 @@ namespace asst
bool m_without_det = false;
bool m_use_cache = false;
Rect m_region_of_appeared;
bool m_use_char_model = false;
};
}

View File

@@ -191,7 +191,11 @@ bool asst::StageDropsImageAnalyzer::analyze_drops()
}
std::string item = match_item(item_roi, drop_type, size - i, size);
int quantity = match_quantity(item_roi);
bool use_word_model = item == LMD_ID;
int quantity = match_quantity(item_roi, use_word_model);
if (use_word_model && quantity == 0) {
quantity = match_quantity(item_roi, false);
}
Log.info("Item id:", item, ", quantity:", quantity);
#ifdef ASST_DEBUG
cv::rectangle(m_image_draw, make_rect<cv::Rect>(item_roi), cv::Scalar(0, 0, 255), 2);
@@ -458,7 +462,7 @@ std::string asst::StageDropsImageAnalyzer::match_item(const Rect& roi, StageDrop
return result;
}
int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi)
int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi, bool use_word_model)
{
auto task_ptr = Task.get<MatchTaskInfo>("StageDrops-Quantity");
@@ -518,6 +522,7 @@ int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi)
analyzer.set_roi(Rect(quantity_roi.x + far_left, quantity_roi.y, far_right - far_left, quantity_roi.height));
analyzer.set_expansion(1);
analyzer.set_threshold(task_ptr->mask_range.first, task_ptr->mask_range.second);
analyzer.set_use_char_model(!use_word_model);
if (!analyzer.analyze()) {
return 0;
@@ -527,8 +532,14 @@ int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi)
#ifdef ASST_DEBUG
cv::rectangle(m_image_draw, make_rect<cv::Rect>(result.rect), cv::Scalar(0, 0, 255));
cv::putText(m_image_draw, result.text, cv::Point(result.rect.x, result.rect.y - 5), cv::FONT_HERSHEY_SIMPLEX, 0.5,
cv::Scalar(0, 255, 0), 2);
if (use_word_model) {
cv::putText(m_image_draw, result.text, cv::Point(result.rect.x, result.rect.y - 20), cv::FONT_HERSHEY_SIMPLEX,
0.5, cv::Scalar(0, 0, 255), 2);
}
else {
cv::putText(m_image_draw, result.text, cv::Point(result.rect.x, result.rect.y - 5), cv::FONT_HERSHEY_SIMPLEX,
0.5, cv::Scalar(0, 255, 0), 2);
}
#endif
std::string digit_str = result.text;

View File

@@ -1,6 +1,6 @@
#pragma once
#include "Config/Miscellaneous/StageDropsConfig.h"
#include "Vision/AbstractImageAnalyzer.h"
#include "Config/Miscellaneous/StageDropsConfig.h"
namespace asst
{
@@ -27,7 +27,7 @@ namespace asst
bool analyze_baseline();
bool analyze_drops();
int match_quantity(const Rect& roi);
int match_quantity(const Rect& roi, bool use_word_model = false);
StageDropType match_droptype(const Rect& roi);
std::string match_item(const Rect& roi, StageDropType type, int index, int size);