Skip to content

Commit

Permalink
Merge pull request #4 from OwlHowlinMornSky/test
Browse files Browse the repository at this point in the history
修正转移GUI后的问题
  • Loading branch information
OwlHowlinMornSky authored Dec 15, 2023
2 parents 88f1460 + 85469ac commit a5ac8ff
Show file tree
Hide file tree
Showing 31 changed files with 1,775 additions and 517 deletions.
18 changes: 18 additions & 0 deletions CoreDll/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)WinFormsGUI\bin\$(Platform)\$(Configuration)\net6.0-windows10.0.22000.0\</OutDir>
<TargetName>$(SolutionName)-Core</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)WinFormsGUI\bin\$(Platform)\$(Configuration)\net6.0-windows10.0.22000.0\</OutDir>
<TargetName>$(SolutionName)-Core</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -65,7 +67,13 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(OHMS_LIB_DIR)\opencv\4.8.0\build\x64\vc16\lib;$(OHMS_LIB_DIR)\ohms\wgc\v1.2\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>windowsapp.lib;dwmapi.lib;opencv_world480d.lib;wgc-capture-d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<Version>
</Version>
</Link>
<Manifest>
<AssemblyIdentity>
</AssemblyIdentity>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -86,7 +94,13 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(OHMS_LIB_DIR)\opencv\4.8.0\build\x64\vc16\lib;$(OHMS_LIB_DIR)\ohms\wgc\v1.2\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>windowsapp.lib;dwmapi.lib;opencv_world480.lib;wgc-capture.lib;%(AdditionalDependencies)</AdditionalDependencies>
<Version>
</Version>
</Link>
<Manifest>
<AssemblyIdentity>
</AssemblyIdentity>
</Manifest>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Clock.cpp" />
Expand All @@ -102,8 +116,12 @@
<ClInclude Include="framework.h" />
<ClInclude Include="Helper.h" />
<ClInclude Include="IHelper.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Time.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CoreDll.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
8 changes: 8 additions & 0 deletions CoreDll/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@
<ClInclude Include="API.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CoreDll.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
Binary file added CoreDll/CoreDll.rc
Binary file not shown.
12 changes: 9 additions & 3 deletions CoreDll/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ void Helper::mainwork() {
// 允许关闭屏幕和睡眠
SetThreadExecutionState(ES_CONTINUOUS);

#ifdef OHMS_DDOA_SHOW
cv::destroyAllWindows(); // show mat的时候才需要销毁窗口
#endif // OHMS_DDOA_SHOW
cv::destroyAllWindows(); // 销毁show窗口

m_running = false; // 清除标记
msgPush(HelperReturnMessage::BtnToStart); // 让主按钮变成start
msgPush(HelperReturnMessage::Stopped); // 通知已完全停止
Expand All @@ -151,4 +150,11 @@ void Helper::msgPush(unsigned long hrm) {
return;
}

void Helper::msgPush(unsigned long hrm, unsigned long code) {
std::lock_guard lg(m_hrm_mutex); // 上锁
m_hrm.push(hrm); // 压入
m_hrm.push(code); // 压入
return;
}

} // namespace ohms
5 changes: 4 additions & 1 deletion CoreDll/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ class Helper final :
*/
virtual void regForNew(bool forNew) override;


virtual void regForMouse(bool forMouse) override;

virtual void regShowCV(bool show) override;

public:
/**
* @brief 尝试开始任务。任务将运行在子线程,如果已经运行则无效。
* @return true为成功
Expand Down Expand Up @@ -61,6 +63,7 @@ class Helper final :
* @param hrm 消息
*/
void msgPush(unsigned long hrm);
void msgPush(unsigned long hrm, unsigned long code);

