Say where a candidate was when the search gate rejects it
A first run in simulation reported "1 candidate(s) matched the shape but fell outside the search gate" every second for fifteen seconds. That says the detector found the plate and something else threw it away, which is useful, but not useful enough: the only question worth asking at that moment is whether to widen the gate or turn the robot, and a count cannot answer it. The reason now carries the position, bearing and range of the nearest rejected candidate along with the gate that rejected it, so the number to put in the config is read off the log instead of guessed. That is what the run needed and did not have.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
|
||||
namespace dock_pattern_detector
|
||||
{
|
||||
@@ -122,6 +123,12 @@ Detection VPatternMatcher::match(const std::vector<Line>& lines) const
|
||||
std::size_t rejected_confidence = 0;
|
||||
std::size_t accepted = 0;
|
||||
|
||||
// Ứng viên GẦN ĐÚNG NHẤT bị cổng tìm kiếm loại. Chỉ đếm số lượng thì không trả lời được câu duy
|
||||
// nhất đáng hỏi lúc đó: nới quạt ra, hay xoay robot lại? Cần biết nó nằm ở đâu.
|
||||
bool have_gated = false;
|
||||
Point gated_apex;
|
||||
double gated_dist = 0.0;
|
||||
|
||||
for (std::size_t i = 0; i + 1 < lines.size(); ++i)
|
||||
{
|
||||
for (std::size_t j = i + 1; j < lines.size(); ++j)
|
||||
@@ -213,12 +220,25 @@ Detection VPatternMatcher::match(const std::vector<Line>& lines) const
|
||||
if (d > profile_.search_radius)
|
||||
{
|
||||
++rejected_prior;
|
||||
if (!have_gated || d < gated_dist)
|
||||
{
|
||||
have_gated = true;
|
||||
gated_apex = apex;
|
||||
gated_dist = d;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (profile_.search_fov > 0.0 && std::fabs(std::atan2(apex.y, apex.x)) > profile_.search_fov)
|
||||
{
|
||||
++rejected_prior;
|
||||
const double bearing = std::fabs(std::atan2(apex.y, apex.x));
|
||||
if (!have_gated || bearing < gated_dist)
|
||||
{
|
||||
have_gated = true;
|
||||
gated_apex = apex;
|
||||
gated_dist = bearing;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -271,8 +291,29 @@ Detection VPatternMatcher::match(const std::vector<Line>& lines) const
|
||||
// "thấy nhưng méo" đòi hai cách xử trí ngược nhau, mà một dòng "detection failed" thì không.
|
||||
if (rejected_prior > 0)
|
||||
{
|
||||
best.reason = std::to_string(rejected_prior) +
|
||||
" candidate(s) matched the shape but fell outside the search gate";
|
||||
// Kèm VỊ TRÍ và HƯỚNG của ứng viên gần nhất bị loại. Chỉ có con số thì không biết nên nới
|
||||
// quạt hay xoay robot — mà đó đúng là câu duy nhất cần trả lời lúc này.
|
||||
char detail[192] = { 0 };
|
||||
if (have_gated)
|
||||
{
|
||||
std::snprintf(detail, sizeof(detail),
|
||||
" (nearest at (%.2f, %.2f) m, bearing %.2f rad = %.0f deg, range %.2f m;"
|
||||
" gate search_fov=%.2f rad",
|
||||
gated_apex.x, gated_apex.y, std::atan2(gated_apex.y, gated_apex.x),
|
||||
std::atan2(gated_apex.y, gated_apex.x) * 180.0 / M_PI,
|
||||
std::hypot(gated_apex.x, gated_apex.y), profile_.search_fov);
|
||||
std::string tail = profile_.has_prior
|
||||
? ", search_radius=" + std::to_string(profile_.search_radius) + " m)"
|
||||
: ")";
|
||||
best.reason = std::to_string(rejected_prior) +
|
||||
" candidate(s) matched the shape but fell outside the search gate" + detail +
|
||||
tail;
|
||||
}
|
||||
else
|
||||
{
|
||||
best.reason = std::to_string(rejected_prior) +
|
||||
" candidate(s) matched the shape but fell outside the search gate";
|
||||
}
|
||||
}
|
||||
else if (rejected_confidence > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user