Lax*_*man 4 python svg opencv contour opencv-contour
我正在使用openCV和python从图像中提取轮廓.现在我需要将这些轮廓路径(列表)导出为svg路径.我怎样才能做到这一点?
码:
ret,thresh = cv2.threshold(imgray,27,25,0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL , cv2.CHAIN_APPROX_TC89_L1)
print(type(contours)) #type list
Run Code Online (Sandbox Code Playgroud)
问题已解决如下:
c = max(contours, key=cv2.contourArea) #max contour
f = open('path.svg', 'w+')
f.write('<svg width="'+str(width)+'" height="'+str(height)+'" xmlns="http://www.w3.org/2000/svg">')
f.write('<path d="M')
for i in xrange(len(c)):
#print(c[i][0])
x, y = c[i][0]
print(x)
f.write(str(x)+ ' ' + str(y)+' ')
f.write('"/>')
f.write('</svg>')
f.close()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3245 次 |
| 最近记录: |