遍历三维数组为一维数组输出并存为txt

import cv2
import numpy as np     

image,contours,hierarchy=cv2.findContours(image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

for obj in np.array(contours):
    t1 = obj.flatten()#降维
    t2 = [str(x) for x in t1]#转为字符串格式
    t3 = ' '.join(t2)
    f = open('test.txt', "a", encoding='utf-8')
    f.writelines([t3,' ','building','\n'])
    f.close()

其中contours为三维数组

猜你喜欢

转载自blog.csdn.net/szy525525/article/details/86013700