Skip to content

Commit

Permalink
pref: 只有遇到致命错误才会终止识别,否则会尽量可能返回识别结果
Browse files Browse the repository at this point in the history
  • Loading branch information
Sallee1 committed Jun 2, 2023
1 parent e2b229f commit 66302b2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
23 changes: 8 additions & 15 deletions cvAutoTrack/src/AutoTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,6 @@ bool AutoTrack::GetTransformOfMap(double& x, double& y, double& a, int& mapId)
init();//初始化
}

/*
获取坐标的优先级远高于获取方向
所以只要能获取到坐标,就可以尝试输出,不至于因为识别不到方向导致追踪失效
*/
if (!GetPositionOfMap(x2, y2, mapId2))
{
return false;
Expand Down Expand Up @@ -652,32 +648,31 @@ bool AutoTrack::GetAllInfo(double& x, double& y, int& mapId, double& a, double&
//err = { 1001, "获取所有信息时,没有识别到paimon" };
return false;
}

if (genshin_minimap.img_minimap.empty())
{
err = { 5, "原神小地图区域为空" };
return false;
}
if (genshin_minimap.rect_avatar.empty())
{
err = { 11,"原神角色小箭头区域为空" };
return false;
}

// x,y,mapId
{
genshin_minimap.config.is_find_paimon = true;

GetPositionOfMap(x, y, mapId);
}

if (genshin_minimap.rect_avatar.empty())
{
err = { 11,"原神角色小箭头区域为空" };
return false;
}

// a
{
direction_calculation_config config;
direction_calculation(genshin_minimap.img_avatar, a, config);
if (config.error)
{
err = config.err;
return false;
}
}
// r
Expand All @@ -687,7 +682,6 @@ bool AutoTrack::GetAllInfo(double& x, double& y, int& mapId, double& a, double&
if (config.error)
{
err = config.err;
return false;
}
}
cv::Mat& giUIDRef = genshin_screen.img_uid;
Expand All @@ -711,14 +705,13 @@ bool AutoTrack::GetAllInfo(double& x, double& y, int& mapId, double& a, double&
if (config.error)
{
err = config.err;
return false;
}
}

#ifdef _DEBUG
showMatchResult(x, y, mapId, a, r);
#endif // _DEBUG
return clear_error_logs();
return clear_error_logs();
}

bool AutoTrack::GetInfoLoadPicture(char* path, int& uid, double& x, double& y, double& a)
Expand Down
4 changes: 4 additions & 0 deletions cvAutoTrack/src/algorithms/algorithms.direction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ struct direction_calculation_config
error_info err = { 0,"" };
};

double last_direction = 0;

void direction_calculation(cv::Mat& giAvatarRef, double& a, direction_calculation_config& config)
{
cv::resize(giAvatarRef, giAvatarRef, cv::Size(), 2, 2);
Expand Down Expand Up @@ -95,6 +97,8 @@ void direction_calculation(cv::Mat& giAvatarRef, double& a, direction_calculatio
{
config.error = true;
config.err = { 9,"提取小箭头特征误差过大" };
a = last_direction;
return;
}
last_direction = a;
}
5 changes: 5 additions & 0 deletions cvAutoTrack/src/algorithms/algorithms.rotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ struct rotation_calculation_config
error_info err = { 0,"" };

};

double lastRotate = 0;

void rotation_calculation(cv::Mat& giMiniMapRef, double&a, rotation_calculation_config& config)
{
cv::Mat img_object(giMiniMapRef(cv::Rect(40, 40, giMiniMapRef.cols - 80, giMiniMapRef.rows - 80)));
Expand Down Expand Up @@ -69,6 +72,7 @@ void rotation_calculation(cv::Mat& giMiniMapRef, double&a, rotation_calculation_
{
config.error = true;
config.err = { 3005 ,"获取视角朝向时,没有提取出视角扇形区域" };
a = lastRotate;
return;
}

Expand Down Expand Up @@ -98,4 +102,5 @@ void rotation_calculation(cv::Mat& giMiniMapRef, double&a, rotation_calculation_
p = p - cv::Point(img_object.cols / 2, img_object.rows / 2);

a = TianLi::Utils::Line2Angle(p);
lastRotate = a;
}
2 changes: 1 addition & 1 deletion cvAutoTrack/src/version/version_tag.tag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.8.103
7.8.104
2 changes: 1 addition & 1 deletion impl/Cpp/TEST_cvAutoTrack_Cpp/TEST_cvAutoTrack_Cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void Run_GetAll()
double x, y, a, r;
int mapId,uid;
std::string mapType;
if (GetAllInfo(x, y, mapId, a, r, uid))
if (!GetAllInfo(x, y, mapId, a, r, uid))
{
switch (mapId) {
case 0:mapType = "提瓦特大陆"; break;
Expand Down

0 comments on commit 66302b2

Please sign in to comment.