1

Problem in Python- Only last numpy array is written to .csv file instead of all arrays being appended to it.How can I fix this?

import cv2, glob
from PIL import Image
import numpy as np
images = glob.glob('*.bmp')
    for image in images:
    img=cv2.imread(image,0)                                #original image
    re=cv2.resize(img, dsize=(128,128), interpolation=cv2.INTER_LINEAR)
    cv2.imwrite("resized_"+image,re)                       #resized image
    a = np.asarray(re)                                     #resized image is converted to pixels
    np.savetxt("sal.csv",a, delimiter=',')
    print(np.asarray(re))                                  #which are printed to csv file. Problem is only the last image pixel values are printed to csv file. Any suggestions to rectify this.
Tanuja
  • 11
  • 2
  • Open the file (`sal.csv`) before the loop and pass the file handle to `np.savetxt()` as described in the answer to: https://stackoverflow.com/questions/27786868/python3-numpy-appending-to-a-file-using-numpy-savetxt – Craig Oct 14 '18 at 01:08

0 Answers0