# -*- coding: utf-8 -*-
"""createcsv.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/0B6o9rnHzHPSIUFlrakp5UDY1S3V2a3RpVnJlVHEycEZPZEww
"""

# converting images to pixels (numpyarray)
import glob
import cv2
images=[]
for file in glob.glob("C:\Users\user\Desktop\ismriti\CK+48\anger\*.png"):
    img=cv2.imread(str(file))
    img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 
    images.append(img)

images

images.insert(0,'P')

images.remove('Pixels')

#creating csv file and storing label and pixels
import csv
with open('testck.csv', 'w') as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
    for i in range(len(images)):
        wr.writerow((0,list(images[i])))

import pandas as pd
ff= pd.read_csv('testck.csv')

ff

import numpy as np
for i in range(len(images)):
    images[i]=np.array(images[i]).flatten()
#     print(len(i))

images[0].shape

h=[]
for file in glob.glob(r"C:\Users\user\Desktop\ismriti\CK+48\contempt\*.png"):
    img=cv2.imread(str(file))
    img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 
    h.append(img)

for i in range(len(h)):
    h[i]=np.array(h[i]).flatten()

#opening the csv in append mode
with open('testck.csv','a', newline='') as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
    for i in range(len(h)):
        wr.writerow((6,list(h[i])))

ff= pd.read_csv('testck.csv')
ff

