|
@@ -119,6 +119,12 @@ class EvidenceV2Params:
|
|
|
body_min_roi_px: int = 90
|
|
body_min_roi_px: int = 90
|
|
|
body_x_margin_ratio: float = 0.03
|
|
body_x_margin_ratio: float = 0.03
|
|
|
body_min_posts: int = 3
|
|
body_min_posts: int = 3
|
|
|
|
|
+ # P0-Q6:箱底暗带缺失时(罐箱箱底被车帮挡住)“只看车体”的判据。
|
|
|
|
|
+ # 立柱跨度下限:敞车横跨整车(实测 0.66~0.92),平车上集装箱波纹只占中间
|
|
|
|
|
+ # 一段(0.36~0.45)→ 用跨度而不是立柱个数区分;上限放宽是因为 C++ 线段
|
|
|
|
|
+ # 通道会把门框/铰链算成多根(C70E 实测 20 根)。
|
|
|
|
|
+ vehicle_min_span_ratio: float = 0.50
|
|
|
|
|
+ vehicle_max_posts: int = 60
|
|
|
# P0-Q3:`1`(敞车)还必须有"八"字斜撑/三角撑证据(docs/edge_evidence.md §4.1)。
|
|
# P0-Q3:`1`(敞车)还必须有"八"字斜撑/三角撑证据(docs/edge_evidence.md §4.1)。
|
|
|
# 容器侧壁只有瓦楞、没有斜撑 → 防"上层箱坐在下层箱上"被判成敞车。
|
|
# 容器侧壁只有瓦楞、没有斜撑 → 防"上层箱坐在下层箱上"被判成敞车。
|
|
|
# 0 = 关闭该门(只用于对照实验,现场不要关)。
|
|
# 0 = 关闭该门(只用于对照实验,现场不要关)。
|
|
@@ -254,6 +260,8 @@ class EvidenceV2Params:
|
|
|
body_min_roi_px=int(raw.get("body_min_roi_px", 90)),
|
|
body_min_roi_px=int(raw.get("body_min_roi_px", 90)),
|
|
|
body_x_margin_ratio=float(raw.get("body_x_margin_ratio", 0.03)),
|
|
body_x_margin_ratio=float(raw.get("body_x_margin_ratio", 0.03)),
|
|
|
body_min_posts=int(raw.get("body_min_posts", 3)),
|
|
body_min_posts=int(raw.get("body_min_posts", 3)),
|
|
|
|
|
+ vehicle_min_span_ratio=float(raw.get("vehicle_min_span_ratio", 0.50)),
|
|
|
|
|
+ vehicle_max_posts=int(raw.get("vehicle_max_posts", 60)),
|
|
|
min_diagonal_braces=int(raw.get("min_diagonal_braces", 1)),
|
|
min_diagonal_braces=int(raw.get("min_diagonal_braces", 1)),
|
|
|
min_wall_opacity=float(raw.get("min_wall_opacity", 0.35)),
|
|
min_wall_opacity=float(raw.get("min_wall_opacity", 0.35)),
|
|
|
max_flat_gap_px=float(raw.get("max_flat_gap_px", 40.0)),
|
|
max_flat_gap_px=float(raw.get("max_flat_gap_px", 40.0)),
|
|
@@ -1135,6 +1143,38 @@ class EvidenceV2:
|
|
|
return 0
|
|
return 0
|
|
|
return int(len(np.asarray(circles).reshape(-1, 3)))
|
|
return int(len(np.asarray(circles).reshape(-1, 3)))
|
|
|
|
|
|
|
|
|
|
+ # ------------------------------------------------------------ 车体测量
|
|
|
|
|
+ def _measure_body(self, gray: np.ndarray, roi: Tuple[int, int, int, int],
|
|
|
|
|
+ scale: float) -> Dict[str, float]:
|
|
|
|
|
+ """车体 ROI 的结构证据(与 C++ ``measure_body`` 同口径)。
|
|
|
|
|
+
|
|
|
|
|
+ 返回 ``posts`` / ``span``(立柱跨度 ÷ ROI 宽)/ ``opacity``(不透明占比)/
|
|
|
|
|
+ ``diagonal``(斜撑数)/ ``height``(原图像素高度)。
|
|
|
|
|
+ """
|
|
|
|
|
+
|
|
|
|
|
+ structure = detect_structure_v2(
|
|
|
|
|
+ gray, roi, min_post_len_ratio=self.p.min_post_len_ratio,
|
|
|
|
|
+ cluster_gap_px=9.0, scale=scale,
|
|
|
|
|
+ )
|
|
|
|
|
+ positions = structure.get("post_positions") or []
|
|
|
|
|
+ span = 0.0
|
|
|
|
|
+ if len(positions) >= 2:
|
|
|
|
|
+ span = (max(positions) - min(positions)) / max(1.0, float(roi[2] - roi[0]))
|
|
|
|
|
+ ground, blocks = ground_like_ratio(
|
|
|
|
|
+ gray, roi, structure.get("lines", []), # type: ignore[arg-type]
|
|
|
|
|
+ block_px=self.p.ground_block_px,
|
|
|
|
|
+ density_lo=self.p.ground_density_lo,
|
|
|
|
|
+ density_hi=self.p.ground_density_hi,
|
|
|
|
|
+ )
|
|
|
|
|
+ opacity = 1.0 - ground if blocks > 0 else 0.0
|
|
|
|
|
+ return {
|
|
|
|
|
+ "posts": int(structure["post_count"]),
|
|
|
|
|
+ "span": float(span),
|
|
|
|
|
+ "opacity": float(opacity),
|
|
|
|
|
+ "diagonal": int(structure["diagonal_lines"]),
|
|
|
|
|
+ "height": float(roi[3] - roi[1]) / max(scale, 1e-6),
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
# ------------------------------------------------------------ 主入口
|
|
# ------------------------------------------------------------ 主入口
|
|
|
def analyze(
|
|
def analyze(
|
|
|
self,
|
|
self,
|
|
@@ -1204,6 +1244,70 @@ class EvidenceV2:
|
|
|
candidates = [b for b in dark if b.y0 >= 0.03 * wh and b.y1 <= 0.90 * wh]
|
|
candidates = [b for b in dark if b.y0 >= 0.03 * wh and b.y1 <= 0.90 * wh]
|
|
|
box = max(candidates, key=lambda b: b.strength) if candidates else None
|
|
box = max(candidates, key=lambda b: b.strength) if candidates else None
|
|
|
if box is None:
|
|
if box is None:
|
|
|
|
|
+ # P0-Q6:没有“箱底暗带”不等于判不了车型。现场目标是判「平车 / 敞车」,
|
|
|
|
|
+ # 罐箱(`04_container_on_gondola.png`)的箱底常被车帮挡住,但车体结构
|
|
|
|
|
+ # (门板立柱 + 斜撑 + 不透明侧墙)仍可见。这里退化为“只看车体”:
|
|
|
|
|
+ # 判得出 → 敞车 1(gap 记 0:箱在车斗内,不存在间隙);
|
|
|
|
|
+ # 判不出 → 仍按 `no_box` 弃权,**绝不**因此猜成平车。
|
|
|
|
|
+ if self.p.body_fallback_enable:
|
|
|
|
|
+ # ROI 用整个搜索窗口:罐箱会把 texture_top 定到车帮上沿,
|
|
|
|
|
+ # 按 texture_top 取 ROI 只剩几十像素,数不到立柱。
|
|
|
|
|
+ vy0 = max(0, int(window[1]))
|
|
|
|
|
+ vy1 = min(wh - 1, int(window[3]))
|
|
|
|
|
+ if vy1 > vy0:
|
|
|
|
|
+ vx0 = max(0, int(round(self.p.body_x_margin_ratio * ww)))
|
|
|
|
|
+ vx1 = min(ww - 1, int(round(
|
|
|
|
|
+ (1.0 - self.p.body_x_margin_ratio) * ww)))
|
|
|
|
|
+ body = self._measure_body(gray, (vx0, vy0, vx1, vy1), scale)
|
|
|
|
|
+ if (body["height"] >= self.p.body_min_roi_px
|
|
|
|
|
+ and self.p.body_min_posts <= body["posts"]
|
|
|
|
|
+ <= self.p.vehicle_max_posts
|
|
|
|
|
+ and body["span"] >= self.p.vehicle_min_span_ratio
|
|
|
|
|
+ and body["opacity"] >= self.p.body_min_opacity
|
|
|
|
|
+ and body["diagonal"] >= self.p.min_diagonal_braces):
|
|
|
|
|
+ conf = min(1.0, 0.55 + 0.25 * min(1.0, body["posts"] / 8.0)
|
|
|
|
|
+ + 0.15 * body["opacity"])
|
|
|
|
|
+ hits = min(1.0, 0.40 + 0.05 * body["posts"]
|
|
|
|
|
+ + 0.20 * body["opacity"])
|
|
|
|
|
+ commit = self.tracker.update(
|
|
|
|
|
+ ts,
|
|
|
|
|
+ state=1,
|
|
|
|
|
+ gap_m=0.0,
|
|
|
|
|
+ gap_px=0.0,
|
|
|
|
|
+ structure_hits=hits,
|
|
|
|
|
+ motion_ok=motion_ok,
|
|
|
|
|
+ view_known=self.p.view != ViewMode.UNKNOWN,
|
|
|
|
|
+ plc_arrived=plc_arrived,
|
|
|
|
|
+ plc_spreader_released=plc_spreader_released,
|
|
|
|
|
+ hoist_high=bool(hoist_high),
|
|
|
|
|
+ )
|
|
|
|
|
+ self._last = EvidenceV2Result(
|
|
|
|
|
+ state=1,
|
|
|
|
|
+ confidence=conf,
|
|
|
|
|
+ view=self.p.view,
|
|
|
|
|
+ texture_top_y=(float(texture_top) / max(scale, 1e-6)
|
|
|
|
|
+ if texture_top > 0.0 else None),
|
|
|
|
|
+ body_posts=int(body["posts"]),
|
|
|
|
|
+ body_span=float(body["span"]),
|
|
|
|
|
+ body_opacity=float(body["opacity"]),
|
|
|
|
|
+ body_diagonal=int(body["diagonal"]),
|
|
|
|
|
+ door_posts=int(body["posts"]),
|
|
|
|
|
+ diagonal_braces=int(body["diagonal"]),
|
|
|
|
|
+ wall_opacity=float(body["opacity"]),
|
|
|
|
|
+ ground_ratio=float(1.0 - body["opacity"]),
|
|
|
|
|
+ gap_px=0.0,
|
|
|
|
|
+ gap_m=0.0,
|
|
|
|
|
+ phase=(commit.phase if motion_ok else CommitPhase.T3),
|
|
|
|
|
+ committed=commit.committed,
|
|
|
|
|
+ commit_reason=commit.reason,
|
|
|
|
|
+ stable_frames=commit.stable_frames,
|
|
|
|
|
+ structure_frames=commit.structure_frames,
|
|
|
|
|
+ motion_ok=motion_ok,
|
|
|
|
|
+ hoist_high=bool(hoist_high),
|
|
|
|
|
+ diagnostics={"vehicle_only": True,
|
|
|
|
|
+ "reason": "vehicle_wall"},
|
|
|
|
|
+ )
|
|
|
|
|
+ return self._last
|
|
|
self._last = EvidenceV2Result(
|
|
self._last = EvidenceV2Result(
|
|
|
view=self.p.view, motion_ok=motion_ok, abstain_reason="no_box",
|
|
view=self.p.view, motion_ok=motion_ok, abstain_reason="no_box",
|
|
|
commit_reason="no_box", phase=CommitPhase.T3 if not motion_ok else CommitPhase.T1,
|
|
commit_reason="no_box", phase=CommitPhase.T3 if not motion_ok else CommitPhase.T1,
|
|
@@ -1434,8 +1538,12 @@ class EvidenceV2:
|
|
|
body = None
|
|
body = None
|
|
|
body_stats = None
|
|
body_stats = None
|
|
|
body_roi = None
|
|
body_roi = None
|
|
|
- if (self.p.body_fallback_enable and texture_top > 0.0 and state != 1
|
|
|
|
|
- and texture_top > window[1] + 0.05 * wh):
|
|
|
|
|
|
|
+ # P0-Q6:空车/无箱兜底。旧条件还要求“纹理车体顶明显低于窗口顶”(有天空),
|
|
|
|
|
+ # 于是“车把画面填满”的空敞车(`02_C70E_shigure03.jpg`,texture_top≈窗口顶)
|
|
|
|
|
+ # 永远进不来,只能弃权。现在只要找到车体顶就试一次;真正的守门是
|
|
|
|
|
+ # posts ∈ [body_min_posts, max_door_posts] —— 集装箱侧壁波纹(实测 18~31 根)
|
|
|
|
|
+ # 会被上限挡掉,不会被误判成门板阵列。
|
|
|
|
|
+ if self.p.body_fallback_enable and texture_top > 0.0 and state != 1:
|
|
|
by0 = max(int(window[1]), int(round(texture_top)))
|
|
by0 = max(int(window[1]), int(round(texture_top)))
|
|
|
by1 = min(int(window[3]), int(round(
|
|
by1 = min(int(window[3]), int(round(
|
|
|
texture_top + self.p.body_bottom_ratio * (window[3] - texture_top))))
|
|
texture_top + self.p.body_bottom_ratio * (window[3] - texture_top))))
|
|
@@ -1443,38 +1551,21 @@ class EvidenceV2:
|
|
|
bx0 = max(0, int(round(self.p.body_x_margin_ratio * ww)))
|
|
bx0 = max(0, int(round(self.p.body_x_margin_ratio * ww)))
|
|
|
bx1 = min(ww - 1, int(round((1.0 - self.p.body_x_margin_ratio) * ww)))
|
|
bx1 = min(ww - 1, int(round((1.0 - self.p.body_x_margin_ratio) * ww)))
|
|
|
body_roi = (bx0, by0, bx1, by1)
|
|
body_roi = (bx0, by0, bx1, by1)
|
|
|
- bst = detect_structure_v2(
|
|
|
|
|
- gray, body_roi,
|
|
|
|
|
- min_post_len_ratio=self.p.min_post_len_ratio,
|
|
|
|
|
- cluster_gap_px=9.0, scale=scale,
|
|
|
|
|
- )
|
|
|
|
|
- bpos = bst.get("post_positions") or []
|
|
|
|
|
- bspan = (
|
|
|
|
|
- (max(bpos) - min(bpos)) / max(1.0, float(body_roi[2] - body_roi[0]))
|
|
|
|
|
- if len(bpos) >= 2 else 0.0
|
|
|
|
|
- )
|
|
|
|
|
- bground, bblocks = ground_like_ratio(
|
|
|
|
|
- gray, body_roi, bst.get("lines", []), # type: ignore[arg-type]
|
|
|
|
|
- block_px=self.p.ground_block_px,
|
|
|
|
|
- density_lo=self.p.ground_density_lo,
|
|
|
|
|
- density_hi=self.p.ground_density_hi,
|
|
|
|
|
- )
|
|
|
|
|
- bopacity = 1.0 - bground if bblocks > 0 else 0.0
|
|
|
|
|
- bh = (by1 - by0) / max(scale, 1e-6)
|
|
|
|
|
|
|
+ b = self._measure_body(gray, body_roi, scale)
|
|
|
body_stats = {
|
|
body_stats = {
|
|
|
- "posts": int(bst["post_count"]),
|
|
|
|
|
- "diagonal": int(bst["diagonal_lines"]),
|
|
|
|
|
- "opacity": bopacity,
|
|
|
|
|
|
|
+ "posts": int(b["posts"]),
|
|
|
|
|
+ "diagonal": int(b["diagonal"]),
|
|
|
|
|
+ "opacity": float(b["opacity"]),
|
|
|
}
|
|
}
|
|
|
- if (bh >= self.p.body_min_roi_px
|
|
|
|
|
- and self.p.body_min_posts <= int(bst["post_count"]) <= self.p.max_door_posts
|
|
|
|
|
- and bspan >= self.p.min_post_span_ratio
|
|
|
|
|
- and bopacity >= self.p.body_min_opacity
|
|
|
|
|
- and int(bst["diagonal_lines"]) >= self.p.min_diagonal_braces):
|
|
|
|
|
|
|
+ if (b["height"] >= self.p.body_min_roi_px
|
|
|
|
|
+ and self.p.body_min_posts <= b["posts"] <= self.p.max_door_posts
|
|
|
|
|
+ and b["span"] >= self.p.min_post_span_ratio
|
|
|
|
|
+ and b["opacity"] >= self.p.body_min_opacity
|
|
|
|
|
+ and b["diagonal"] >= self.p.min_diagonal_braces):
|
|
|
state = 1
|
|
state = 1
|
|
|
- conf = min(1.0, 0.55 + 0.25 * min(1.0, bst["post_count"] / 8.0)
|
|
|
|
|
- + 0.15 * bopacity)
|
|
|
|
|
- hits = min(1.0, 0.40 + 0.05 * bst["post_count"] + 0.20 * bopacity)
|
|
|
|
|
|
|
+ conf = min(1.0, 0.55 + 0.25 * min(1.0, b["posts"] / 8.0)
|
|
|
|
|
+ + 0.15 * b["opacity"])
|
|
|
|
|
+ hits = min(1.0, 0.40 + 0.05 * b["posts"] + 0.20 * b["opacity"])
|
|
|
reason = "body_fallback_wall"
|
|
reason = "body_fallback_wall"
|
|
|
gap_px = 0.0
|
|
gap_px = 0.0
|
|
|
body = body_stats
|
|
body = body_stats
|