Explorar o código

feat(portcv): 空平车也输出 state=3(P0-Q10),并修掉载车被判空车

一、修危险误判(先做)
* 删除"空车竖棱门数不够就回退宽松(body_min_post_len_ratio)"的兜底:
  实测 img01(NX70A 平车+蓝箱,真值 2)在宽松门下被聚成 7 根"立柱"→ 越过
  空车门变成 3(载车被判空车);而空 C70/C70EA 在严格门下本来就够数(9/5 根)。
  删掉后 img01 = 255(安全侧),Python/C++ 两侧一致。

二、空平车判据(P0-Q10)
平车没有侧墙,空载时看到的是车底板。全部满足才判 3:
1) under_deck:薄边梁下方确有更暗带(车底透空/阴影),不是地面
2) 边梁是薄边:<= contact_max_h_ratio x 估箱高(厚亮面是地面/月台/下层箱顶)
3) 箱底不贴边梁:gap_px >= empty_flatbed_min_gap_px(16 px)
   —— 实测 01_flatcar/img00/img01 三张载车样本 gap≈0,直接排除
4) 边梁上方那段(车面纵深,<=0.25 画幅)是光滑亮面:
   竖向/横向边缘块覆盖率 <= empty_flatbed_max_plane_edge(0.12),
   灰度不低于边梁 empty_flatbed_max_gray_drop(80) —— 排除集装箱侧壁与阴影
命中 -> state=3、class_reason=empty_flatbed、gap=0;与空敞车互斥(先判侧墙)。

三、新增配置(C++/Python 同名同义,均写进 default/front/rtsp 三份)
empty_flatbed_enable / empty_flatbed_min_gap_px / empty_flatbed_max_plane_edge /
empty_flatbed_max_gray_drop

四、验证
* 七张实测图(C++ 与 Python 一致):
  01_flatcar -> 2、02_C70E -> 3、03_C70EA -> 3、04_container_on_gondola -> 1、
  img00(平车+白箱) -> 2、img01(平车+蓝箱) -> 255(原误判 3)、img02(C70+罐箱) -> 1
* A 段(C70+罐箱):发布 1x43 / 0x7,无 2、无 3
* B 段(X70+干箱):发布 2x18 / 0x32,无 1、无 3(与 P0-Q9 基线逐帧一致)
* Python:test_evidence_v2 42 项(新增 EmptyFlatbedTests 4 项)+ 相关模块 89 项全绿
* C++:ctest 8/8(selftest_edge_v2 新增空平车 7 项断言:合成空平车 -> 3 且 commit、
  平车+箱不得 3、开关关闭不得 3)
* check_configs 8/8、gen_cpp_constants --check OK

五、数据缺口(未写成已验证)
仓库与现有素材里没有一张"空平车"图/视频;上述阈值由"载车 gap≈0"三点实测 +
合成空平车场景支撑。真机召回/误报需现场补拍空平车片段后签收;
empty_flatbed_enable=false 可一键回退为 255。
kwass hai 3 días
pai
achega
7010e32dd0

+ 2 - 2
README.md

@@ -30,7 +30,7 @@ git push -u origin develop      # 推到 Gitee 私有库(首次需认证,见
 
 分支模型、提交规范、发布检查清单、回滚与远程仓库接入:见
 **[docs/git_workflow.md](docs/git_workflow.md)**。
-提交钩子(`.githooks/pre-commit`,跑 353 项单测)需每人执行一次
+提交钩子(`.githooks/pre-commit`,跑 357 项单测)需每人执行一次
 `git config core.hooksPath .githooks` 才会生效。
 
 远端:`origin` = `https://gitee.com/kwass122/hengda--kwass.git`(**私有库**)。
@@ -195,7 +195,7 @@ cmake -S cpp -B build -DCMAKE_BUILD_TYPE=Release
 cmake --build build -j
 ctest --test-dir build --output-on-failure     # 八个自检全绿(200 / 269 / 110 / 231 / 112 / 54 / 56 / 104)
 
-# 一条命令跑完"冻结点"回归(ctest + Python 353 单测 + v1/v2 现场回放),失败即非 0 退出
+# 一条命令跑完"冻结点"回归(ctest + Python 357 单测 + v1/v2 现场回放),失败即非 0 退出
 python scripts/regression_freeze.py --build-dir build
 
 # 跑起来(PLC 用 MB_CLIENT 轮询 1502 端口读 12 个字结果区)

+ 4 - 0
configs/README.md

@@ -113,6 +113,10 @@ C++:`cpp/include/portcv/capture.hpp`),默认值与语义一致:
 | `evidence_v2.empty_min_diagonal_braces` | `1` | 空车判据的斜撑门(与 `min_diagonal_braces` 分开) |
 | `evidence_v2.empty_top_margin_ratio` | `0.0` | 车体顶相对窗口顶的最小余量;0 = 车填满画面时也用整个窗口 |
 | `evidence_v2.allow_state3` | `true` | 空车 `3` 是否允许提交(与 `commit.allow_state3` **串联**,任一 false 即只识别不提交) |
