Dec-14-2018, 08:05 PM
Hi
Im trying to read images from folders into a dataframe , where each row in the dataframe is all the images for a folder :
I can read all the images in each folder to {samples} list but when I try to insert them into dataframe I get this error :
Im trying to read images from folders into a dataframe , where each row in the dataframe is all the images for a folder :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import cv2 import os,glob import matplotlib.pylab as plt from os import listdir,makedirs from os.path import isfile,join import pandas as pd import PIL import numpy as np from scipy.ndimage import imread pth = 'C:/Users/sarmad/Documents/n/' folders = os.listdir(pth) videos = pd.DataFrame() for folder in folders: pth_upd = pth + folder + '/' #print(pth_upd) allfiles = os.listdir(pth_upd) files = [] columns = [ 'data' ] index = [folders] for file in allfiles: files.append( file ) if ( '.bmp' in file ) else None samples = np.empty(( 0 , 64 , 64 )) for file in files: img = cv2.imread(os.path.join(pth_upd, file ),cv2.IMREAD_GRAYSCALE) #print(img) # read image img = img.reshape( 1 , 64 , 64 ) samples = np.append(samples, img, axis = 0 ) df = pd.DataFrame( index = folders) df[ 'img_frames' ] = pd.DataFrame([samples],index = folders) |
Quote:ValueError Traceback (most recent call last)
<ipython-input-99-db4b01fe9450> in <module>
20 samples = np.append(samples, img, axis=0)
21 df = pd.DataFrame( index=folders)
---> 22 df['img_frames'] = pd.DataFrame([samples],index=folders)
23
24
ValueError: Must pass 2-d input