我想使用OCR仅提取CAD模型的基础尺寸,但有一些我不需要的关联尺寸(如角度、从基线到孔的长度等)。这是一个技术图纸的例子。(红色圆圈中的数字是基础尺寸,其余紫色高亮的部分是需要忽略的。) 如何告诉我的程序只提取基础尺寸(在进入CNC之前的块体的高度、长度和宽度)?
问题在于我得到的图纸没有特定的格式,所以我无法告诉OCR尺寸的位置。它必须通过上下文自己判断。
我应该通过机器学习来训练程序,运行几次迭代并进行纠正吗?如果是,哪些方法是可行的?我能想到的唯一方法是Opencv级联分类器。还有其他解决这个问题的办法吗?抱歉这篇文章有点长。谢谢。
回答:
我理解你的感受…这是一个非常棘手的问题,我们花了过去三年时间寻找解决方案。请原谅我提及自己的解决方案,但它肯定能解决你的问题:pip install werk24
from werk24 import Hook, W24AskVariantMeasuresfrom werk24.models.techread import W24TechreadMessagefrom werk24.utils import w24_read_sync from . import get_drawing_bytes # 定义你自己的 def recv_measures(message: W24TechreadMessage) -> None: for cur_measure in message.payload_dict.get('measures'): print(cur_measure) if __name__ == "__main__": # 定义你希望从API接收的信息 # 以及信息可用时要执行的操作。 hooks = [Hook(ask=W24AskVariantMeasures(), function=recv_measures)] # 向Werk24 API提交请求 w24_read_sync(get_drawing_bytes(), hooks)
在你的例子中,它将返回例如以下测量值
{ "position": <STRIPPED> "label": { "blurb": "ø30 H7 +0.0210/0", "quantity": 1, "size": { "blurb": "30", "size_type":" "DIAMETER", "nominal_size": "30.0", }, "unit": "MILLIMETER", "size_tolerance": { "toleration_type": "FIT_SIZE_ISO", "blurb": "H7", "deviation_lower": "0.0", "deviation_upper": "0.0210", "fundamental_deviation": "H", "tolerance_grade": { "grade":7, "warnings":[] }, "thread": null, "chamfer": null, "depth":null, "test_dimension": null, }, "warnings": [], "confidence": 0.98810 }
或者对于GD&T
{ "position": <STRIPPED>, "frame": { "blurb": "[⟂|0.05|A]", "characteristic": "⟂", "zone_shape": null, "zone_value": { "blurb": "0.05", "width_min": 0.05, "width_max": null, "extend_quantity": null, "extend_shape": null, "extend": null, "extend_angle": null }, "zone_combinations": [], "zone_offset": null, "zone_constraint": null, "feature_filter": null, "feature_associated": null, "feature_derived": null, "reference_association": null, "reference_parameter": null, "material_condition": null, "state": null, "data": [ { "blurb": "A" } ] }}
详细信息请查看Werk24的文档。