载入中...
搜索中...
未找到
ActionGuideVerify.cpp
浏览该文件的文档.
2
3#include "common/Diagnostic.h"
4
5#include <algorithm>
6#include <cmath>
7#include <span>
8#include <utility>
9
10namespace eve {
11namespace {
12
13template <typename T>
14Result<T> invalid(std::string message, std::string path) {
16}
17
18std::uint8_t maxRgb(std::uint8_t r, std::uint8_t g, std::uint8_t b) {
19 return static_cast<std::uint8_t>(std::max({r, g, b}));
20}
21
22} // namespace
23
25 std::span<const std::uint8_t> candidateRgba8,
26 std::uint32_t width, std::uint32_t height,
27 std::uint8_t guideLuminanceThreshold,
28 std::uint8_t candidateAlphaThreshold) {
29 const size_t expected = size_t(width) * height * 4;
30 if (width == 0 || height == 0) return invalid<ActionGuideSilhouetteMetrics>("empty canvas", "size");
31 if (guideRgba8.size() != expected || candidateRgba8.size() != expected)
32 return invalid<ActionGuideSilhouetteMetrics>("RGBA buffer size mismatch", "rgba8");
33
35 for (size_t p = 0; p + 3 < expected; p += 4) {
36 const bool guideFg = maxRgb(guideRgba8[p], guideRgba8[p + 1], guideRgba8[p + 2]) >= guideLuminanceThreshold;
37 const bool candFg = candidateRgba8[p + 3] > candidateAlphaThreshold;
38 if (guideFg) ++metrics.guideForeground;
39 if (candFg) ++metrics.candidateForeground;
40 if (guideFg && candFg) ++metrics.intersection;
41 if (guideFg || candFg) ++metrics.unionCount;
42 }
43 if (metrics.guideForeground == 0)
44 return invalid<ActionGuideSilhouetteMetrics>("guide silhouette foreground is empty", "guide");
45 if (metrics.candidateForeground == 0)
46 return invalid<ActionGuideSilhouetteMetrics>("candidate foreground is empty", "candidate");
47 metrics.iou = static_cast<double>(metrics.intersection) / static_cast<double>(metrics.unionCount);
49}
50
51Result<ActionGuideJointMetrics> compareActionGuideJointError(std::span<const ActionGuideLandmark> expected,
52 std::span<const ActionGuideLandmark> observed) {
54 if (expected.empty()) {
55 metrics.evaluated = false;
57 }
58 if (observed.empty())
59 return invalid<ActionGuideJointMetrics>("observed joints required when expected landmarks are present",
60 "joints");
61
62 metrics.evaluated = true;
63 double maxError = 0.0;
64 for (const auto& exp : expected) {
65 const ActionGuideLandmark* match = nullptr;
66 for (const auto& obs : observed) {
67 if (obs.boneId == exp.boneId) {
68 match = &obs;
69 break;
70 }
71 }
72 if (!match) {
73 ++metrics.missingBones;
74 continue;
75 }
76 ++metrics.matchedBones;
77 const double dx = exp.x - match->x;
78 const double dy = exp.y - match->y;
79 const double error = std::sqrt(dx * dx + dy * dy);
81 }
82 metrics.maxErrorPx = maxError;
83 if (metrics.matchedBones == 0)
84 return invalid<ActionGuideJointMetrics>("no overlapping boneId between expected and observed joints", "joints");
86}
87
89 if (request.pack.shots.empty()) return invalid<ActionGuideVerifyReport>("guide pack has no shots", "pack.shots");
90 if (request.shots.size() != request.pack.shots.size())
91 return invalid<ActionGuideVerifyReport>("verify shot count must equal pack.shots size", "shots");
92
94 report.sourceGuideRevision = request.pack.revision;
95 report.minSilhouetteIoU = request.pack.qc.minSilhouetteIoU;
96 report.maxJointErrorPx = request.pack.qc.maxJointErrorPx;
97 report.passed = true;
98
99 for (size_t i = 0; i < request.shots.size(); ++i) {
100 const auto& in = request.shots[i];
101 const auto path = "shots[" + std::to_string(i) + "]";
103 shot.shotIndex = static_cast<std::int64_t>(i);
104 shot.shotId = in.shotId.empty() ? request.pack.shots[i].shotId : in.shotId;
105 if (!in.shotId.empty() && in.shotId != request.pack.shots[i].shotId) {
106 shot.passed = false;
107 shot.reason = "shotId does not match pack.shots order";
108 report.passed = false;
109 report.shots.push_back(std::move(shot));
110 continue;
111 }
112 if (!in.guideSilhouetteRgba8 || !in.candidateRgba8)
113 return invalid<ActionGuideVerifyReport>("missing guide or candidate RGBA", path);
114 if (in.width == 0 || in.height == 0 || in.width != static_cast<std::uint32_t>(request.pack.canvas.width) ||
115 in.height != static_cast<std::uint32_t>(request.pack.canvas.height))
116 return invalid<ActionGuideVerifyReport>("shot size must match pack.canvas", path + ".size");
117
118 auto iou = compareActionGuideSilhouetteIoU(*in.guideSilhouetteRgba8, *in.candidateRgba8, in.width, in.height,
119 request.guideLuminanceThreshold, request.candidateAlphaThreshold);
120 if (!iou) return Result<ActionGuideVerifyReport>::failure(iou.status());
121 shot.silhouette = iou.value();
122
123 if (shot.silhouette.iou + 1e-12 < report.minSilhouetteIoU) {
124 shot.passed = false;
125 shot.reason = "silhouette IoU below qc.minSilhouetteIoU";
126 } else {
127 shot.passed = true;
128 }
129
130 if (!in.expectedJoints.empty()) {
131 auto joints = compareActionGuideJointError(in.expectedJoints, in.observedJoints);
132 if (!joints) {
133 shot.passed = false;
134 shot.reason = joints.status().describe();
135 joints.ignore();
136 } else {
137 shot.joints = joints.value();
138 if (shot.joints.evaluated &&
139 (shot.joints.maxErrorPx > report.maxJointErrorPx || shot.joints.missingBones > 0)) {
140 shot.passed = false;
141 shot.reason = shot.joints.missingBones > 0 ? "joint boneId missing from observation"
142 : "joint error exceeds qc.maxJointErrorPx";
143 }
144 }
145 }
146
147 if (!shot.passed) report.passed = false;
148 report.shots.push_back(std::move(shot));
149 }
150
151 auto encoded = encodeActionGuideVerifyReport(report);
152 if (!encoded) return Result<ActionGuideVerifyReport>::failure(encoded.status());
153 report.evidence = std::move(encoded).takeValue();
154 return Result<ActionGuideVerifyReport>::success(std::move(report));
155}
156
158 Value::Array shots;
159 for (const auto& shot : report.shots) {
160 Value::Object row{
161 {"shotId", shot.shotId},
162 {"shotIndex", shot.shotIndex},
163 {"passed", shot.passed},
164 {"reason", shot.reason},
165 {"silhouette",
166 Value::object({{"iou", shot.silhouette.iou},
167 {"intersection", static_cast<std::int64_t>(shot.silhouette.intersection)},
168 {"union", static_cast<std::int64_t>(shot.silhouette.unionCount)},
169 {"guideForeground", static_cast<std::int64_t>(shot.silhouette.guideForeground)},
170 {"candidateForeground", static_cast<std::int64_t>(shot.silhouette.candidateForeground)}})},
171 {"joints", Value::object({{"evaluated", shot.joints.evaluated},
172 {"maxErrorPx", shot.joints.maxErrorPx},
173 {"matchedBones", static_cast<std::int64_t>(shot.joints.matchedBones)},
174 {"missingBones", static_cast<std::int64_t>(shot.joints.missingBones)}})}};
175 shots.emplace_back(std::move(row));
176 }
178 {{"schema", std::string(kActionGuideVerifyReportSchemaId)},
179 {"schemaVersion", static_cast<std::int64_t>(kActionGuideVerifyReportSchemaVersion)},
180 {"sourceGuideRevision", static_cast<std::int64_t>(report.sourceGuideRevision)},
181 {"passed", report.passed},
182 {"minSilhouetteIoU", report.minSilhouetteIoU},
183 {"maxJointErrorPx", report.maxJointErrorPx},
184 {"shots", Value(std::move(shots))},
185 {"playSmoke", Value::object({{"status", std::string("skipped")},
186 {"hint", std::string("optional eve_play smoke after geometric pass")}})}}));
187}
188
189} // namespace eve
CPU silhouette IoU and joint-error gates for ActionGuide candidates.
glm::vec4 p[6]
Stable, structured diagnostics shared by engine modules.
std::string message
const GltfImportRequest & request
tensor::Graph g
Definition GpuGraph.cpp:7
double r
std::uint32_t height
std::uint32_t width
double maxError
MeleePoint3 b
Definition MeleeHit.cpp:41
glm::dvec3 dx
std::string error
Definition Package.cpp:174
std::string path
Definition PlayHost.cpp:111
float dy
Definition Shadow.cpp:151
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Definition Value.h:33
static Value object(Object value)
Compatibility factory for an object value.
Definition Value.cpp:129
Status invalid(const char *message)
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
constexpr std::string_view kActionGuideVerifyReportSchemaId
constexpr std::uint64_t kActionGuideVerifyReportSchemaVersion
Result< ActionGuideVerifyReport > verifyActionGuideCandidates(const ActionGuideVerifyRequest &request)
Evaluate every shot against pack.qc; returns a report even when some shots fail.
Result< ActionGuideJointMetrics > compareActionGuideJointError(std::span< const ActionGuideLandmark > expected, std::span< const ActionGuideLandmark > observed)
Max L2 pixel error across bones present in both landmark lists (matched by boneId)....
Result< ActionGuideSilhouetteMetrics > compareActionGuideSilhouetteIoU(std::span< const std::uint8_t > guideRgba8, std::span< const std::uint8_t > candidateRgba8, std::uint32_t width, std::uint32_t height, std::uint8_t guideLuminanceThreshold, std::uint8_t candidateAlphaThreshold)
Compute silhouette IoU between guide luminance mask and candidate alpha mask.
Result< Value > encodeActionGuideVerifyReport(const ActionGuideVerifyReport &report)
Encode a verify report as a durable evidence Value.
Measured joint L2 error for one shot (optional when joints absent).
Projected joint in guide-canvas pixels (origin top-left) plus view depth.
ActionGuideSilhouetteMetrics silhouette
Measured silhouette overlap for one shot.
Aggregate verify report for one GuidePack revision. @ownership Caller-owned; Values are independent c...
std::vector< ActionGuideShotVerifyResult > shots
In-memory verify request.