feat: 新增 CAD 元素识别模块,支持柱子/文字/墙体候选检测

- 新增 element_detector.py,包含 ColumnDetector、TextExtractor、WallCandidateDetector
- ColumnDetector:通过 INSERT 块名关键词识别柱子候选
- TextExtractor:提取 TEXT/MTEXT 内容、坐标、图层
- WallCandidateDetector:按长度阈值筛选 LINE/LWPOLYLINE,排除标注图层
- 采用 OOP 设计,所有规则可配置,保留原始 handle 追溯
- 输出 element_detection.json 和 element_report.txt
- 更新 main.py 集成元素识别步骤
This commit is contained in:
zwt13703
2026-07-08 14:39:54 +08:00
parent 9feeb14910
commit 4983048268
3 changed files with 481 additions and 0 deletions
+23
View File
@@ -7,6 +7,7 @@ import ezdxf
from layer_analysis import analyze_layers
from entity_analysis import analyze_entities
from element_detector import ElementDetector
# 路径配置
BASE_DIR = Path(__file__).parent.parent.parent
@@ -143,6 +144,28 @@ def main():
)
print(f"JSON 已保存到: {output_json}")
# ========== 第二阶段:元素识别 ==========
print(f"\n{'' * 56}")
print(f" 开始元素识别...")
detector = ElementDetector()
detection_result = detector.detect_all(doc)
# 输出元素检测 JSON
detection_json = OUTPUT_DIR / f"{DXF_FILE.stem}_element_detection.json"
detection_json.write_text(
json.dumps(detection_result, ensure_ascii=False, indent=2),
encoding="utf-8",
)
print(f"元素检测结果已保存到: {detection_json}")
# 输出统计报告
from element_detector import generate_report
report = generate_report(detection_result)
report_path = OUTPUT_DIR / f"{DXF_FILE.stem}_element_report.txt"
report_path.write_text(report, encoding="utf-8")
print(f"分析报告已保存到: {report_path}")
print(report)
if __name__ == "__main__":
main()