// 子任务,返回 false 表示无法继续 (在 Helper.subworks.cpp 实现)
protected:
Expand Down
35 changes: 25 additions & 10 deletions CoreDll/Helper.steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace {
constexpr int g_nMatchMethod = cv::TM_SQDIFF_NORMED; // opencv match时用的方法。
constexpr bool g_useColorDiff = false; // check函数用的选项。

bool g_showcv = false;
bool g_showopened = false;
std::mutex g_showcvMutex;

/**
* @brief 比较两个mat,按超过阈值的像素数。
* @param matSample 输入
Expand Down Expand Up @@ -108,21 +112,33 @@ inline bool find(const cv::Mat& matSample, const cv::Mat& matTemplate, cv::Rect&
bool res = check(matSample(r), matTemplate, thres);
if (res) rect = r; // 保存到rect

#ifdef OHMS_DDOA_SHOW
matSample.copyTo(srcImage); // 复制原始输入
cv::rectangle(srcImage, oldRect, cv::Scalar(255, 0, 0), 2, 8, 0); // 蓝线画寻找范围框
cv::rectangle(srcImage, r, res ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255), 2, 8, 0); // 画最佳匹配框(满足阈值为绿,否则为红)
cv::resize(srcImage, srcImage, srcImage.size() / 2, 0.0, 0.0, cv::InterpolationFlags::INTER_LINEAR); // 缩小到一般
cv::imshow("show", srcImage); // show
#endif // OHMS_DDOA_SHOW
std::lock_guard lg(g_showcvMutex);
if (g_showcv) {
matSample.copyTo(srcImage); // 复制原始输入
cv::rectangle(srcImage, oldRect, cv::Scalar(255, 0, 0), 2, 8, 0); // 蓝线画寻找范围框
cv::rectangle(srcImage, r, res ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255), 2, 8, 0); // 画最佳匹配框(满足阈值为绿,否则为红)
cv::resize(srcImage, srcImage, srcImage.size() / 2, 0.0, 0.0, cv::InterpolationFlags::INTER_LINEAR); // 缩小到一般
g_showopened = true;
cv::imshow("show", srcImage); // show
}
#ifndef _DEBUG
else if (g_showopened) { // Release 时自动关闭 OpenCV 窗口
cv::destroyAllWindows();
}
#endif
return res;
}

}

namespace ohms {

bool ohms::Helper::step_copyMat(cv::Mat& target) {
void Helper::regShowCV(bool show) {
std::lock_guard lg(g_showcvMutex);
g_showcv = show;
}

bool Helper::step_copyMat(cv::Mat& target) {
if (r_capture->isRefreshed()) { // refresh过再处理画面才有意义
if (r_capture->copyMatTo(target, true)) { // 要求转换为BGR
if (target.size().width != 960 || target.size().height != 540) { // 确保大小满足要求
Expand Down Expand Up @@ -272,8 +288,7 @@ bool Helper::step_keepClickingUntil(
}

void Helper::step_subtaskError(unsigned long type) {
msgPush(HelperReturnMessage::Log_ErrorInTask);
msgPush(type);
msgPush(HelperReturnMessage::Log_ErrorInTask, type);
throw 0; // 要求停止
}

Expand Down
3 changes: 1 addition & 2 deletions CoreDll/Helper.subworks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ bool Helper::subwork_challenge() {
begin_point:
try {
++i;
msgPush(HelperReturnMessage::Log_Challenge_BeginNum);
msgPush(i);
msgPush(HelperReturnMessage::Log_Challenge_BeginNum, i);

// 查找目标。
if (!step_waitFor(forNew ? mat_ChaGameNew : mat_ChaGameLast, rect_ChaGame, rect, seconds(15.0f)))
Expand Down
4 changes: 4 additions & 0 deletions CoreDll/IHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum CORE_API HelperReturnMessage : unsigned long {
Log_Task_Stop,
Log_Task_Exception,

// 以下都是 Log_ErrorInTask 指定参数
Log_Task_Challenge_NoNew,
Log_Task_Challenge_NoLast,
Log_Task_Challenge_NoEnter,
Expand Down Expand Up @@ -67,6 +68,9 @@ class CORE_API IHelper {

virtual void regForMouse(bool forMouse) = 0;

virtual void regShowCV(bool show) = 0;

public:
/**
* @brief 尝试开始任务。任务将运行在子线程,如果已经运行则无效。
* @return true为成功
Expand Down
14 changes: 14 additions & 0 deletions CoreDll/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by CoreDll.rc

// 新对象的下一组默认值
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Binary file added CoreWrapper/CoreWrapper.rc
Binary file not shown.
23 changes: 17 additions & 6 deletions CoreWrapper/HelperWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ HelperWrapper::~HelperWrapper() {
m_helper = nullptr;
}

void HelperWrapper::regForNew(bool forNew) {
m_helper->regForNew(forNew);
}

void HelperWrapper::regForMouse(bool forMouse) {
m_helper->regForMouse(forMouse);
void HelperWrapper::set(HelprSet type, System::Int32 val) {
switch (type) {
case HelprSet::Cha_New:
m_helper->regForNew(val);
break;
case HelprSet::Ctrl_MouseInput:
m_helper->regForMouse(val);
break;
case HelprSet::ShowCV:
m_helper->regShowCV(val);
break;
}
}

bool HelperWrapper::start() {
Expand All @@ -44,4 +50,9 @@ System::UInt32 HelperWrapper::codePop() {
return res;
}

void HelperWrapper::drop() {
ohms::IHelper::drop();
m_helper = nullptr;
}

}
6 changes: 4 additions & 2 deletions CoreWrapper/HelperWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <IHelper.h>
#include "ReturnMessages.h"
#include "SettingsEnum.h"

namespace Wrapper {

Expand All @@ -11,8 +12,7 @@ public ref class HelperWrapper {
~HelperWrapper();

public:
void regForNew(bool forNew);
void regForMouse(bool forMouse);
void set(HelprSet type, System::Int32 val);

bool start();
void askForStop();
Expand All @@ -21,6 +21,8 @@ public ref class HelperWrapper {
ReturnMessage msgPop();
System::UInt32 codePop();

void drop();

private:
ohms::IHelper* m_helper;
};
Expand Down
15 changes: 15 additions & 0 deletions CoreWrapper/SettingsEnum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

namespace Wrapper {

public enum class HelprSet {
None = 0,

Cha_New,

Ctrl_MouseInput,

ShowCV,
};

}
23 changes: 21 additions & 2 deletions CoreWrapper/Wrapper.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)WinFormsGUI\bin\$(Platform)\$(Configuration)\net6.0-windows10.0.22000.0\</OutDir>
<TargetName>$(SolutionName)-Core-Wrapper</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)WinFormsGUI\bin\$(Platform)\$(Configuration)\net6.0-windows10.0.22000.0\</OutDir>
<TargetName>$(SolutionName)-Core-Wrapper</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -63,9 +65,15 @@
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<Link>
<AdditionalDependencies>CoreDll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>$(SolutionName)-Core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutputPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<Version>
</Version>
</Link>
<Manifest>
<AssemblyIdentity>
</AssemblyIdentity>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -76,17 +84,28 @@
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<Link>
<AdditionalDependencies>CoreDll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>$(SolutionName)-Core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutputPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<Version>
</Version>
</Link>
<Manifest>
<AssemblyIdentity>
</AssemblyIdentity>
</Manifest>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="HelperWrapper.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="ReturnMessages.h" />
<ClInclude Include="SettingsEnum.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="HelperWrapper.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CoreWrapper.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
11 changes: 11 additions & 0 deletions CoreWrapper/Wrapper.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@
<ClInclude Include="ReturnMessages.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="SettingsEnum.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="HelperWrapper.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CoreWrapper.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions CoreWrapper/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by CoreWrapper.rc

// 新对象的下一组默认值
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Loading

0 comments on commit a5ac8ff

Please sign in to comment.