|
|
@@ -5,9 +5,11 @@
|
|
|
``docs/route_v2.md`` §2–§4 与 P0 实测(``docs/evidence/p0_v2``):
|
|
|
|
|
|
* **1(敞车)**:箱底以下是一整面不透明侧墙,门板立柱 ``8–14`` 根、
|
|
|
- 立柱间距有规律,斜撑/矩形门可作加分;
|
|
|
+ 立柱间距有规律,斜撑/矩形门可作加分;**贴合形态**(箱底与墙顶/箱顶贴住)
|
|
|
+ 必须有"八"字斜撑,防"上层箱坐在下层箱上"被判 1;
|
|
|
* **2(平车)**:箱底以下只有薄车面边梁,下方透空,能看到地面/植被;
|
|
|
- 门板立柱 ``0–4`` 根;
|
|
|
+ 门板立柱 ``0–4`` 根;**边梁必须是薄边,且下方有车底空隙/阴影暗带**,
|
|
|
+ 否则地面/堆料/下层箱顶会被误判 2;
|
|
|
* **0(其他)**:只有连续地面,既无门板阵列也无可信车面边梁。
|
|
|
|
|
|
与 v1 的区别
|
|
|
@@ -93,6 +95,14 @@ class EvidenceV2Params:
|
|
|
flat_max_door_posts: int = 4
|
|
|
max_post_spacing_cv: float = 6.0
|
|
|
min_post_len_ratio: float = 0.30
|
|
|
+ # P0-Q3:门板立柱间距下限(**原图像素**)。容器侧壁瓦楞周期通常 10~20 px,
|
|
|
+ # C70 门板立柱 63~185 px(docs/edge_evidence.md §4.1)→ 低于该值不构成门板阵列。
|
|
|
+ # 没有这条时,"上层箱坐在下层箱上"会把下层箱的瓦楞当成车斗门板 → 误判 1。
|
|
|
+ min_post_spacing_px: float = 24.0
|
|
|
+ # P0-Q3:`1`(敞车)还必须有"八"字斜撑/三角撑证据(docs/edge_evidence.md §4.1)。
|
|
|
+ # 容器侧壁只有瓦楞、没有斜撑 → 防"上层箱坐在下层箱上"被判成敞车。
|
|
|
+ # 0 = 关闭该门(只用于对照实验,现场不要关)。
|
|
|
+ min_diagonal_braces: int = 1
|
|
|
min_wall_opacity: float = 0.35
|
|
|
max_flat_gap_px: float = 40.0
|
|
|
wall_edge_density_ref: float = 0.14
|
|
|
@@ -103,6 +113,15 @@ class EvidenceV2Params:
|
|
|
min_flat_ground_ratio: float = 0.40
|
|
|
min_zero_ground_ratio: float = 0.65
|
|
|
deck_min_len_ratio: float = 0.30
|
|
|
+ # P0-Q3:`2`(平车)必须是"薄车面边梁 + 车面下方暗带"。
|
|
|
+ # 箱底紧贴的亮带若比 contact_max_h_ratio × 估箱高更厚,它不是车面边梁,
|
|
|
+ # 而是地面 / 下层箱顶 / 月台 / 货台等大平面 → 不当作车面、不判 2。
|
|
|
+ contact_max_h_ratio: float = 0.12
|
|
|
+ # 车面亮带下方必须在 under_deck_search_h_ratio × 画幅内找到一条更暗的
|
|
|
+ # under_deck_min_h_ratio × 画幅高的带(车底空隙/阴影);找不到 → 不判 2。
|
|
|
+ under_deck_dark_delta: float = 12.0
|
|
|
+ under_deck_min_h_ratio: float = 0.01
|
|
|
+ under_deck_search_h_ratio: float = 0.10
|
|
|
box_height_m: float = 2.591
|
|
|
px_per_m: float = 0.0
|
|
|
min_scale_px: float = 60.0
|
|
|
@@ -134,6 +153,18 @@ class EvidenceV2Params:
|
|
|
raise ValueError("below_height_ratio 必须为正")
|
|
|
if self.min_door_posts < 1:
|
|
|
raise ValueError("min_door_posts 至少 1")
|
|
|
+ if not 0.0 < self.contact_max_h_ratio <= 0.5:
|
|
|
+ raise ValueError("contact_max_h_ratio 必须在 (0,0.5]")
|
|
|
+ if self.under_deck_dark_delta < 0.0:
|
|
|
+ raise ValueError("under_deck_dark_delta 不能为负")
|
|
|
+ if not 0.0 < self.under_deck_min_h_ratio <= 0.1:
|
|
|
+ raise ValueError("under_deck_min_h_ratio 必须在 (0,0.1]")
|
|
|
+ if not 0.0 < self.under_deck_search_h_ratio <= 0.5:
|
|
|
+ raise ValueError("under_deck_search_h_ratio 必须在 (0,0.5]")
|
|
|
+ if self.min_post_spacing_px < 0.0:
|
|
|
+ raise ValueError("min_post_spacing_px 不能为负")
|
|
|
+ if self.min_diagonal_braces < 0:
|
|
|
+ raise ValueError("min_diagonal_braces 不能为负")
|
|
|
if self.box_height_m <= 0.0:
|
|
|
raise ValueError("box_height_m 必须为正")
|
|
|
|
|
|
@@ -161,6 +192,8 @@ class EvidenceV2Params:
|
|
|
flat_max_door_posts=int(raw.get("flat_max_door_posts", 4)),
|
|
|
max_post_spacing_cv=float(raw.get("max_post_spacing_cv", 6.0)),
|
|
|
min_post_len_ratio=float(raw.get("min_post_len_ratio", 0.30)),
|
|
|
+ min_post_spacing_px=float(raw.get("min_post_spacing_px", 24.0)),
|
|
|
+ min_diagonal_braces=int(raw.get("min_diagonal_braces", 1)),
|
|
|
min_wall_opacity=float(raw.get("min_wall_opacity", 0.35)),
|
|
|
max_flat_gap_px=float(raw.get("max_flat_gap_px", 40.0)),
|
|
|
wall_edge_density_ref=float(raw.get("wall_edge_density_ref", 0.14)),
|
|
|
@@ -171,6 +204,10 @@ class EvidenceV2Params:
|
|
|
min_flat_ground_ratio=float(raw.get("min_flat_ground_ratio", 0.40)),
|
|
|
min_zero_ground_ratio=float(raw.get("min_zero_ground_ratio", 0.65)),
|
|
|
deck_min_len_ratio=float(raw.get("deck_min_len_ratio", 0.30)),
|
|
|
+ contact_max_h_ratio=float(raw.get("contact_max_h_ratio", 0.12)),
|
|
|
+ under_deck_dark_delta=float(raw.get("under_deck_dark_delta", 12.0)),
|
|
|
+ under_deck_min_h_ratio=float(raw.get("under_deck_min_h_ratio", 0.01)),
|
|
|
+ under_deck_search_h_ratio=float(raw.get("under_deck_search_h_ratio", 0.10)),
|
|
|
box_height_m=float(raw.get("box_height_m", 2.591)),
|
|
|
px_per_m=float(raw.get("px_per_m", 0.0)),
|
|
|
min_scale_px=float(raw.get("min_scale_px", 60.0)),
|
|
|
@@ -210,6 +247,7 @@ class EvidenceV2Result:
|
|
|
diagonal_braces: int = 0
|
|
|
wall_opacity: float = 0.0
|
|
|
deck_edge: bool = False
|
|
|
+ under_deck: bool = False
|
|
|
wheel_count: int = 0
|
|
|
ground_ratio: float = 0.0
|
|
|
phase: CommitPhase = CommitPhase.T1
|
|
|
@@ -252,11 +290,13 @@ class EvidenceV2Result:
|
|
|
ok = self.publishable(require_commit)
|
|
|
state = int(self.state) if ok else int(SceneState.UNKNOWN)
|
|
|
conf = float(self.confidence) if ok else 0.0
|
|
|
- reason = "v2:%s view=%s posts=%d opacity=%.2f gap=%s commit=%s hoist=%d" % (
|
|
|
+ reason = "v2:%s view=%s posts=%d opacity=%.2f deck=%d under_deck=%d gap=%s commit=%s hoist=%d" % (
|
|
|
"ok" if ok else "abstain",
|
|
|
self.view.value,
|
|
|
int(self.door_posts),
|
|
|
float(self.wall_opacity),
|
|
|
+ int(bool(self.deck_edge)),
|
|
|
+ int(bool(self.under_deck)),
|
|
|
"n/a" if self.gap_px is None else "%.0fpx" % self.gap_px,
|
|
|
self.commit_reason,
|
|
|
int(bool(self.hoist_high)),
|
|
|
@@ -292,6 +332,7 @@ class EvidenceV2Result:
|
|
|
"diagonal_braces": int(self.diagonal_braces),
|
|
|
"wall_opacity": round(float(self.wall_opacity), 3),
|
|
|
"deck_edge": bool(self.deck_edge),
|
|
|
+ "under_deck": bool(self.under_deck),
|
|
|
"wheel_count": int(self.wheel_count),
|
|
|
"ground_ratio": round(float(self.ground_ratio), 3),
|
|
|
"phase": self.phase.value,
|
|
|
@@ -325,6 +366,19 @@ def _to_gray(image: np.ndarray) -> np.ndarray:
|
|
|
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
|
|
|
|
|
|
|
|
+def _row_mean(gray: np.ndarray, x0: int, x1: int, y0: int, y1: int) -> float:
|
|
|
+ """``[x0,x1) × [y0,y1)`` 的灰度均值(越界自动钳制;空框返回 0)。"""
|
|
|
+
|
|
|
+ h, w = gray.shape[:2]
|
|
|
+ xa = max(0, min(int(x0), w))
|
|
|
+ xb = max(xa, min(int(x1), w))
|
|
|
+ ya = max(0, min(int(y0), h))
|
|
|
+ yb = max(ya, min(int(y1), h))
|
|
|
+ if xb <= xa or yb <= ya:
|
|
|
+ return 0.0
|
|
|
+ return float(gray[ya:yb, xa:xb].mean())
|
|
|
+
|
|
|
+
|
|
|
def horizontal_bands(
|
|
|
gray: np.ndarray,
|
|
|
roi: Tuple[int, int, int, int],
|
|
|
@@ -855,25 +909,50 @@ class EvidenceV2:
|
|
|
gap_px: Optional[float],
|
|
|
motion_ok: bool,
|
|
|
view: ViewMode,
|
|
|
+ under_deck: bool = False,
|
|
|
+ post_spacing_px: Optional[float] = None,
|
|
|
+ diagonal_braces: int = 0,
|
|
|
) -> Tuple[int, float, float, str]:
|
|
|
- """返回 ``(state, confidence, structure_hits, reason)``。"""
|
|
|
+ """返回 ``(state, confidence, structure_hits, reason)``。
|
|
|
+
|
|
|
+ ``under_deck``:车面亮带下方是否找到"车底空隙/阴影"暗带(P0-Q3)。
|
|
|
+ ``post_spacing_px``:门板立柱间距(**原图像素**);容器瓦楞 10~20 px,
|
|
|
+ C70 门板 63~185 px。``None``/``<=0`` 表示不可用(不因此拒绝)。
|
|
|
+ """
|
|
|
|
|
|
if view == ViewMode.UNKNOWN:
|
|
|
return int(SceneState.UNKNOWN), 0.0, 0.0, "view_unknown"
|
|
|
if not motion_ok:
|
|
|
return int(SceneState.UNKNOWN), 0.0, 0.0, "motion"
|
|
|
|
|
|
+ spacing_ok = (
|
|
|
+ post_spacing_px is None
|
|
|
+ or float(post_spacing_px) <= 0.0
|
|
|
+ or float(post_spacing_px) >= self.p.min_post_spacing_px
|
|
|
+ )
|
|
|
+ # P0-Q3:只在"箱底与车面/箱顶贴合"(gap<=1px)时才要求"八"字斜撑。
|
|
|
+ # 真实 C70 在 T1 窗口箱底高于墙顶(A ≈25 px),不应因斜撑不可见被弃权;
|
|
|
+ # 而"上层箱坐在下层箱上/箱直接坐地"是贴合形态,必须有门板结构才判 1。
|
|
|
+ contact_bed = gap_px is None or float(gap_px) <= 1.0
|
|
|
+ doors_ok = (not contact_bed) or (
|
|
|
+ int(diagonal_braces) >= self.p.min_diagonal_braces
|
|
|
+ )
|
|
|
bed_strong = (
|
|
|
self.p.min_door_posts <= posts <= self.p.max_door_posts
|
|
|
and opacity >= self.p.min_wall_opacity
|
|
|
and (gap_px is None or gap_px <= self.p.max_bed_gap_px)
|
|
|
and (spacing_cv is None or spacing_cv <= self.p.max_post_spacing_cv)
|
|
|
+ and spacing_ok
|
|
|
+ and doors_ok
|
|
|
)
|
|
|
- # 平车:没有门板阵列 + 箱底下有可见车面边梁。地面比例只作置信度加分:
|
|
|
- # B 的落位帧里车面本身占满动态 ROI,分块“地面样”会偏低。
|
|
|
+ # 平车:没有门板阵列 + 箱底下有可见车面边梁 + 边梁下方有"车底空隙/阴影"。
|
|
|
+ # `under_deck` 是 P0-Q3 加的硬门:地面/堆场/下层箱顶只有亮面,
|
|
|
+ # 找不到这条暗带 → 不判 2(宁可 255,绝不允许把地面堆料当平车)。
|
|
|
+ # 地面比例只作置信度加分:B 的落位帧里车面本身占满动态 ROI,分块“地面样”会偏低。
|
|
|
flat_strong = (
|
|
|
posts <= self.p.flat_max_door_posts
|
|
|
and deck
|
|
|
+ and under_deck
|
|
|
and (gap_px is None or gap_px <= self.p.max_flat_gap_px)
|
|
|
)
|
|
|
|
|
|
@@ -989,6 +1068,16 @@ class EvidenceV2:
|
|
|
below = [b for b in bright if b.y0 >= box.y1 - 1.0]
|
|
|
bed = min(below, key=lambda b: b.y0) if below else None
|
|
|
|
|
|
+ # P0-Q3:箱底紧贴的亮带若"太厚",它不是车面边梁,而是地面/下层箱顶/
|
|
|
+ # 月台/货台等大平面。把它当车面会在地面堆料场景误判 2(验收口径里
|
|
|
+ # `2` 的误报优先级最高)。厚度门以"估箱高"为基准,避免受分辨率影响。
|
|
|
+ est_h = max(60.0, box.y0 - 0.05 * wh)
|
|
|
+ thick_contact = False
|
|
|
+ if bed is not None and bed.y0 <= box.y1 + 1.0:
|
|
|
+ if (bed.y1 - bed.y0) > self.p.contact_max_h_ratio * est_h:
|
|
|
+ thick_contact = True
|
|
|
+ bed = None
|
|
|
+
|
|
|
px_per_m, vertical_run = self._scale_from_vertical(gray, box, window, scale)
|
|
|
box_h_px = None
|
|
|
if px_per_m is not None:
|
|
|
@@ -1065,7 +1154,7 @@ class EvidenceV2:
|
|
|
hoist_cues["source"] = "image_rows"
|
|
|
|
|
|
# 动态 ROI:y 从本帧箱底下沿开始,绝不复用 P0 固定 y=475..619。
|
|
|
- est_h = max(60.0, box.y0 - 0.05 * wh)
|
|
|
+ # (est_h 在"贴合亮带厚度门"处已算好,此处复用。)
|
|
|
# 起点要越过箱体下侧梁/车体上缘的强横线:从箱底下方约 7% 箱高开始。
|
|
|
# 但若箱底已经贴近画面底边,剩余高度不足以再跳过 7%,就只留 2 px
|
|
|
# 保护带。否则整段动态 ROI 会落到画面外,平车的车面边梁/地板线
|
|
|
@@ -1117,6 +1206,26 @@ class EvidenceV2:
|
|
|
for seg in structure.get("horizontal", []) # type: ignore[union-attr]
|
|
|
)
|
|
|
wheels = self._wheel_count(gray, below_work, scale)
|
|
|
+ # P0-Q3:`2` 必须"薄车面边梁 + 车面下方暗带(车底空隙/阴影)"。
|
|
|
+ # 地面/堆场/下层箱顶只有连续亮面,找不到这条暗带 → deck 不成立 → 不判 2。
|
|
|
+ # 这里是**收紧**:找不到暗带时宁可 255,也不猜成平车(验收口径:误报优先)。
|
|
|
+ under_deck = False
|
|
|
+ if bed is not None and (bed.y1 - bed.y0) > 0.0:
|
|
|
+ band_mean = _row_mean(gray, window[0], window[2], bed.y0, bed.y1)
|
|
|
+ probe_h = max(2, int(round(self.p.under_deck_min_h_ratio * wh)))
|
|
|
+ search_h = max(probe_h + 1, int(round(self.p.under_deck_search_h_ratio * wh)))
|
|
|
+ probe_y0 = max(0, int(round(bed.y1)))
|
|
|
+ probe_y1 = min(wh - 1, probe_y0 + search_h)
|
|
|
+ darkest = None
|
|
|
+ for y in range(probe_y0, max(probe_y0 + 1, probe_y1 - probe_h + 1)):
|
|
|
+ value = _row_mean(gray, window[0], window[2], y, y + probe_h)
|
|
|
+ if darkest is None or value < darkest:
|
|
|
+ darkest = value
|
|
|
+ under_deck = (
|
|
|
+ darkest is not None
|
|
|
+ and darkest <= band_mean - self.p.under_deck_dark_delta
|
|
|
+ )
|
|
|
+ deck_edge = bool(deck_edge and under_deck)
|
|
|
gap_px = None
|
|
|
if bed is not None:
|
|
|
gap_px = max(0.0, (bed.y0 - box.y1) / max(scale, 1e-6))
|
|
|
@@ -1131,6 +1240,12 @@ class EvidenceV2:
|
|
|
gap_px=gap_px,
|
|
|
motion_ok=motion_ok,
|
|
|
view=self.p.view,
|
|
|
+ under_deck=under_deck,
|
|
|
+ post_spacing_px=(
|
|
|
+ None if spacing_median is None
|
|
|
+ else float(spacing_median) / max(scale, 1e-6)
|
|
|
+ ),
|
|
|
+ diagonal_braces=int(structure["diagonal_lines"]),
|
|
|
)
|
|
|
gap_m = (
|
|
|
None if gap_px is None or px_per_m is None or px_per_m <= 0.0
|
|
|
@@ -1171,6 +1286,7 @@ class EvidenceV2:
|
|
|
diagonal_braces=int(structure["diagonal_lines"]),
|
|
|
wall_opacity=opacity,
|
|
|
deck_edge=bool(deck_edge),
|
|
|
+ under_deck=bool(under_deck),
|
|
|
wheel_count=int(wheels),
|
|
|
ground_ratio=ground,
|
|
|
phase=phase,
|
|
|
@@ -1192,6 +1308,8 @@ class EvidenceV2:
|
|
|
"class_reason": reason,
|
|
|
"box_band": [round(box.y0 / scale, 2), round(box.y1 / scale, 2)],
|
|
|
"bed_band": None if bed is None else [round(bed.y0 / scale, 2), round(bed.y1 / scale, 2)],
|
|
|
+ "under_deck": bool(under_deck),
|
|
|
+ "thick_contact": bool(thick_contact),
|
|
|
"vertical_run_px": None if vertical_run is None else round(vertical_run / scale, 2),
|
|
|
"motion_diff": round(motion_diff, 2),
|
|
|
"motion_ratio": round(motion_ratio, 3),
|