From e731a09f113f5a8c16200c6497c49bb7c929b6d5 Mon Sep 17 00:00:00 2001 From: amate Date: Mon, 19 Apr 2021 06:45:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=BB[fix]=20=E5=88=9D=E5=9B=9E=E8=B5=B7?= =?UTF-8?q?=E5=8B=95=E6=99=82=E3=81=AB=E3=83=AC=E3=83=BC=E3=82=B9=E5=A0=B4?= =?UTF-8?q?=E3=81=AE=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=81=8C=E3=81=99?= =?UTF-8?q?=E3=81=B9=E3=81=A6=E5=A4=96=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B?= =?UTF-8?q?=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・[fix] "プレビューウィンドウの更新をトレーニング画面で止める"が機能していなかったのを修正 ・[fix] 起動時にイベント名の検索が機能していなかったのを修正 ・[fix] 特定のイベント名の選択肢が出てこなかったのを修正 --- UmaCruise/MainDlg.cpp | 18 +++++++++++------- UmaCruise/UmaCruise.vcxproj | 3 +++ UmaCruise/UmaEventLibrary.cpp | 8 ++++++++ UmaCruise/UmaTextRecognizer.cpp | 29 ++++++++++++++++++++++++++--- UmaCruise/UmaTextRecognizer.h | 10 +++++----- UmaLibrary/Common.json | 6 ++++++ 6 files changed, 59 insertions(+), 15 deletions(-) diff --git a/UmaCruise/MainDlg.cpp b/UmaCruise/MainDlg.cpp index a0af092..c6196bc 100644 --- a/UmaCruise/MainDlg.cpp +++ b/UmaCruise/MainDlg.cpp @@ -239,18 +239,22 @@ LRESULT CMainDlg::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) m_previewWindow.ShowWindow(SW_NORMAL); } } - // Race m_showRaceAfterCurrentDate = jsonSetting["MainDlg"].value("ShowRaceAfterCurrentDate", m_showRaceAfterCurrentDate); const int32_t state = jsonSetting["MainDlg"].value("RaceMatchState", -1); _SetRaceMatchState(state); - _UpdateRaceList(L""); + } else { + _SetRaceMatchState(-1); } + _UpdateRaceList(L""); + DoDataExchange(DDX_LOAD); } catch (std::exception& e) { ATLTRACE(L"%s\n", (LPCWSTR)(CA2W(e.what()))); + ERROR_LOG << L"LoadConfig failed: " << (LPCWSTR)(CA2W(e.what())); + ATLASSERT(FALSE); } ChangeWindowTitle(L"init suscess!"); @@ -430,11 +434,8 @@ void CMainDlg::OnStart(UINT uNotifyCode, int nID, CWindow wndCtl) bool success = m_umaTextRecoginzer.TextRecognizer(ssImage.get()); if (success) { bool updateImage = true; - if (m_config.stopUpdatePreviewOnTraining) { - const std::wstring& currentMenu = m_umaTextRecoginzer.GetCurrentMenu(); - if (currentMenu != L"琬" && currentMenu != L"g[jO") { - updateImage = false; - } + if (m_config.stopUpdatePreviewOnTraining && !m_umaTextRecoginzer.IsTrainingMenu()) { + updateImage = false; } if (updateImage) { m_previewWindow.UpdateImage(ssImage.release()); @@ -518,6 +519,9 @@ void CMainDlg::OnStart(UINT uNotifyCode, int nID, CWindow wndCtl) void CMainDlg::OnEventNameChanged(UINT uNotifyCode, int nID, CWindow wndCtl) { DoDataExchange(DDX_SAVE, IDC_EDIT_EVENTNAME); + if (m_eventName.IsEmpty()) { + return; + } std::vector eventNames; eventNames.emplace_back((LPCWSTR)m_eventName); auto optUmaEvent = m_umaEventLibrary.AmbiguousSearchEvent(eventNames); diff --git a/UmaCruise/UmaCruise.vcxproj b/UmaCruise/UmaCruise.vcxproj index 5f89fa0..5a5906d 100644 --- a/UmaCruise/UmaCruise.vcxproj +++ b/UmaCruise/UmaCruise.vcxproj @@ -200,6 +200,9 @@ $(IntDir)/UmaCruise.tlb + + copy "$(targetPath)" "$(SolutionDir)#Release\UmaUmaCruise\UmaUmaCruise.exe" + diff --git a/UmaCruise/UmaEventLibrary.cpp b/UmaCruise/UmaEventLibrary.cpp index 13aeb67..3e160dd 100644 --- a/UmaCruise/UmaEventLibrary.cpp +++ b/UmaCruise/UmaEventLibrary.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "UmaEventLibrary.h" +#include #include #include #include @@ -55,6 +56,12 @@ boost::optional retrieve( return retrieve(dbr, ambiguousEventNames, measure, threshold, kMinThreshold); } +void EventNameNormalize(std::wstring& eventName) +{ + std::wregex rx(L"iisx[^\\j]+j"); + eventName = std::regex_replace(eventName, rx, L""); +} + // ============================================================== bool UmaEventLibrary::LoadUmaMusumeLibrary() @@ -66,6 +73,7 @@ bool UmaEventLibrary::LoadUmaMusumeLibrary() for (const json& jsonEvent : jsonEventList) { auto eventElm = *jsonEvent.items().begin(); std::wstring eventName = UTF16fromUTF8(eventElm.key()); + EventNameNormalize(eventName); charaEvent.umaEventList.emplace_back(); UmaEvent& umaEvent = charaEvent.umaEventList.back(); diff --git a/UmaCruise/UmaTextRecognizer.cpp b/UmaCruise/UmaTextRecognizer.cpp index 7f2cd49..8d9279d 100644 --- a/UmaCruise/UmaTextRecognizer.cpp +++ b/UmaCruise/UmaTextRecognizer.cpp @@ -278,7 +278,18 @@ bool UmaTextRecognizer::TextRecognizer(Gdiplus::Bitmap* image) cv::Mat thresImage; cv::threshold(grayImage, thresImage, 0.0, 255.0, cv::THRESH_OTSU); - +#if 0 + // 4{ + cv::Mat resizedImage; + constexpr double scale = 4.0; + cv::resize(cutImage2, resizedImage, cv::Size(), scale, scale, cv::INTER_CUBIC); + + cv::Mat grayImage2; + cv::cvtColor(resizedImage, grayImage2, cv::COLOR_RGB2GRAY); + + cv::Mat thresImage2; + cv::threshold(grayImage2, thresImage2, 0.0, 255.0, cv::THRESH_OTSU); +#endif auto funcPushBackImageText = [this](cv::Mat& image) { std::wstring text = TextFromImage(image); @@ -299,6 +310,8 @@ bool UmaTextRecognizer::TextRecognizer(Gdiplus::Bitmap* image) funcPushBackImageText(grayImage); funcPushBackImageText(invertedImage); funcPushBackImageText(thresImage); + //funcPushBackImageText(resizedImage); + //funcPushBackImageText(thresImage2); } { // ݂̓t CRect rcTurnBounds = _AdjustBounds(srcImage, m_testBounds[kCurrentTurnBounds]); @@ -328,12 +341,22 @@ bool UmaTextRecognizer::TextRecognizer(Gdiplus::Bitmap* image) //INFO_LOG << L"CurrentTurn, cut: " << cutImageText << L" thres: " << thresImageText; } - { // ݃j[[琬/g[jO] + { // ݃j[[g[jO] + m_bTrainingMenu = false; + CRect rcCurrentMenuBounds = _AdjustBounds(srcImage, m_testBounds[kCurrentMenuBounds]); cv::Mat cutImage(srcImage, cvRectFromCRect(rcCurrentMenuBounds)); std::wstring cutImageText = TextFromImage(cutImage); - m_currentMenu = cutImageText; + if (cutImageText == L"g[jO") { + CRect rcBackButtonBounds = _AdjustBounds(srcImage, m_testBounds[kBackButtonBounds]); + cv::Mat cutImage2(srcImage, cvRectFromCRect(rcBackButtonBounds)); + + std::wstring cutImage2Text = TextFromImage(cutImage2); + if (cutImage2Text == L"߂") { + m_bTrainingMenu = true; + } + } } return true; diff --git a/UmaCruise/UmaTextRecognizer.h b/UmaCruise/UmaTextRecognizer.h index c453247..10c21e1 100644 --- a/UmaCruise/UmaTextRecognizer.h +++ b/UmaCruise/UmaTextRecognizer.h @@ -28,8 +28,8 @@ class UmaTextRecognizer const std::vector& GetEventName() const { return m_eventName; } - const std::wstring& GetCurrentMenu() const { - return m_currentMenu; + bool IsTrainingMenu() const { + return m_bTrainingMenu; } private: @@ -44,10 +44,10 @@ class UmaTextRecognizer CSize m_baseClientSize; enum TestBounds { - kUmaMusumeSubNameBounds, kUmaMusumeNameBounds, kCurrentTurnBounds, kEventCategoryBounds, kEventNameBounds, kEventNameIconBounds, kCurrentMenuBounds, kMaxCount + kUmaMusumeSubNameBounds, kUmaMusumeNameBounds, kCurrentTurnBounds, kEventCategoryBounds, kEventNameBounds, kEventNameIconBounds, kCurrentMenuBounds, kBackButtonBounds, kMaxCount }; static constexpr LPCWSTR kTestBoundsName[kMaxCount] = { - L"UmaMusumeSubNameBounds", L"UmaMusumeNameBounds", L"CurrentTurnBounds", L"EventCategoryBounds", L"EventNameBounds", L"EventNameIconBounds", L"CurrentMenuBounds", + L"UmaMusumeSubNameBounds", L"UmaMusumeNameBounds", L"CurrentTurnBounds", L"EventCategoryBounds", L"EventNameBounds", L"EventNameIconBounds", L"CurrentMenuBounds", L"BackButtonBounds", }; std::array m_testBounds; int m_kCurrentTurnThreshold = 111; @@ -56,6 +56,6 @@ class UmaTextRecognizer std::vector m_umaMusumeName; std::vector m_currentTurn; std::vector m_eventName; - std::wstring m_currentMenu; + bool m_bTrainingMenu = false; }; diff --git a/UmaLibrary/Common.json b/UmaLibrary/Common.json index 7b30f3d..0590582 100644 --- a/UmaLibrary/Common.json +++ b/UmaLibrary/Common.json @@ -29,6 +29,12 @@ }, "EventNameIconBounds": { "x": 96, "y": 197, "width": 30, "height": 30 + }, + "CurrentMenuBounds" : { + "x": 19, "y": 2, "width": 114, "height": 31 + }, + "BackButtonBounds" : { + "x": 43, "y": 993, "width": 58, "height": 32 } },