- 将坐标数据写入.txt
- 再还原
contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE,cv.CHAIN_APPROX_NONE) #获得二值图像轮廓坐标
print(len(contours))
#写如文档(前提在该目录下没有这个文件)
fo = open("C:\Users\star\Desktop\point.txt", "w")
for i in contours:
for y in i:
for x in y:
fo.writelines(str(x))
fo.close()
然后就写成这个鬼样子:
将这个鬼样子的数据还原为Numpy数组
fo = open("C:\Users\star\Desktop\text1.txt", "r")
date = fo.read()
date = date.replace("["," ")
date = date.replace("]"," ")
date = date.split()
date = list(map(int, date))
print(int(len(date)/2))
Points = np.array(date).reshape(562,2)
效果:
date.replace("["," ")
将字符串中的“[”换为“ ”
date.split():
将字符串以空格分割,返回的是列表
list(map(int, date))
先将date的数据化为int,但是返回值为map
再转换为列表类型
np.array(date).reshape(562,2)
化为最终形态
大家有什么更好的办法,求教(ಡωಡ)



