我需要将已在 Python 中处理的图像名称附加到输出 .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))])