Код: Выделить всё
docMsp = doc.modelspace()
for e in doc.entities:
if e.dxftype() == 'MTEXT' or e.dxftype() == 'DIMENSION':
docMsp.delete_entity(e)
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ctx = RenderContext(doc)
out = MatplotlibBackend(ax)
cfg = config.Configuration(
background_policy=config.BackgroundPolicy.BLACK,
color_policy=config.ColorPolicy.WHITE,
)
frontend = Frontend(ctx, out, config=cfg)
frontend.draw_layout(docMsp, finalize=True)
fig.canvas.draw()
graph_image = np.array(fig.canvas.get_renderer()._renderer)
imgGray = cv2.cvtColor(graph_image, cv2.COLOR_BGR2GRAY)
img = cv2.threshold(imgGray, 120, 255, cv2.THRESH_BINARY)[1]
contours, hierarchy = cv2.findContours(img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
forms.append("Number of contours: " + str(len(contours)/2))
Код: Выделить всё
for e in doc.entities:
if e.dxftype() == 'MTEXT' or e.dxftype() == 'DIMENSION':
docMsp.delete_entity(e)
Или, может быть, другой способ обнаружить замкнутый многоугольник?
Подробнее здесь: https://stackoverflow.com/questions/790 ... ion-in-dxf