質問編集履歴

1

tr.pyの内容の一部をsample.pyに統合してみたが、変化がない

2020/06/14 08:46

投稿

mintiamegahard
mintiamegahard

スコア8

test CHANGED
File without changes
test CHANGED
@@ -229,3 +229,181 @@
229
229
  ```
230
230
 
231
231
  ご回答よろしくお願いいたします。
232
+
233
+
234
+
235
+ ###以下、再編集
236
+
237
+
238
+
239
+ ##該当のソースコード3(sample.py(統合後))
240
+
241
+ ```Python
242
+
243
+ import tkinter as tk
244
+
245
+
246
+
247
+ from PIL import Image, ImageTk, ImageDraw, ImageFont
248
+
249
+ import cv2
250
+
251
+ import numpy as np
252
+
253
+
254
+
255
+ from face_recognition import *
256
+
257
+ from predict import *
258
+
259
+ from create_dataset import *
260
+
261
+
262
+
263
+ root = tk.Tk()
264
+
265
+ root.title('sample')
266
+
267
+ root.geometry('1000x400+150+10')
268
+
269
+
270
+
271
+ f1 = tk.LabelFrame(root, bd=2, relief="ridge", text="camera")
272
+
273
+ f1.pack(side='top', anchor='w', padx=20)
274
+
275
+
276
+
277
+ camera = tk.Canvas(f1, width=600, height=400, bg="white")
278
+
279
+ camera.pack(side='left')
280
+
281
+
282
+
283
+ model_path = '../models/20180402-114759'
284
+
285
+ pic_path = "../dataset/images"
286
+
287
+ dataset_path = '../dataset/emb/faceEmbedding.npy'
288
+
289
+ filename = '../dataset/emb/name.txt'
290
+
291
+ reload = False
292
+
293
+ face_recognition_threshold = 0.85
294
+
295
+
296
+
297
+ print("initializing models...")
298
+
299
+ face_detect = Facedetection()
300
+
301
+ face_net = facenetEmbedding(model_path)
302
+
303
+ if reload:
304
+
305
+ print("refreshing face embeddings...")
306
+
307
+ create_face_embedding(model_path, pic_path, dataset_path, filename)
308
+
309
+ print("loading embeddings...")
310
+
311
+ dataset_emb, names_list = load_dataset(dataset_path, filename)
312
+
313
+
314
+
315
+
316
+
317
+ def capture():
318
+
319
+ try:
320
+
321
+ global c, w, h
322
+
323
+ c = cv2.VideoCapture(0)
324
+
325
+ w = c.get(cv2.CAP_PROP_FRAME_WIDTH)
326
+
327
+ h = c.get(cv2.CAP_PROP_FRAME_HEIGHT)
328
+
329
+ pass
330
+
331
+ except:
332
+
333
+ import sys
334
+
335
+ c.release()
336
+
337
+ cv2.destroyAllWindows()
338
+
339
+
340
+
341
+
342
+
343
+ def up():
344
+
345
+ global img
346
+
347
+ ret, frame = c.read()
348
+
349
+ if ret:
350
+
351
+ result = face_recognition_image_driver(dataset_emb, names_list, face_detect, face_net, frame,
352
+
353
+ face_recognition_threshold)
354
+
355
+
356
+
357
+ def put_text_japanese(img, text, pos):
358
+
359
+ img_PIL = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
360
+
361
+ font_size = 25
362
+
363
+ font = ImageFont.truetype('meiryo', font_size, encoding="utf-8")
364
+
365
+ fillColor = (255, 0, 0) # 青(0, 0, 255)
366
+
367
+ draw = ImageDraw.Draw(img_PIL)
368
+
369
+ draw.text((pos[0], pos[1] - font_size - 10), text, font=font, fill=fillColor)
370
+
371
+ img = cv2.cvtColor(np.asarray(img_PIL), cv2.COLOR_RGB2BGR)
372
+
373
+ return img
374
+
375
+
376
+
377
+ frame = put_text_japanese(frame, result, (0, int(h)))
378
+
379
+
380
+
381
+ img = ImageTk.PhotoImage(Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)))
382
+
383
+ camera.create_image(w / 2, h / 2, image=img)
384
+
385
+ root.after(1, up)
386
+
387
+
388
+
389
+
390
+
391
+ root.after(1, up)
392
+
393
+
394
+
395
+
396
+
397
+ capture()
398
+
399
+ up()
400
+
401
+
402
+
403
+ root.mainloop()
404
+
405
+
406
+
407
+ ```
408
+
409
+ ご回答よろしくお願いいたします。