将下述代码增加显示边缘图像功能: import cv2 import numpy as np from dxfwrite import DXFEngine as dxf img = cv2.imread('ft.jpg', 0) edges = cv2.Canny(img, 100, 200) thresh = cv2.threshold(edges, 27, 255, cv2.THRESH_BINARY)[1] contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) dwg = dxf.drawing('output2.dxf') for contour in contours: if len(contour) > 1: dwg.add(dxf.polyline(contour[:, 0, :])) dwg.save()
时间: 2023-08-13 22:15:09 浏览: 138
图像处理代码,实现图像边缘检测
可以在代码最后添加以下代码来显示边缘图像:
```
cv2.imshow('Edges', edges)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
完整代码如下:
```
import cv2
import numpy as np
from dxfwrite import DXFEngine as dxf
img = cv2.imread('ft.jpg', 0)
edges = cv2.Canny(img, 100, 200)
thresh = cv2.threshold(edges, 27, 255, cv2.THRESH_BINARY)[1]
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
dwg = dxf.drawing('output2.dxf')
for contour in contours:
if len(contour) > 1:
dwg.add(dxf.polyline(contour[:, 0, :]))
dwg.save()
cv2.imshow('Edges', edges)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
运行代码后,会在生成的 DXF 文件同时显示边缘图像。
阅读全文