質問編集履歴

2

コードを修正しました。

2020/07/01 01:30

投稿

YYJP
YYJP

スコア23

test CHANGED
File without changes
test CHANGED
@@ -130,115 +130,127 @@
130
130
 
131
131
  frame = imutils.resize(frame,width=300)
132
132
 
133
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
133
+ ####
134
-
135
- faces = face_detection.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=5,minSize=(30,30),flags=cv2.CASCADE_SCALE_IMAGE)
134
+
136
-
137
-
138
-
139
- canvas = np.zeros((250, 300, 3), dtype="uint8")
140
-
141
- frameClone = frame.copy()
135
+ prev_time = time.time()
136
+
142
-
137
+ while True:
138
+
139
+ curr_time = time.time()
140
+
143
- if len(faces) > 0:
141
+ if curr_time - prev_time >= 0.1:
144
-
145
- faces = sorted(faces, reverse=True,
146
-
147
- key=lambda x: (x[2] - x[0]) * (x[3] - x[1]))[0]
148
-
149
- (fX, fY, fW, fH) = faces
150
-
151
- # Extract the ROI of the face from the grayscale image, resize it to a fixed 28x28 pixels, and then prepare
152
-
153
- # the ROI for classification via the CNN
154
-
155
- roi = gray[fY:fY + fH, fX:fX + fW]
156
-
157
- roi = cv2.resize(roi, (64, 64))
158
-
159
- roi = roi.astype("float") / 255.0
160
-
161
- roi = img_to_array(roi)
162
-
163
- roi = np.expand_dims(roi, axis=0)
164
142
 
165
143
 
166
144
 
167
-
145
+ gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
146
+
168
-
147
+ faces = face_detection.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=5,minSize=(30,30),flags=cv2.CASCADE_SCALE_IMAGE)
148
+
149
+
150
+
151
+ canvas = np.zeros((250, 300, 3), dtype="uint8")
152
+
153
+ frameClone = frame.copy()
154
+
155
+ if len(faces) > 0:
156
+
169
- preds = emotion_classifier.predict(roi)[0]
157
+ faces = sorted(faces, reverse=True,
170
-
158
+
171
- with open(filenameTXT, 'a') as f:
159
+ key=lambda x: (x[2] - x[0]) * (x[3] - x[1]))[0]
172
-
173
- ################この処理が、動画に対し0.1秒刻みでなされるようにしたい##################
160
+
174
-
175
- print(preds, file=f)
161
+ (fX, fY, fW, fH) = faces
176
-
177
- ####################################################################################
162
+
178
-
179
- emotion_probability = np.max(preds)
180
-
181
- label = EMOTIONS[preds.argmax()]
182
-
183
- ###
184
-
185
- time.sleep(1)
186
-
187
- ###
188
-
189
- else: continue
190
-
191
-
192
-
193
-
194
-
195
- for (i, (emotion, prob)) in enumerate(zip(EMOTIONS, preds)):
163
+ # Extract the ROI of the face from the grayscale image, resize it to a fixed 28x28 pixels, and then prepare
196
-
197
- # construct the label text
164
+
198
-
199
- text = "{}: {:.2f}%".format(emotion, prob * 100)
200
-
201
-
202
-
203
- # draw the label + probability bar on the canvas
165
+ # the ROI for classification via the CNN
166
+
204
-
167
+ roi = gray[fY:fY + fH, fX:fX + fW]
168
+
169
+ roi = cv2.resize(roi, (64, 64))
170
+
171
+ roi = roi.astype("float") / 255.0
172
+
173
+ roi = img_to_array(roi)
174
+
205
- # emoji_face = feelings_faces[np.argmax(preds)]
175
+ roi = np.expand_dims(roi, axis=0)
206
-
207
-
208
176
 
209
177
 
210
178
 
179
+
180
+
181
+ preds = emotion_classifier.predict(roi)[0]
182
+
183
+ with open(filenameTXT, 'a') as f:
184
+
185
+ #print(preds)
186
+
187
+ print(preds, file=f)
188
+
189
+ emotion_probability = np.max(preds)
190
+
191
+ label = EMOTIONS[preds.argmax()]
192
+
193
+ ###
194
+
195
+ time.sleep(1)
196
+
197
+ ###
198
+
199
+ else: continue
200
+
201
+
202
+
203
+
204
+
205
+ for (i, (emotion, prob)) in enumerate(zip(EMOTIONS, preds)):
206
+
207
+ # construct the label text
208
+
209
+ text = "{}: {:.2f}%".format(emotion, prob * 100)
210
+
211
+
212
+
213
+ # draw the label + probability bar on the canvas
214
+
215
+ # emoji_face = feelings_faces[np.argmax(preds)]
216
+
217
+
218
+
219
+
220
+
211
- w = int(prob * 300)
221
+ w = int(prob * 300)
212
-
222
+
213
- cv2.rectangle(canvas, (7, (i * 35) + 5),
223
+ cv2.rectangle(canvas, (7, (i * 35) + 5),
214
-
224
+
215
- (w, (i * 35) + 35), (0, 0, 255), -1)
225
+ (w, (i * 35) + 35), (0, 0, 255), -1)
216
-
226
+
217
- cv2.putText(canvas, text, (10, (i * 35) + 23),
227
+ cv2.putText(canvas, text, (10, (i * 35) + 23),
218
-
228
+
219
- cv2.FONT_HERSHEY_SIMPLEX, 0.45,
229
+ cv2.FONT_HERSHEY_SIMPLEX, 0.45,
220
-
230
+
221
- (255, 255, 255), 2)
231
+ (255, 255, 255), 2)
222
-
232
+
223
- cv2.putText(frameClone, label, (fX, fY - 10),
233
+ cv2.putText(frameClone, label, (fX, fY - 10),
224
-
234
+
225
- cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
235
+ cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
226
-
236
+
227
- cv2.rectangle(frameClone, (fX, fY), (fX + fW, fY + fH),
237
+ cv2.rectangle(frameClone, (fX, fY), (fX + fW, fY + fH),
228
-
238
+
229
- (0, 0, 255), 2)
239
+ (0, 0, 255), 2)
230
-
240
+
231
- # for c in range(0, 3):
241
+ # for c in range(0, 3):
232
-
242
+
233
- # frame[200:320, 10:130, c] = emoji_face[:, :, c] * \
243
+ # frame[200:320, 10:130, c] = emoji_face[:, :, c] * \
234
-
244
+
235
- # (emoji_face[:, :, 3] / 255.0) + frame[200:320,
245
+ # (emoji_face[:, :, 3] / 255.0) + frame[200:320,
236
-
246
+
237
- # 10:130, c] * (1.0 - emoji_face[:, :, 3] / 255.0)
247
+ # 10:130, c] * (1.0 - emoji_face[:, :, 3] / 255.0)
248
+
249
+
250
+
238
-
251
+ prev_time = curr_time
252
+
239
-
253
+ ####
240
-
241
-
242
254
 
243
255
  cv2.imshow('your_face', frameClone)
244
256
 

1

タイトルを修正しました。

2020/07/01 01:30

投稿

YYJP
YYJP

スコア23

test CHANGED
@@ -1 +1 @@
1
- 動画を0.1秒刻みで解析したい
1
+ 表情認識AIで、動画内の表情を0.1秒刻みで解析したい
test CHANGED
@@ -40,6 +40,12 @@
40
40
 
41
41
 
42
42
 
43
+ 下記見づらいコードですが、
44
+
45
+ 何卒、よろしくお願いいたします。
46
+
47
+
48
+
43
49
  ### 該当のソースコード
44
50
 
45
51