+| `evidence_v2.empty_flatbed_enable` | `true` | 空平车(车面裸露)也判 `3`;false = 只判空敞车 |
+| `evidence_v2.empty_flatbed_min_gap_px` | `16.0` | 车面纵深下限(原图像素)。载车箱底贴边梁 `gap≈0` → 直接排除 |
+| `evidence_v2.empty_flatbed_max_plane_edge` | `0.12` | 车面 ROI 竖向/横向边缘覆盖率上限(车面几乎无纹理) |
+| `evidence_v2.empty_flatbed_max_gray_drop` | `80.0` | 车面灰度相对边梁的最大下降(车面是亮面) |
 
 判据/实测见 `docs/route_v2.md` §4.2 P0-Q9、`docs/edge_evidence.md` §7.2 ⑦。
 **两道安全门**:`empty_wall_below_deck`(平车“薄车面边梁+车面下暗带”在候选墙之上 ⇒

+ 4 - 0
configs/default.json

@@ -180,6 +180,10 @@
     "empty_min_wall_h_ratio": 0.25,
     "empty_min_post_len_ratio": 0.3,
     "empty_min_diagonal_braces": 1,
+    "empty_flatbed_enable": true,
+    "empty_flatbed_min_gap_px": 16.0,
+    "empty_flatbed_max_plane_edge": 0.12,
+    "empty_flatbed_max_gray_drop": 80.0,
     "empty_top_margin_ratio": 0.0,
     "allow_state3": true,
     "min_diagonal_braces": 1,

+ 4 - 0
configs/edge-v2-front.json

@@ -107,6 +107,10 @@
     "empty_min_wall_h_ratio": 0.25,
     "empty_min_post_len_ratio": 0.3,
     "empty_min_diagonal_braces": 1,
+    "empty_flatbed_enable": true,
+    "empty_flatbed_min_gap_px": 16.0,
+    "empty_flatbed_max_plane_edge": 0.12,
+    "empty_flatbed_max_gray_drop": 80.0,
     "empty_top_margin_ratio": 0.0,
     "allow_state3": true,
     "min_wall_opacity": 0.35,

+ 4 - 0
configs/edge-v2-rtsp.json

@@ -130,6 +130,10 @@
     "empty_min_wall_h_ratio": 0.25,
     "empty_min_post_len_ratio": 0.3,
     "empty_min_diagonal_braces": 1,
+    "empty_flatbed_enable": true,
+    "empty_flatbed_min_gap_px": 16.0,
+    "empty_flatbed_max_plane_edge": 0.12,
+    "empty_flatbed_max_gray_drop": 80.0,
     "empty_top_margin_ratio": 0.0,
     "allow_state3": true,
     "min_wall_opacity": 0.35,

+ 7 - 0
cpp/include/portcv/edge_v2.hpp

@@ -137,6 +137,13 @@ struct EdgeV2Params {
     double empty_min_post_len_ratio = 0.30;
     /// 空车判据的斜撑门(与 `min_diagonal_braces` 分开,便于现场按车型单独放宽)。
     int empty_min_diagonal_braces = 1;
+    /// P0-Q10:空平车(平车、车面裸露)→ 也输出 state=3。
+    /// 与载车的本质差别:载车必然有箱底暗带紧贴(或很近)车面边梁;空平车的
+    /// “箱底”是车底板远端边缘线,与近侧边梁之间隔着整片车面(纵深 >= min_gap_px)。
+    bool empty_flatbed_enable = true;
+    double empty_flatbed_min_gap_px = 16.0;   ///< 车面纵深下限(原图像素)
+    double empty_flatbed_max_plane_edge = 0.12;  ///< 车面边缘覆盖率上限(车面几乎无纹理)
+    double empty_flatbed_max_gray_drop = 80.0;   ///< 车面灰度相对边梁的最大下降
     /// 车体顶相对搜索窗顶的最小余量(×画幅高)。0 = 不设门槛:车把画面填满
     /// (空 C70E 实测 texture_top≈2% 画幅)时也用整个窗口做侧墙 ROI。
     double empty_top_margin_ratio = 0.0;

+ 18 - 0
cpp/src/app_config.cpp

@@ -468,6 +468,10 @@ bool apply_evidence_v2(const Config& cfg, AppConfig* out, std::string* error) {
         num("evidence_v2.empty_min_wall_h_ratio", &v->empty_min_wall_h_ratio),
         num("evidence_v2.empty_min_post_len_ratio", &v->empty_min_post_len_ratio),
         integer("evidence_v2.empty_min_diagonal_braces", &v->empty_min_diagonal_braces),
+        flag("evidence_v2.empty_flatbed_enable", &v->empty_flatbed_enable),
+        num("evidence_v2.empty_flatbed_min_gap_px", &v->empty_flatbed_min_gap_px),
+        num("evidence_v2.empty_flatbed_max_plane_edge", &v->empty_flatbed_max_plane_edge),
+        num("evidence_v2.empty_flatbed_max_gray_drop", &v->empty_flatbed_max_gray_drop),
         num("evidence_v2.empty_top_margin_ratio", &v->empty_top_margin_ratio),
         flag("evidence_v2.allow_state3", &v->allow_state3),
         num("evidence_v2.min_wall_opacity", &v->min_wall_opacity),
@@ -732,6 +736,15 @@ bool validate(const AppConfig* cfg, std::string* error) {
     if (v2.empty_min_diagonal_braces < 0) {
         return bad("evidence_v2.empty_min_diagonal_braces 不能为负(0=不启用该门)");
     }
+    if (v2.empty_flatbed_min_gap_px < 0.0) {
+        return bad("evidence_v2.empty_flatbed_min_gap_px 不能为负");
+    }
+    if (v2.empty_flatbed_max_plane_edge < 0.0 || v2.empty_flatbed_max_plane_edge > 1.0) {
+        return bad("evidence_v2.empty_flatbed_max_plane_edge 必须 ∈ [0,1]");
+    }
+    if (v2.empty_flatbed_max_gray_drop < 0.0) {
+        return bad("evidence_v2.empty_flatbed_max_gray_drop 不能为负");
+    }
     if (v2.empty_min_posts < 1) {
         return bad("evidence_v2.empty_min_posts 至少为 1");
     }
@@ -1050,6 +1063,11 @@ std::string describe_app_config(const AppConfig& cfg) {
                 v2.empty_min_posts, v2.max_door_posts, v2.empty_min_span_ratio,
                 v2.empty_min_opacity, v2.empty_min_wall_h_ratio,
                 v2.empty_min_post_len_ratio, v2.empty_top_margin_ratio);
+    append_line(&out,
+                "v2空平车: enable=%d gap>=%.0fpx 车面边缘<=%.2f 灰度降<=%.0f"
+                "(薄边梁+车底透空+光滑亮车面 -> 3)\n",
+                v2.empty_flatbed_enable ? 1 : 0, v2.empty_flatbed_min_gap_px,
+                v2.empty_flatbed_max_plane_edge, v2.empty_flatbed_max_gray_drop);
     append_line(&out,
                 "v2落位: require_commit=%d gap_m<=%.2f gap_px<=%.1f stable=%d structure=%d "
                 "allow_state2=%d allow_state3=%d use_plc_arrival=%s\n",

+ 174 - 10
cpp/src/edge_v2.cpp

@@ -333,14 +333,9 @@ EmptyEvidence detect_empty_vehicle(const GrayImage& work, const int window[4],
     out.roi[3] = wy1;
     out.body = measure_body(work, bx0, wy0, bx1, wy1, p, scale,
                             p.empty_min_post_len_ratio);
-    // 低分辨率/低对比素材上,严格竖棱门可能“一根都数不到”(03_C70EA 实测 0 根),
-    // 而宽松门能数到 3 根;反过来 02_C70E 用宽松门会数到 20 根(>max_door_posts)。
-    // 所以**先严格、数不够再回退宽松**,其余门(跨度/不透明/斜撑/墙高)不变。
-    if (out.body.posts < p.empty_min_posts &&
-        p.body_min_post_len_ratio < p.empty_min_post_len_ratio) {
-        out.body = measure_body(work, bx0, wy0, bx1, wy1, p, scale,
-                                p.body_min_post_len_ratio);
-    }
+    // 不再“严格数不够就回退宽松”:实测 `img01`(NX70A 平车+蓝箱)在宽松门下会被
+    // 聚成 7 根“立柱” → 越过空车门变成 3(危险误判);空 C70/C70EA 在严格门下
+    // 本来就够数,回退没有收益。
     out.present = true;
     const double body_h_orig = out.body.height / std::max(scale, 1e-6);
     if (body_h_orig < static_cast<double>(p.body_min_roi_px)) {
@@ -394,6 +389,154 @@ EmptyEvidence detect_empty_vehicle(const GrayImage& work, const int window[4],
 }
 
 
+// P0-Q10:空平车(平车、车面裸露)证据 —— 与 Python `_detect_empty_flatbed` 同构。
+//
+// 与载车的本质差别:**载车必然有箱底暗带紧贴(或很近)车面边梁**;空平车的
+// “箱底”其实是车底板**远端边缘线**,与近侧边梁之间隔着整片车面(纵深
+// >= empty_flatbed_min_gap_px)。再要求那片车面**光滑 + 亮**,排除集装箱侧壁
+// (瓦楞/立柱 → 边缘覆盖率高)和地面(暗且纹理多)。
+struct PlaneStats {
+    bool ok = false;
+    double mean = 0.0;
+    double vcov = 0.0;
+    double hcov = 0.0;
+};
+
+/// ``[x0,x1) × [y0,y1)`` 的灰度均值(越界自动钳制;空框返回 0)。
+double row_mean(const GrayImage& gray, int x0, int x1, int y0, int y1) {
+    x0 = std::max(0, x0);
+    y0 = std::max(0, y0);
+    x1 = std::min(gray.width, x1);
+    y1 = std::min(gray.height, y1);
+    if (x1 <= x0 || y1 <= y0) { return 0.0; }
+    double sum = 0.0;
+    for (int y = y0; y < y1; ++y) {
+        for (int x = x0; x < x1; ++x) { sum += gray.at(x, y); }
+    }
+    return sum / static_cast<double>((x1 - x0) * (y1 - y0));
+}
+
+PlaneStats plane_stats(const GrayImage& gray, int x0, int y0, int x1, int y1,
+                       int block = 16, double th = 50.0, double hit = 0.03) {
+    PlaneStats out;
+    x0 = std::max(0, x0);
+    y0 = std::max(0, y0);
+    x1 = std::min(gray.width, x1);
+    y1 = std::min(gray.height, y1);
+    if (x1 - x0 < 16 || y1 - y0 < 6) { return out; }
+    const GrayImage crop = crop_gray(gray, x0, y0, x1, y1);
+    if (crop.empty()) { return out; }
+    const SobelResult grad = sobel(crop);
+    const int nb = std::max(1, crop.width / std::max(4, block));
+    int vhit = 0;
+    int hhit = 0;
+    double sum = 0.0;
+    for (int y = 0; y < crop.height; ++y) {
+        for (int x = 0; x < crop.width; ++x) { sum += crop.at(x, y); }
+    }
+    for (int b = 0; b < nb; ++b) {
+        const int xs = b * block;
+        const int xe = std::min(crop.width, xs + block);
+        if (xe <= xs) { continue; }
+        int vcnt = 0;
+        int hcnt = 0;
+        int total = 0;
+        for (int y = 0; y < crop.height; ++y) {
+            for (int x = xs; x < xe; ++x) {
+                ++total;
+                const std::size_t idx =
+                    static_cast<std::size_t>(y) * static_cast<std::size_t>(crop.width) +
+                    static_cast<std::size_t>(x);
+                if (std::fabs(grad.gx[idx]) >= static_cast<float>(th)) { ++vcnt; }
+                if (std::fabs(grad.gy[idx]) >= static_cast<float>(th)) { ++hcnt; }
+            }
+        }
+        if (total <= 0) { continue; }
+        if (static_cast<double>(vcnt) / total >= hit) { ++vhit; }
+        if (static_cast<double>(hcnt) / total >= hit) { ++hhit; }
+    }
+    out.ok = true;
+    out.mean = sum / static_cast<double>(std::max(1, crop.width * crop.height));
+    out.vcov = static_cast<double>(vhit) / nb;
+    out.hcov = static_cast<double>(hhit) / nb;
+    return out;
+}
+
+struct FlatbedEvidence {
+    bool present = false;
+    bool ok = false;
+    std::string reason;
+    double confidence = 0.0;
+    double hits = 0.0;
+    int roi[4] = {0, 0, 0, 0};
+    double depth = 0.0;
+};
+
+FlatbedEvidence detect_empty_flatbed(const GrayImage& work, const int window[4],
+                                     const V2Band& box, const V2Band& bed,
+                                     bool deck_edge, bool under_deck,
+                                     std::optional<double> gap_px,
+                                     const EdgeV2Params& p) {
+    FlatbedEvidence out;
+    if (!p.empty_flatbed_enable) { return out; }
+    if (bed.height() <= 0.0) { return out; }
+    if (!under_deck) { return out; }
+    // 边梁必须是“薄边”(厚亮面是地面/月台/下层箱顶)
+    const double est_h =
+        std::max(60.0, box.height() > 0.0
+                           ? (box.y0 - 0.05 * static_cast<double>(work.height))
+                           : 0.45 * static_cast<double>(work.height));
+    if (bed.height() > p.contact_max_h_ratio * est_h) {
+        out.reason = "empty_flatbed_thick_sill";
+        return out;
+    }
+    // 载车:箱底暗带紧贴/贴近边梁(实测 01/img00/img01 三张载车样本 gap≈0)
+    if (box.height() > 0.0) {
+        if (!gap_px.has_value() || *gap_px < p.empty_flatbed_min_gap_px) { return out; }
+    }
+    const int wh = work.height;
+    const double sill = bed.y0;
+    const double depth = gap_px.has_value() ? *gap_px : 0.0;
+    const double target_h = std::min(std::max(depth, p.empty_flatbed_min_gap_px),
+                                     0.25 * static_cast<double>(wh));
+    int plane_h = static_cast<int>(std::lround(target_h));
+    if (plane_h < 6) { plane_h = 6; }
+    const int bot = static_cast<int>(std::lround(sill));
+    const int top = std::max(window[1], bot - plane_h);
+    if (bot - top < 6) { return out; }
+    out.present = true;
+    out.roi[0] = window[0];
+    out.roi[1] = top;
+    out.roi[2] = window[2];
+    out.roi[3] = bot;
+    out.depth = depth;
+    const PlaneStats st = plane_stats(work, out.roi[0], out.roi[1], out.roi[2], out.roi[3]);
+    if (!st.ok) { return out; }
+    out.reason = "empty_flatbed_plane";
+    const int sy1 = std::max(static_cast<int>(std::lround(bed.y1)), bot + 1);
+    const double sill_mean = row_mean(work, window[0], window[2], bot, sy1);
+    if (st.vcov > p.empty_flatbed_max_plane_edge) {
+        out.reason = "empty_flatbed_texture";
+        return out;
+    }
+    if (st.hcov > p.empty_flatbed_max_plane_edge * 1.5) {
+        out.reason = "empty_flatbed_texture";
+        return out;
+    }
+    if (st.mean < sill_mean - p.empty_flatbed_max_gray_drop) {
+        out.reason = "empty_flatbed_dark";
+        return out;
+    }
+    const double edge_ratio =
+        std::min(1.0, st.vcov / std::max(1e-6, p.empty_flatbed_max_plane_edge));
+    out.ok = true;
+    out.reason = "empty_flatbed";
+    out.confidence = std::min(1.0, 0.65 + 0.20 * (1.0 - edge_ratio));
+    out.hits = std::min(1.0, 0.62 + 0.25 * (1.0 - edge_ratio));
+    return out;
+}
+
+
 std::string fmt(const char* pattern, double value) {
     char buf[128];
     std::snprintf(buf, sizeof(buf), pattern, value);
@@ -1326,6 +1469,7 @@ EvidenceV2Result EdgeV2::analyze(const GrayImage& gray, double ts, bool plc_arri
     BodyEvidence body;
     bool body_override = false;
     bool empty_override = false;
+    bool flat_override = false;
     std::string empty_reason;
     int body_y0 = 0;
     int body_y1 = 0;
@@ -1360,12 +1504,32 @@ EvidenceV2Result EdgeV2::analyze(const GrayImage& gray, double ts, bool plc_arri
         }
     }
 
+    // P0-Q10:空平车(平车、车面裸露)→ 3。与空敞车**互斥**(上面已先判敞车侧墙);
+    // 判据:薄车面边梁 + 车底透空 + 边梁上方是一片光滑亮车面(车底板),
+    // 且**没有箱底暗带紧贴边梁**(载车实测 gap≈0)。
+    if (!empty_override && final_state != 1) {
+        const FlatbedEvidence flat = detect_empty_flatbed(
+            work, window, box, bed, deck_edge, under_deck, gap_px, p_);
+        if (flat.ok) {
+            final_state = 3;
+            final_conf = flat.confidence;
+            final_hits = flat.hits;
+            final_reason = "empty_flatbed";
+            commit_gap_px = 0.0;
+            commit_gap_m = 0.0;
+            flat_override = true;
+            empty_reason = "empty_flatbed";
+        } else if (empty_reason.empty()) {
+            empty_reason = flat.reason;
+        }
+    }
+
     // 安全兜底:能看到“车体顶(上方有天空)”且正常路径给 2,但箱底以下
     // 连 1 根立柱都没有、箱体还在车体内部 → 这是空车/无箱的歧义帧,绝不判 2。
     // 注意这里用 `<=1` 而不是 `==0`:Python/C++ 的线段通道在“空敞车门板被铆钉
     // 打断”时可能给出 0 或 1 根(实测 02_C70E:C++ 0 根、Python 1 根),
     // 用 0 会让同一张图在两种实现下结论不同(2 vs 255)。
-    if (!body_override && texture_top > 0.0 && cls.state == 2 &&
+    if (!body_override && !flat_override && texture_top > 0.0 && cls.state == 2 &&
         static_cast<int>(posts.size()) <= 1 &&
         box.y1 > texture_top + 0.02 * work.height &&
         body.posts <= p_.max_door_posts &&
@@ -1383,7 +1547,7 @@ EvidenceV2Result EdgeV2::analyze(const GrayImage& gray, double ts, bool plc_arri
     out.state = final_state;
     out.confidence = final_conf;
     out.view = p_.view;
-    out.empty_vehicle = empty_override;
+    out.empty_vehicle = empty_override || flat_override;
     out.empty_reason = empty_reason;
     out.body_posts = body.posts;
     out.body_span = body.span_ratio;

+ 48 - 0
cpp/tests/selftest_edge_v2.cpp

@@ -87,6 +87,29 @@ portcv::GrayImage flat_scene(int gap_px = 4) {
     return img;
 }
 
+portcv::GrayImage empty_flatbed_scene() {
+    // P0-Q10:空平车(车底板裸露)—— 薄边梁 + 车底透空 + 光滑亮车面 + 沥青地。
+    // 与 flat_scene(平车+箱)的差别:箱底暗带不再紧贴边梁,中间隔着整片车面。
+    portcv::GrayImage img(1280, 720, 200);
+    fill_rect(&img, 0, 60, 1280, 64, 30);     // 车底板远端边缘(细暗线)
+    fill_rect(&img, 0, 64, 1280, 300, 165);   // 车底板(光滑亮面)
+    for (int y = 120; y < 300; y += 120) {    // 很淡的车面板缝
+        fill_rect(&img, 0, y, 1280, y + 2, 159);
+    }
+    fill_rect(&img, 0, 300, 1280, 304, 228);  // 近侧边梁(薄亮边)
+    fill_rect(&img, 0, 304, 1280, 334, 40);   // 车底透空(暗)
+    fill_rect(&img, 0, 334, 1280, 430, 70);   // 转向架/车底结构
+    for (int y = 430; y < 720; ++y) {         // 沥青地:亮度缓变 + 小抖动
+        const double t = static_cast<double>(y - 430) / 290.0;
+        const int base = 95 + static_cast<int>(40.0 * t);
+        for (int x = 0; x < 1280; ++x) {
+            const int j = ((x * 7919 + y * 104729) % 7) - 3;
+            img.set(x, y, static_cast<uint8_t>(std::max(0, std::min(255, base + j))));
+        }
+    }
+    return img;
+}
+
 portcv::GrayImage flat_contact_scene() {
     // 侧视 X70A:箱底与车面直接贴合(gap=0),车面边梁紧贴箱底;
     // 动态 ROI 从箱底下方开始,因此边梁本身落在 ROI 外。用于防止
@@ -362,6 +385,31 @@ int main() {
         check(last_no3.to_observation(0.6, 0, true).state == 255,
               "allow_state3=false observation abstains to 255");
     }
+    // ---------------- P0-Q10:空平车(车面裸露) ----------------
+    {
+        EdgeV2 ev(p, fast_commit());
+        portcv::EvidenceV2Result last;
+        for (int i = 0; i < 6; ++i) { last = ev.analyze(empty_flatbed_scene(), i * 0.1); }
+        std::printf("       empty-flatbed: %s\n", last.evidence_summary().c_str());
+        check(last.state == 3, "empty flatbed -> 3");
+        check(last.empty_vehicle, "empty flatbed flags empty_vehicle");
+        check(last.class_reason == "empty_flatbed", "empty flatbed reason=empty_flatbed");
+        check(last.committed, "empty flatbed commits with fast_commit");
+        check(last.to_observation(0.6, 0, true).state == 3,
+              "empty flatbed observation -> 3");
+        // 平车+箱(真值 2)绝不能落 3
+        EdgeV2 ev2(p, fast_commit());
+        portcv::EvidenceV2Result r2;
+        for (int i = 0; i < 6; ++i) { r2 = ev2.analyze(flat_scene(4), i * 0.1); }
+        std::printf("       flatcar+box: %s\n", r2.evidence_summary().c_str());
+        check(r2.state != 3, "flatcar+container never 3");
+        // 开关关闭 → 不判 3
+        portcv::EdgeV2Params off = p;
+        off.empty_flatbed_enable = false;
+        EdgeV2 ev3(off, fast_commit());
+        const auto r3 = ev3.analyze(empty_flatbed_scene(), 0.0);
+        check(r3.state != 3, "empty flatbed gate off -> not 3");
+    }
     // ---------------- P0-0 图像侧安全门 ----------------
     {
         // 直接测算子(与 Python `test_detect_hoist_high_finds_dark_bar_with_bright_sky_below`

+ 10 - 0
docs/edge_evidence.md

@@ -682,6 +682,16 @@ python scripts/replay_check.py runs/v2gate_B4.jsonl --images runs/_v2gate_B4
   `allow_state3=false`(顶层与 `commit.allow_state3` 串联)可回退为“只识别、不提交”。
   **已知边界**:空平车(无箱平车)仍不判 `3`;罐箱之类“侧壁占满画面宽度”的载车
   仍需 `0` 类负样本复核。
+* **空平车也输出 `state=3`(2026-11-20,P0-Q10)**:平车没有侧墙,空载时看到的是
+  **车底板**。判据全部满足才判:`under_deck`(边梁下方确有更暗带=车底透空)、
+  边梁是薄边(≤`contact_max_h_ratio`×估箱高)、**箱底不贴边梁**
+  (`gap_px ≥ empty_flatbed_min_gap_px`,默认 16 px;实测三张载车样本 gap≈0)、
+  边梁上方那段(车面纵深,≤0.25×画幅)是光滑亮面(`vcov/hcov ≤ 0.12`、
+  灰度降 ≤80)→ `3` + `class_reason=empty_flatbed`。与空敞车互斥(先判侧墙)。
+  **同时修掉一个危险误判**:删掉“严格竖棱门数不够就回退宽松”的兜底 ——
+  `img01`(NX70A 平车+蓝箱,真值 2)在宽松门下会被聚成 7 根“立柱”→ 误判 `3`;
+  空 C70/C70EA 在严格门下本来就够数(9/5 根)。七张实测图:`2/3/3/1` + `255/255/1`。
+  **空平车真机素材仍缺**,需现场补拍后再签收。
 * **P0-Q6 无箱兜底(2026-11-19)**:罐箱箱底被车帮完全挡住 → 整帧 `no_box`。
   此时改走“只看车体”:ROI = 整个搜索窗口,`measure_body` 数门板立柱,判据是
   **立柱跨度** ≥ `vehicle_min_span_ratio`(0.50)——敞车横跨整车

+ 2 - 2
docs/git_workflow.md

@@ -18,7 +18,7 @@
 | 首版基线 | 附注标签 `v0.1.0` —— 与本轮桌面交付包一致 |
 | 行尾策略 | `.gitattributes`:库内统一 LF,`*.bat/*.cmd/*.ps1` 检出为 CRLF |
 | 提交模板 | `.gitmessage`(`git config commit.template`) |
-| 提交钩子 | `.githooks/pre-commit`:跑 L1 单测(353 项,约 6 s) |
+| 提交钩子 | `.githooks/pre-commit`:跑 L1 单测(357 项,约 6 s) |
 | 忽略清单 | `.gitignore`:`runs/`、`build/`、`build-cmake/`、权重(`*.onnx/*.rknn/*.engine`)、`*.out/*.err`… |
 | 远端仓库 | `origin` → `git@gitee.com:kwass122/hengda--kwass.git`(Gitee **私有库**;`main`/`develop`/`v0.1.0` 已于 2026-11-09 推送,见 §6.1) |
 
@@ -260,7 +260,7 @@ git bisect good v0.1.0
 # 1) 工作区必须干净,且当前在 release/* 或 main 上
 git status -sb
 
-# 2) L1 单元测试(353 项)
+# 2) L1 单元测试(357 项)
 python -m unittest discover -s tests -q
 
 # 3) L2 契约自检(C++ 侧 8 组 1128 项断言)

+ 18 - 0
docs/route_v2.md

@@ -314,6 +314,23 @@ PLC 若只看 `state`,会把“保持的 0”误当成“已确认不在车上
 > ② 只“看得见车体结构但不够完整”时仍按旧口径弃权 `255 ambiguous_empty_vehicle`,
 > 绝不判 `1/2`。`allow_state3=false`(顶层与 `commit.allow_state3` 串联)可回退为
 > “只识别、不提交”。
+> **P0-Q10 空平车也输出 `state=3`(2026-11-20)**:平车没有侧墙,空载时直接看到
+> **车底板**。判据(与 0/1/2 同一套证据链,**全部满足**才判):
+> ① `under_deck`(薄边梁下方确实有更暗的带 = 车底透空,不是地面);
+> ② 边梁是**薄边**(≤ `contact_max_h_ratio` × 估箱高;厚亮面是地面/月台/下层箱顶);
+> ③ **没有箱底暗带紧贴边梁**:`gap_px ≥ empty_flatbed_min_gap_px`(默认 16 px)——
+> 实测 `01_flatcar`/`img00`/`img01` 三张**载车**样本 `gap≈0`,直接被排除;
+> ④ 边梁上方那一段(高度 = 车面纵深,最大 0.25×画幅)必须是**光滑亮面**:
+> 竖向/横向边缘块覆盖率 ≤ `empty_flatbed_max_plane_edge`(0.12),且灰度不低于
+> 边梁 `empty_flatbed_max_gray_drop`(80)—— 排除集装箱侧壁(瓦楞/立柱)与阴影。
+> 命中 → `state=3`、`class_reason=empty_flatbed`、`gap=0`。
+> **与空敞车互斥**:先判敞车侧墙(P0-Q9),未命中才判空平车。
+> 实测:合成空平车场景 → `3` 且 6 帧内 commit;`flat_scene`(平车+箱)→ `2`;
+> `ground`/`thick_contact`/`stacked` → 不判 3;A 发布 `1×43/0×7`、B 发布
+> `2×18/0×32`(与未加该判据时逐帧一致)。
+> **数据缺口(必须说清)**:仓库与现场素材里**没有一张空平车图/视频**,上述阈值
+> 只由"载车必须 gap≈0"这条三点实测 + 合成场景支撑;真机召回/误报需现场补拍
+> 空平车片段后再签收。`empty_flatbed_enable=false` 可一键回退为 255。
 > **注意**:对 1 px Canny 掩膜直接开运算会把车体边缘也一起删掉(实测开运算后
 > 行密度=0);正确做法是“竖向梯度块覆盖率/局部密度”,不是裸形态学开运算。
 > 若集装箱侧壁占满整个画面宽度(看不到车面/地面陪衬),跨度可能 ≥0.60 → 仍需
@@ -794,6 +811,7 @@ else:
 
 | 日期 | 变更 |
 | --- | --- |
+| 2026-11-20 | **P0-Q10 空平车也输出 `state=3`(并修掉一个危险误判)**:① 先删掉"严格竖棱门数不够就回退宽松"的兜底——实测 `img01`(NX70A 平车+蓝箱,真值 2)在宽松门下会被聚成 7 根"立柱"→ 越过空车门变成 **3**(载车被判空车);空 C70/C70EA 在严格门下本来就够数(9/5 根),回退无收益。② 新增空平车判据 `evidence_v2.empty_flatbed_*`:`under_deck` + 薄边梁 + **箱底不贴边梁**(`gap_px ≥ 16 px`;载车三样本实测 gap≈0)+ 边梁上方是光滑亮车面(`vcov/hcov ≤ 0.12`,灰度降 ≤80)→ `state=3`、`class_reason=empty_flatbed`。与空敞车互斥(先判侧墙)。③ 实测:合成空平车 → 3(6 帧 commit);`flat_scene` → 2;`ground/thick_contact/stacked` → 不判 3;七张实测图 = `2/3/3/1 + 255/255/1`(img01 由 3 修正为 255);A 发布 `1×43/0×7`、B 发布 `2×18/0×32` 与基线逐帧一致。**空平车真机素材仍缺**,阈值由合成 + 载车 gap≈0 支撑 |
 | 2026-11-20 | **P0-Q9 空车单独输出 `state=3`(取代 P0-Q7 的"空车一律 255")**:把空车逻辑从 255 里摘干净,做成独立判据 `evidence_v2.empty_*`:`texture_top` 以下侧墙 ROI 必须满足 门板立柱∈[3,16] / 跨度≥0.60 / 不透明≥0.55 / 斜撑≥1 / **可见墙高≥0.25 画幅** / **竖棱长度≥0.30×墙高**,命中→`3`(`gap=0`);只"看得见车体结构但不够完整"仍按旧口径 `255 ambiguous_empty_vehicle`。两道安全门:①`empty_wall_below_deck`(平车"薄车面边梁+车面下暗带"出现在候选墙之上 ⇒ 那是车面以下的地面,不判空车);②空车专用竖棱门(0.30 vs 兜底的 0.15,防止平车车面下方的地面碎竖棱被当成门板)。实测:`02_C70E`、`03_C70EA` 两张空车图 **255 → 3**;`01_flatcar`(posts=63)/`04_container_on_gondola`(墙高 13%) 保持 **2 / 1** 不变;`00` 合成地面/堆料仍不判 3。状态码全线放开到 `{0,1,2,3}`(schema/STATE_LABELS/PublishGate/commit/check_contract_v2/replay_check/plc_interface);新增 `allow_state3`(顶层与 `commit` 串联)。Python `test_evidence_v2.EmptyVehicleTests` 5 项 + C++ `selftest_edge_v2` 4 项 |
 | 2026-11-19 | **P0-Q8 Python/C++ 判据对齐(四张图两侧同为 2/255/255/1)**:① `_measure_body` 改用 `body_min_post_len_ratio`(0.15) —— 原用主判据的 0.30,1920 宽平车图竖棱被打断成 ≤121 px,**一根都数不到**→误判“空车歧义”;② 空车歧义的“箱底以下无立柱”由 `==0` 放宽到 `<=1`(`02_C70E`:C++ 0 根 / Python 1 根,用 0 结论不同);③ Python 补回“必须有天空”的车体兜底门(与 C++ 一致);④ **回放脚本必须按灰度解码**(`imread(..., IMREAD_GRAYSCALE)`):JPEG 经 BGR→gray 差 ±1 灰阶,`find_texture_top` 从 404 跳到 636 → 平车被判空车。`scripts/vis_evidence_v2_steps.py` 同步修好并补 NO_BOX 4 宫格 |
 | 2026-11-19 | **P0-Q7 空车口径统一(客户选择:弃权)**:两张空车图 `02_C70E`(车填满画面,`texture_top≈10`)与 `03_C70EA`(上方有天空)此前一个靠 `ambiguous_empty_vehicle` 给 255、另一个靠 `body_fallback_wall` 给 1,属**同类不同果**。现统一为 **空车(无箱)一律 255**:`body_fallback_wall` 命中车体结构只用于确认"这是空车",不再输出 1(给 1 会被 PLC 当成"箱已在车斗内")。实测:4 张图 = `2 / 255 / 255 / 1`(末张为罐箱载车,仍输出 1);`新建文件夹` 的 C70+罐箱由 255 → **1**(无箱兜底生效);A 发布 `1×40`、B 发布 `2×37`(无 false 1/2);Python `test_empty_c70_body_fallback_abstains`、C++ `empty C70 + sky wires -> 255` 钉住该口径 |

+ 1 - 1
docs/soak_7x24.md

@@ -257,6 +257,6 @@ ASAN_OPTIONS=detect_leaks=1:abort_on_error=1 \
 - 此前跑过 6 s 冒烟(`runs/soak7_final4`):PASS,4 个样本,FC4+CRC 探活 100%。
 - 质量补丁/报告脱敏/终止事件硬失败后再次跑 6 s 冒烟(`runs/soak7_postpatch6`,合成输入 + 放宽阈值):
   PASS,4 个样本、0 重启、FC4+CRC 探活 100%;仅验证链路,不是 168 h 证据。
-- 单测 `python -m unittest discover -s tests -t .` 共 184 项全部通过(当时口径;当前主线为 353 项,见 `docs/stability_soak.md`)。
+- 单测 `python -m unittest discover -s tests -t .` 共 184 项全部通过(当时口径;当前主线为 357 项,见 `docs/stability_soak.md`)。
 - **168 h 未在本聊天会话内执行**:它必须在目标板卡 + 真实 RTSP + 真实 PLC 环境连续运行;
   本页给出的是可复现的执行与验收方法,不能把 20 s 冒烟当成 7×24 结论。

+ 1 - 1
docs/stability_soak.md

@@ -96,7 +96,7 @@ CSV 每行一次采样,可直接拖进表格画曲线,也可以当交付证
 | 运行期观测量自检(p50/p95/p99 / LOW_FPS / `fps_x10`) | `portcv_rate_selftest` | **110 通过 / 0 失败**(两个变体一致) |
 | 边缘证据自检 | `portcv_edge_selftest` | **112 通过 / 0 失败**(2026-10-27:C1/F2/F3/G2 等 12 项历史失败清零) |
 | 标定记录自检(sha256 / canonical JSON 跨语言黄金向量 / 过期与漂移) | `portcv_calib_selftest` | **104 通过 / 0 失败**(2026-10-27 新增;`ctest` **8/8**) |
-| Python 回归 | `python -m unittest discover -s tests -t .` | **353 项全绿**(本机 ~6 s,2026-11-18 复核) |
+| Python 回归 | `python -m unittest discover -s tests -t .` | **357 项全绿**(本机 ~6 s,2026-11-18 复核) |
 | 配置模板校验 | `python scripts/check_configs.py` | **4/4 通过**(default / edge-cpp / jetson-rtsp / rk3588-rtsp) |
 | 默认值防漂移 | `dump_default_config.py` 与 `configs/default.json` 逐字节对比 | **完全一致**(4945 字节) |
 | 默认值防漂移 | `dump_default_config.py --stdout` 与 `configs/default.json` 逐字节对比 | **完全一致**(2815 字节) |

+ 1 - 1
docs/standard_gbt45163_5_review.md

@@ -193,7 +193,7 @@ a) 传感器标定;b) 目标识别(被吊物、位置、抓取特征、装
 | P0-6 置信度校准 | **待 P0-4 数据积累** | 按 ODD 分桶可靠性图/ECE、分对象阈值、弃权率 |
 | P0-7 试验模板 | **已完成(初版)** | `docs/test_plan_gbt45163_5.md`:L1~L5、16 条用例、ODD 矩阵、300 事件/桶、通过准则与未关闭项 |
 
-> 已执行:`python -m unittest discover -s tests -v` → **353 项通过**(含新增 `test_decision`、`test_commit`、`test_recognition`、`test_health`、`test_evidence_v2`、`test_negative_frame_regression`、`test_storage`、`test_evidence_drill`、`test_calibration`(含 `hold_on_stale` 与跨语言黄金哈希)、`test_cli_selftest` 用例)。
+> 已执行:`python -m unittest discover -s tests -v` → **357 项通过**(含新增 `test_decision`、`test_commit`、`test_recognition`、`test_health`、`test_evidence_v2`、`test_negative_frame_regression`、`test_storage`、`test_evidence_drill`、`test_calibration`(含 `hold_on_stale` 与跨语言黄金哈希)、`test_cli_selftest` 用例)。
 > 真实视频回归因原始 mp4 已不在 `C:\Users\Administrator\Videos`,本轮用 `runs/video_eval/v2_120939_annot_05_i0668.jpg` 的取证帧验证拦截;现场拿到原片后必须重跑 `scripts/video_eval.py`,验收两个负样本 **0 次 commit**。
 > **交付完整性提醒**:`build/` 在 `.gitignore` 内,凡被文档/单测引用的工具都必须迁到 `scripts/`。本轮已迁:`scripts/calib_record.py`(标定记录)、`scripts/evidence_drill.py`(证据恢复演练,**`tests/test_evidence_drill.py` 直接 import 它,不迁则交付版本单测必红**)、`scripts/video_eval.py`(L3/TP-SAFE-001 回放)、`scripts/summarize_eval.py`(回放汇总)、`scripts/verify_equiv.py`(回放复算 vs `VisionPipeline.step`,已改成 `--video` 传参)。`build/` 里剩下的 `a1_*.py`、`_probe_*.py` 等为**一次性调参/看图脚本,明确列为非交付物**,不得写进验收步骤。
 

+ 5 - 0
portcv/config.py

@@ -151,6 +151,11 @@ DEFAULTS: Dict[str, Any] = {
         "empty_min_post_len_ratio": 0.30,
         # 空车斜撑门(与 min_diagonal_braces 分开;现场可按车型单独放宽)
         "empty_min_diagonal_braces": 1,
+        # P0-Q10:空平车(车面裸露)→ 也输出 3
+        "empty_flatbed_enable": True,
+        "empty_flatbed_min_gap_px": 16.0,
+        "empty_flatbed_max_plane_edge": 0.12,
+        "empty_flatbed_max_gray_drop": 80.0,
         "empty_top_margin_ratio": 0.0,
         # 空车 3 是否允许提交(与 allow_state2 同级;false = 只识别、不提交)
         "allow_state3": True,

+ 146 - 7
portcv/logic/evidence_v2.py

@@ -148,6 +148,17 @@ class EvidenceV2Params:
     empty_min_post_len_ratio: float = 0.30
     # 空车判据的斜撑门(与 `min_diagonal_braces` 分开,便于现场按车型单独放宽)。
     empty_min_diagonal_braces: int = 1
+    # ---- P0-Q10:空平车(平车、车面裸露)→ 也输出 state=3 ----
+    # 平车没有侧墙,空载时直接看到**车底板**:薄车面边梁 + 车底透空 + 边梁上方是
+    # 一片光滑亮面(车面),且**没有箱底暗带紧贴边梁**(载车的箱底阴影必然贴着边梁,
+    # 实测 01/img00/img01 三张载车样本 gap=0)。
+    empty_flatbed_enable: bool = True
+    # 车面纵深下限(原图像素):近侧边梁 → 车面远端边缘线。载车 gap≈0 → 直接排除。
+    empty_flatbed_min_gap_px: float = 16.0
+    # 车面 ROI 的边缘覆盖率上限(竖向/横向):车面几乎无纹理,集装箱侧壁有瓦楞/立柱。
+    empty_flatbed_max_plane_edge: float = 0.12
+    # 车面灰度相对边梁的最大下降(灰阶):车面是亮面,车底/阴影/地面会明显更暗。
+    empty_flatbed_max_gray_drop: float = 80.0
     # 车体顶相对搜索窗顶的最小余量(×画幅高)。0 = 不设门槛:车把画面填满
     # (`02_C70E` 实测 texture_top≈2% 画幅)时也用整个窗口做侧墙 ROI,靠
     # `empty_*` 那组门来判断——否则“空车占满画面”这一类永远进不来。
@@ -299,6 +310,12 @@ class EvidenceV2Params:
             empty_min_wall_h_ratio=float(raw.get("empty_min_wall_h_ratio", 0.25)),
             empty_min_post_len_ratio=float(raw.get("empty_min_post_len_ratio", 0.30)),
             empty_min_diagonal_braces=int(raw.get("empty_min_diagonal_braces", 1)),
+            empty_flatbed_enable=bool(raw.get("empty_flatbed_enable", True)),
+            empty_flatbed_min_gap_px=float(raw.get("empty_flatbed_min_gap_px", 16.0)),
+            empty_flatbed_max_plane_edge=float(
+                raw.get("empty_flatbed_max_plane_edge", 0.12)),
+            empty_flatbed_max_gray_drop=float(
+                raw.get("empty_flatbed_max_gray_drop", 35.0)),
             empty_top_margin_ratio=float(raw.get("empty_top_margin_ratio", 0.0)),
             allow_state3=bool(raw.get("allow_state3", True)),
             min_diagonal_braces=int(raw.get("min_diagonal_braces", 1)),
@@ -1244,13 +1261,9 @@ class EvidenceV2:
         roi = (bx0, wy0, bx1, wy1)
         b = self._measure_body(gray, roi, scale,
                               post_len_ratio=p.empty_min_post_len_ratio)
-        # 低分辨率/低对比素材上,严格竖棱门可能“一根都数不到”(03_C70EA 512 px
-        # 实测 0 根),而宽松门能数到 3 根;反过来 02_C70E 用宽松门会数到 20 根
-        # (>max_door_posts)。所以**先严格、数不够再回退宽松**,其余门不变。
-        if (int(b["posts"]) < p.empty_min_posts
-                and p.body_min_post_len_ratio < p.empty_min_post_len_ratio):
-            b = self._measure_body(gray, roi, scale,
-                                   post_len_ratio=p.body_min_post_len_ratio)
+        # 不再“严格数不够就回退宽松”:实测 `img01`(NX70A 平车+蓝箱)在宽松门下会被
+        # 聚成 7 根“立柱” → 越过空车门变成 3(危险误判)。而空 C70(02=9 根)、
+        # 空 C70EA(03=5 根)在严格门下本来就够数,回退没有收益。
         stats = {
             "posts": int(b["posts"]),
             "span": float(b["span"]),
@@ -1305,6 +1318,107 @@ class EvidenceV2:
         out["hits"] = min(1.0, 0.45 + 0.04 * b["posts"] + 0.25 * b["opacity"])
         return out
 
+    @staticmethod
+    def _plane_stats(gray: np.ndarray, roi: Tuple[int, int, int, int],
+                     block: int = 16, th: float = 50.0,
+                     hit: float = 0.03) -> Optional[Dict[str, float]]:
+        """ROI 的灰度均值 + 竖向/横向边缘块覆盖率(与 ``find_texture_top`` 同口径)。
+
+        车底板几乎无纹理(两项覆盖率都低);集装箱侧壁有瓦楞/立柱(覆盖率高)。
+        """
+
+        x0, y0, x1, y1 = [int(v) for v in roi]
+        x0, y0 = max(0, x0), max(0, y0)
+        x1 = min(int(gray.shape[1]), x1)
+        y1 = min(int(gray.shape[0]), y1)
+        if x1 - x0 < 16 or y1 - y0 < 6:
+            return None
+        crop = gray[y0:y1, x0:x1]
+        gx = np.abs(cv2.Sobel(crop, cv2.CV_32F, 1, 0, ksize=3))
+        gy = np.abs(cv2.Sobel(crop, cv2.CV_32F, 0, 1, ksize=3))
+        nb = max(1, crop.shape[1] // block)
+        vhit = 0
+        hhit = 0
+        for b in range(nb):
+            xs = b * block
+            xe = min(crop.shape[1], xs + block)
+            if xe <= xs:
+                continue
+            if float((gx[:, xs:xe] >= th).mean()) >= hit:
+                vhit += 1
+            if float((gy[:, xs:xe] >= th).mean()) >= hit:
+                hhit += 1
+        return {
+            "mean": float(crop.mean()),
+            "vcov": vhit / float(nb),
+            "hcov": hhit / float(nb),
+        }
+
+    def _detect_empty_flatbed(self, gray: np.ndarray,
+                              window: Tuple[int, int, int, int],
+                              box, bed, deck_edge: bool, under_deck: bool,
+                              gap_px: Optional[float]) -> Optional[Dict[str, object]]:
+        """空平车(平车、车面裸露)证据 —— P0-Q10,判据见 ``EvidenceV2Params``。
+
+        与载车的本质差别:**载车必然有箱底暗带紧贴(或很近)车面边梁**,空平车的
+        “箱底”其实是车底板**远端边缘线**,与近侧边梁之间隔着整片车面(纵深
+        ≥ ``empty_flatbed_min_gap_px``)。再要求那片车面**光滑 + 亮**,排除集装箱
+        侧壁(瓦楞/立柱 → 边缘覆盖率高)和地面(暗且纹理多)。
+        """
+
+        p = self.p
+        if not p.empty_flatbed_enable:
+            return None
+        if bed is None or float(bed.height) <= 0.0:
+            return None
+        if not under_deck:
+            return None
+        # 边梁必须是“薄边”(厚亮面是地面/月台/下层箱顶)
+        est_h = max(60.0, (float(box.y0) - 0.05 * float(gray.shape[0]))
+                    if box is not None else 0.45 * float(gray.shape[0]))
+        if float(bed.height) > p.contact_max_h_ratio * est_h:
+            return {"ok": False, "reason": "empty_flatbed_thick_sill",
+                    "stats": {}, "roi": (0, 0, 0, 0)}
+        # 载车:箱底暗带紧贴/贴近边梁(实测 01/img00/img01 三张载车样本 gap≈0)
+        if box is not None and (gap_px is None
+                               or float(gap_px) < p.empty_flatbed_min_gap_px):
+            return None
+        wh, ww = gray.shape[:2]
+        sill = float(bed.y0)
+        depth = float(gap_px) if gap_px is not None else 0.0
+        plane_h = int(round(min(max(depth, p.empty_flatbed_min_gap_px), 0.25 * wh)))
+        top = max(int(window[1]), int(round(sill)) - plane_h)
+        bot = int(round(sill))
+        if bot - top < 6:
+            return None
+        roi = (int(window[0]), top, int(window[2]), bot)
+        stats = self._plane_stats(gray, roi)
+        if stats is None:
+            return None
+        sill_mean = _row_mean(gray, int(window[0]), int(window[2]),
+                              int(round(bed.y0)), max(int(round(bed.y1)), int(round(bed.y0)) + 1))
+        out: Dict[str, object] = {
+            "ok": False,
+            "reason": "empty_flatbed_plane",
+            "stats": dict(stats, sill_mean=sill_mean, plane_h=bot - top, depth=depth),
+            "roi": roi,
+        }
+        if stats["vcov"] > p.empty_flatbed_max_plane_edge:
+            out["reason"] = "empty_flatbed_texture"
+            return out
+        if stats["hcov"] > p.empty_flatbed_max_plane_edge * 1.5:
+            out["reason"] = "empty_flatbed_texture"
+            return out
+        if stats["mean"] < sill_mean - p.empty_flatbed_max_gray_drop:
+            out["reason"] = "empty_flatbed_dark"
+            return out
+        edge_ratio = min(1.0, stats["vcov"] / max(1e-6, p.empty_flatbed_max_plane_edge))
+        out["ok"] = True
+        out["reason"] = "empty_flatbed"
+        out["confidence"] = min(1.0, 0.65 + 0.20 * (1.0 - edge_ratio))
+        out["hits"] = min(1.0, 0.62 + 0.25 * (1.0 - edge_ratio))
+        return out
+
     def _measure_body(self, gray: np.ndarray, roi: Tuple[int, int, int, int],
                       scale: float,
                       post_len_ratio: Optional[float] = None) -> Dict[str, float]:
@@ -1735,6 +1849,7 @@ class EvidenceV2:
         body_roi = None
         empty_flag = False
         empty_reason = ""
+        flat_stats: Optional[Dict[str, float]] = None
         # P0-Q9:空车识别(state=3)。判据只看 texture_top 以下那一片**敞车侧墙**:
         # 完整的一节空敞车侧墙 → 3;只是“看得见车体结构但不够完整” → 保持旧的
         # 弃权口径(255 ambiguous_empty_vehicle),绝不判 1/2。
@@ -1770,6 +1885,29 @@ class EvidenceV2:
                     hits = 0.0
                     reason = "ambiguous_empty_vehicle"
                     body_stats = estats
+        # P0-Q10:空平车(平车、车面裸露)→ 也输出 3。
+        # 与空敞车**互斥**:上面已先判敞车侧墙;这里是“薄车面边梁 + 车底透空 +
+        # 边梁上方是一片光滑亮车面 + 没有箱底紧贴边梁”。载车(01/img00/img01)
+        # 的箱底暗带 gap≈0 → 直接排除。
+        if not empty_flag and state != 1:
+            flat = self._detect_empty_flatbed(
+                gray, window,
+                box if box is not None and float(box.height) > 0.0 else None,
+                bed if bed is not None and float(bed.height) > 0.0 else None,
+                bool(deck_edge), bool(under_deck), gap_px,
+            )
+            if flat is not None:
+                if flat.get("ok"):
+                    state = 3
+                    conf = float(flat["confidence"])
+                    hits = float(flat["hits"])
+                    reason = "empty_flatbed"
+                    gap_px = 0.0
+                    empty_flag = True
+                    empty_reason = "empty_flatbed"
+                    flat_stats = dict(flat["stats"])  # type: ignore[arg-type]
+                elif not empty_reason:
+                    empty_reason = str(flat.get("reason") or "")
         gap_m = (
             None if gap_px is None or px_per_m is None or px_per_m <= 0.0
             else gap_px / px_per_m
@@ -1858,6 +1996,7 @@ class EvidenceV2:
                 "body_fallback": bool(body),
                 "empty_vehicle": bool(empty_flag),
                 "empty_reason": empty_reason,
+                "empty_flatbed": flat_stats,
                 "body_wall_h_ratio": (
                     None if not body_stats else body_stats.get("wall_h_ratio")
                 ),

+ 57 - 0
tests/test_evidence_v2.py

@@ -94,6 +94,28 @@ def flat_contact_scene() -> np.ndarray:
     return image
 
 
+def empty_flatbed_scene(*, deck_gray: int = 165, sill_gray: int = 228) -> np.ndarray:
+    """P0-Q10:空平车(车底板裸露)—— 薄边梁 + 车底透空 + 光滑亮车面 + 地面。
+
+    与 ``flat_scene``(平车+箱)的差别:箱底暗带不再紧贴边梁,中间隔着整片车面。
+    """
+
+    h, w = 720, 1280
+    image = np.full((h, w), 200, dtype=np.uint8)   # 天空/背景
+    image[60:64, :] = 30                            # 车底板远端边缘(细暗线 → 被当成“箱底”)
+    image[64:300, :] = deck_gray                    # 车底板(光滑亮面)
+    for y in range(120, 300, 120):                  # 车面板缝(很淡的横缝)
+        image[y:y + 2, :] = deck_gray - 6
+    image[300:304, :] = sill_gray                   # 近侧边梁(薄亮边)
+    image[304:334, :] = 40                          # 车底透空(暗)
+    image[334:430, :] = 70                          # 转向架/车底结构(暗)
+    rng = np.random.default_rng(20261120)
+    ramp = np.linspace(95, 135, h - 430).reshape(-1, 1)
+    jitter = rng.integers(-3, 4, size=(h - 430, w))
+    image[430:, :] = np.clip(ramp + jitter, 0, 255).astype(np.uint8)  # 沥青地
+    return image
+
+
 def make(params: EvidenceV2Params, tracker: CommitTracker | None = None) -> EvidenceV2:
     return EvidenceV2(params, tracker)
 
@@ -332,6 +354,41 @@ class EmptyVehicleTests(unittest.TestCase):
         self.assertTrue(params.require_commit)
 
 
+class EmptyFlatbedTests(unittest.TestCase):
+    """P0-Q10:空平车(车面裸露)也输出 3;载车/地面绝不落 3。"""
+
+    def test_empty_flatbed_is_state3_and_commits(self):
+        ev = EvidenceV2(EvidenceV2Params(px_per_m=115.6),
+                        CommitTracker(CommitParams(stable_frames=3, structure_frames=3)))
+        last = None
+        for i in range(6):
+            last = ev.analyze(empty_flatbed_scene(), ts=i * 0.1)
+        self.assertIsNotNone(last)
+        self.assertEqual(last.state, 3, last.to_dict())
+        self.assertEqual(last.class_reason, "empty_flatbed", last.to_dict())
+        self.assertTrue(last.committed, last.to_dict())
+        self.assertEqual(last.to_observation(ts=0.6, require_commit=True).state, 3)
+
+    def test_flatcar_with_container_is_not_empty(self):
+        ev = make(EvidenceV2Params(px_per_m=115.6, require_commit=False))
+        for image in (flat_scene(), flat_contact_scene()):
+            result = ev.analyze(image, ts=0.0)
+            self.assertNotEqual(result.state, 3, result.to_dict())
+            self.assertFalse(result.empty_vehicle, result.to_dict())
+
+    def test_ground_and_stack_never_empty_flatbed(self):
+        ev = make(EvidenceV2Params(px_per_m=115.6, require_commit=False))
+        for image in (ground_scene(), thick_contact_scene(), stacked_scene()):
+            result = ev.analyze(image, ts=0.0)
+            self.assertNotEqual(result.state, 3, result.to_dict())
+
+    def test_flatbed_gate_can_be_disabled(self):
+        ev = make(EvidenceV2Params(px_per_m=115.6, require_commit=False,
+                                   empty_flatbed_enable=False))
+        result = ev.analyze(empty_flatbed_scene(), ts=0.0)
+        self.assertNotEqual(result.state, 3, result.to_dict())
+
+
 class GroundStackSafetyTests(unittest.TestCase):
     """P0-Q3:地面/堆料/堆叠箱不得被判成 1(敞车)或 2(平车)。"""