質問編集履歴
3
誤記修正2
test
CHANGED
File without changes
|
test
CHANGED
@@ -288,7 +288,7 @@
|
|
288
288
|
|
289
289
|
cv2.namedWindow('img', cv2.WINDOW_NORMAL)
|
290
290
|
|
291
|
-
|
291
|
+
|
292
292
|
|
293
293
|
# 結果の表示
|
294
294
|
|
2
誤記修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -284,7 +284,7 @@
|
|
284
284
|
|
285
285
|
|
286
286
|
|
287
|
-
|
287
|
+
|
288
288
|
|
289
289
|
cv2.namedWindow('img', cv2.WINDOW_NORMAL)
|
290
290
|
|
1
解決方法を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -192,8 +192,124 @@
|
|
192
192
|
|
193
193
|
|
194
194
|
|
195
|
-
###
|
195
|
+
### 解決方法
|
196
|
+
|
196
|
-
|
197
|
+
①len(faces)の出力確認
|
198
|
+
|
197
|
-
|
199
|
+
②len(faces)の出力によって条件分岐するように作成
|
200
|
+
|
198
|
-
|
201
|
+
```
|
202
|
+
|
203
|
+
# --------------------------------
|
204
|
+
|
205
|
+
# 3.カメラ画像の取得
|
206
|
+
|
207
|
+
# --------------------------------
|
208
|
+
|
209
|
+
# カメラの指定(適切な引数を渡す)
|
210
|
+
|
211
|
+
cap = cv2.VideoCapture(1)
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
# カメラ画像の表示 ('q'入力で終了)
|
216
|
+
|
217
|
+
while(True):
|
218
|
+
|
219
|
+
ret, img = cap.read()
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
img_gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
# 顔のランドマーク検出(2.の関数呼び出し)
|
228
|
+
|
229
|
+
faces = face_detector(img_gry, 1)
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
#ーーーーーーーーーーーーーーーーーーーー#
|
234
|
+
|
235
|
+
#len(faces)の出力が0,1であることを確認 #
|
236
|
+
|
237
|
+
#ーーーーーーーーーーーーーーーーーーーー#
|
238
|
+
|
239
|
+
print(len(faces))
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
#ーーーーーーーーーーーーーーーーーーーーーーーーーー#
|
244
|
+
|
245
|
+
#len(faces)が1であればMOVIE,0であればLOSTと表示#
|
246
|
+
|
247
|
+
#ーーーーーーーーーーーーーーーーーーーー ーーーーー#
|
248
|
+
|
249
|
+
if len(faces) == 1:
|
250
|
+
|
251
|
+
cv2.putText(img, 'MOVIE', (0, 100), cv2.FONT_HERSHEY_PLAIN, 7, (255, 255, 255), 5, cv2.LINE_AA)
|
252
|
+
|
253
|
+
else:
|
254
|
+
|
255
|
+
cv2.putText(img, 'LOST', (0, 50), cv2.FONT_HERSHEY_PLAIN, 7, (255, 255, 255), 5, cv2.LINE_AA)
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
# 顔のランドマーク検出
|
260
|
+
|
261
|
+
for face in faces:
|
262
|
+
|
263
|
+
landmark = face_predictor(img_gry, face)
|
264
|
+
|
265
|
+
landmark = face_utils.shape_to_np(landmark)
|
266
|
+
|
267
|
+
Land.append(landmark[28])
|
268
|
+
|
269
|
+
ue = time.time()
|
270
|
+
|
271
|
+
TIME.append(ue-ut)
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
# ランドマーク描画
|
278
|
+
|
279
|
+
for (x, y) in landmark:
|
280
|
+
|
281
|
+
right_eye_x, right_eye_y = landmark[36][0],landmark[36][1]
|
282
|
+
|
283
|
+
cv2.circle(img, (x, y), 3, (0, 0, 255), -1)
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
before_landmark = len(landmark)
|
288
|
+
|
289
|
+
cv2.namedWindow('img', cv2.WINDOW_NORMAL)
|
290
|
+
|
291
|
+
#cv2.putText(img, 'Movie', (0, 50), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 2, cv2.LINE_AA)
|
292
|
+
|
293
|
+
# 結果の表示
|
294
|
+
|
295
|
+
resized_img = cv2.resize(img,(500, 300))
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
cv2.imshow('img', resized_img)
|
300
|
+
|
301
|
+
# 'q'が入力されるまでループ
|
302
|
+
|
199
|
-
if
|
303
|
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
304
|
+
|
305
|
+
break
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
cap.release()
|
312
|
+
|
313
|
+
cv2.destroyAllWindows()
|
314
|
+
|
315
|
+
```
|