-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster0.py
217 lines (163 loc) · 3.94 KB
/
cluster0.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env python2
import time
start = time.time()
import argparse
import cv2
import itertools
import os
import numpy as np
np.set_printoptions(precision=2)
import openface
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as pyplot
m = np.loadtxt('/home/wizkraft/openface-master/demos/matrix_dabangg.txt', usecols=range(128))
print m.shape
n = len(m[:,127])
'''
R[i] stores the frequency of appearance of Person i
N[i] stores the centre/first image of Person i
M[i] stores the number of the person assigned to ith image
'''
M = np.zeros(n+2)
N = np.zeros(n+1)
R = np.zeros(n+1)
#initial = int(n/2)
initial = 0
M[initial]=1
N[1]=1
k=1
for i in range(initial,n-1):
#statinfo = os.stat("/home/wizkraft/Desktop/Faces/Thor/"+str(i)+".jpg")
#if statinfo.st_size < 10000:
# continue
d = m[i,:] - m[i+1,:]
if np.dot(d,d) < 1:
M[i+1]=M[i]
else:
min = 5
index = 1
for j in range(1,k+1):
d = m[int(N[j]),:] - m[i+1,:]
if np.dot(d,d) < min:
min = np.dot(d,d)
index = int(N[j])
if min < 0.95:
M[i+1] = M[index]
else:
M[i+1]=k+1
N[k+1]=i+1
k=k+1
s = k # number of different characters in the movie
for i in range(1,n):
R[int(M[i])] = R[int(M[i])]+1
max1 = 0
max2 = 0
max3 = 0
max4 = 0
index1 = 0
index2 = 0
index3 = 0
index4 = 0
for i in range(1,s+1):
print R[i],N[i]
if max1 < R[i]:
max1=R[i]
index1 = i
for i in range(1,s+1):
if i==index1:
continue
if max2 < R[i]:
max2=R[i]
index2 = i
for i in range(1,s+1):
if i == index1 or i == index2:
continue
if max3 < R[i]:
max3=R[i]
index3 = i
for i in range(1,s+1):
if i==index1 or i==index2 or i==index3:
continue
if max4 < R[i]:
max4=R[i]
index4 = i
print N[int(index1)]
print N[int(index2)]
print N[int(index3)]
print N[int(index4)]
frequencies = [0] * s
i=0
for i in range(0,s-1):
frequencies[i] = int(R[i+1])
alphab = []
calc = 1
while int(calc) <= s:
alphab.append(str(calc))
calc = int(calc) + 1
pos = np.arange(len(alphab))
width = 1.0 # gives histogram aspect to the bar diagram
ax = plt.axes()
ax.set_xticks(pos + (width / 2))
ax.set_xticklabels(alphab)
pyplot.title('Thor')
pyplot.xlabel('Person Number')
pyplot.ylabel('Appearence Frequency')
plt.bar(pos, frequencies, width, color='r')
plt.show()
t = np.loadtxt('/home/wizkraft/Desktop/Faces/Dabangg/images.txt', usecols=range(1))
noi = 0 #number of intervals
while(t[noi]>0):
noi = noi+1
t[noi] = n+1
a1 = [0]*noi
a2 = [0]*noi
a3 = [0]*noi
a4 = [0]*noi
for i in range(0,noi) :
for j in range(int(t[i]),int(t[i+1])):
if M[j]==index1:
a1[i]=a1[i]+1
if M[j]==index2:
a2[i]=a2[i]+1
if M[j]==index3:
a3[i]=a3[i]+1
if M[j]==index4:
a4[i]=a4[i]+1
print a1
print a2
print a3
print a4
print("--- %s seconds ---" % (time.time() - start))
alphab = []
calc = 1
while int(calc) <= noi:
alphab.append(str(calc))
calc = int(calc) + 1
pos = np.arange(len(alphab))
width = 1.0 # gives histogram aspect to the bar diagram
ax = plt.axes()
ax.set_xticks(pos + (width / 2))
ax.set_xticklabels(alphab)
pyplot.title('Actor 1')
pyplot.xlabel('Time Interval')
pyplot.ylabel('Appearence Frequency')
plt.bar(pos, a1, width, color='r')
plt.show()
alphab = []
calc = 1
while int(calc) <= noi:
alphab.append(str(calc))
calc = int(calc) + 1
pos = np.arange(len(alphab))
width = 1.0 # gives histogram aspect to the bar diagram
ax = plt.axes()
ax.set_xticks(pos + (width / 2))
ax.set_xticklabels(alphab)
pyplot.title('Actor 2')
pyplot.xlabel('Time Interval')
pyplot.ylabel('Appearence Frequency')
plt.bar(pos, a2, width, color='r')
plt.show()
# edit in line 21 to upload desired matrix
# edit in line 153 to upload the images matrix specifying time interval