forked from nabulago/anomaly-event-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasetgenerator.py
117 lines (110 loc) · 3.51 KB
/
datasetgenerator.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'''
flatten image, normalize, stack and add to dataset
'''
import cv2
import numpy as np
from os.path import isfile, join
from os import listdir
from random import shuffle
from shutil import copyfile
import os
import pickle
import cv2
datasetPath = '/apperance'
# trainFolders = ['Train001','Train002']
# image_15.txt has the filepaths of all the apperance windows
# of different scales
fileData = open('./apperance/image_15.txt','r').read().split('\n')
fileData = sorted(fileData)
#print len(fileData)
fileData = list(set(fileData))
print len(fileData)
i = 0
# while i<5:
# print fileData[i]
# sampleOne = fileData[i]
# i = i +1
#print "out"
# shuffle(fileData) # Don't shuffle the data if you want to consecutive samples
#print "data shuffled"
# i = 0
images = np.ones((225,),dtype='uint8')
print type(images)
print fileData[10]
for i,flD in enumerate(fileData):
print "File data : " + str(i) +str(fileData[i])
if i==20:
break
with open("apperance_main.pkl",'wb') as imageDataset:
for flD in fileData:
if i%100 == 0:
print "===================="
print "Completed 100 images"
print "===================="
print "Total images saved : " + str(i)
if i%1000 == 0:
print "===================="
print "Completed 1000 images"
print "===================="
print "Total images saved : " + str(i)
if i > 20000:
print "===================="
print "Completed 20000 files"
print "===================="
break
# print "Second loop"
print flD
# print fileData
# print "File data : " +str(fileData[i])
# sampleOne = fileData[i]
# fileShow = datasetPath+"/"+sampleOne
fileShow = datasetPath+"/"+str(fileData[i])
# print fileShow
image = cv2.imread(fileShow,0)
# if not image.any(): continue
# print image.shape
image = cv2.resize(image, (15,15),0)
#cv2.imshow("image",image)
image.shape
# print "image shape" + str(image.flatten().shape)
# print type(image)
image = image.flatten()
#cv2.imshow("images",images)
image = cv2.normalize((image).astype('float'), None, 0, 1, cv2.NORM_MINMAX)
#print image
# print "After normalization" +str(image.shape)
images = np.column_stack((images,image))
#print type(images)
#print images.shape
#print images
# print images.shape
# k = cv2.waitKey(1) & 0xff
# if k == 27:
# pickle.dump(image,imageDataset,-1)
# imageDataset.close()
# if not imageDataset.closed:
# imageDataset.close()
# cv2.destoyAllWindows()
# break
# elif k == ord('q'):
# pickle.dump(image,imageDataset,-1)
# if not imageDataset.closed:
# imageDataset.close()
# cv2.destoyAllWindows()
# break
# k = cv2.waitKey(0) & 0xff
# if k == 27:
# cv2.destoyAllWindows()
# break
# elif k == ord('q'):
# cv2.destoyAllWindows()
# break
i = i +1
pickle.dump(image,imageDataset,-1)
# if not imageDataset.closed:
# pickle.dump(images,imageDataset,-1)
# imageDataset.close()
if not imageDataset.closed:
imageDataset.close()
#imd = open('motionfeatures.p','rb')
#imdataset = pickle.load(imd)