0
我需要將已經在Python中處理過的圖像的名稱追加到輸出.csv文件中。並將下一個圖像處理的結果放到另一個.csv垂直列或水平行。如何將處理後的圖像的名稱添加到.csv輸出文件?
怎麼樣?下面是代碼:
def humoments(self): #function for HuMoments computation
for filename in glob.iglob ('*.tif'):
img = cv.LoadImageM(filename, cv.CV_LOAD_IMAGE_GRAYSCALE)
cancer = cv.GetHuMoments(cv.Moments(img))
#arr = cancer
arr = numpy.array([cancer])
with open('hu.csv', 'wb') as csvfile: #puts the array to file
for elem in arr.flat[:50]:
writer = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow([('{}\t'.format(elem))])