質問編集履歴
1
tr.pyの内容の一部をsample.pyに統合してみたが、変化がない
title
CHANGED
File without changes
|
body
CHANGED
@@ -113,4 +113,93 @@
|
|
113
113
|
break
|
114
114
|
|
115
115
|
```
|
116
|
+
ご回答よろしくお願いいたします。
|
117
|
+
|
118
|
+
###以下、再編集
|
119
|
+
|
120
|
+
##該当のソースコード3(sample.py(統合後))
|
121
|
+
```Python
|
122
|
+
import tkinter as tk
|
123
|
+
|
124
|
+
from PIL import Image, ImageTk, ImageDraw, ImageFont
|
125
|
+
import cv2
|
126
|
+
import numpy as np
|
127
|
+
|
128
|
+
from face_recognition import *
|
129
|
+
from predict import *
|
130
|
+
from create_dataset import *
|
131
|
+
|
132
|
+
root = tk.Tk()
|
133
|
+
root.title('sample')
|
134
|
+
root.geometry('1000x400+150+10')
|
135
|
+
|
136
|
+
f1 = tk.LabelFrame(root, bd=2, relief="ridge", text="camera")
|
137
|
+
f1.pack(side='top', anchor='w', padx=20)
|
138
|
+
|
139
|
+
camera = tk.Canvas(f1, width=600, height=400, bg="white")
|
140
|
+
camera.pack(side='left')
|
141
|
+
|
142
|
+
model_path = '../models/20180402-114759'
|
143
|
+
pic_path = "../dataset/images"
|
144
|
+
dataset_path = '../dataset/emb/faceEmbedding.npy'
|
145
|
+
filename = '../dataset/emb/name.txt'
|
146
|
+
reload = False
|
147
|
+
face_recognition_threshold = 0.85
|
148
|
+
|
149
|
+
print("initializing models...")
|
150
|
+
face_detect = Facedetection()
|
151
|
+
face_net = facenetEmbedding(model_path)
|
152
|
+
if reload:
|
153
|
+
print("refreshing face embeddings...")
|
154
|
+
create_face_embedding(model_path, pic_path, dataset_path, filename)
|
155
|
+
print("loading embeddings...")
|
156
|
+
dataset_emb, names_list = load_dataset(dataset_path, filename)
|
157
|
+
|
158
|
+
|
159
|
+
def capture():
|
160
|
+
try:
|
161
|
+
global c, w, h
|
162
|
+
c = cv2.VideoCapture(0)
|
163
|
+
w = c.get(cv2.CAP_PROP_FRAME_WIDTH)
|
164
|
+
h = c.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
165
|
+
pass
|
166
|
+
except:
|
167
|
+
import sys
|
168
|
+
c.release()
|
169
|
+
cv2.destroyAllWindows()
|
170
|
+
|
171
|
+
|
172
|
+
def up():
|
173
|
+
global img
|
174
|
+
ret, frame = c.read()
|
175
|
+
if ret:
|
176
|
+
result = face_recognition_image_driver(dataset_emb, names_list, face_detect, face_net, frame,
|
177
|
+
face_recognition_threshold)
|
178
|
+
|
179
|
+
def put_text_japanese(img, text, pos):
|
180
|
+
img_PIL = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
181
|
+
font_size = 25
|
182
|
+
font = ImageFont.truetype('meiryo', font_size, encoding="utf-8")
|
183
|
+
fillColor = (255, 0, 0) # 青(0, 0, 255)
|
184
|
+
draw = ImageDraw.Draw(img_PIL)
|
185
|
+
draw.text((pos[0], pos[1] - font_size - 10), text, font=font, fill=fillColor)
|
186
|
+
img = cv2.cvtColor(np.asarray(img_PIL), cv2.COLOR_RGB2BGR)
|
187
|
+
return img
|
188
|
+
|
189
|
+
frame = put_text_japanese(frame, result, (0, int(h)))
|
190
|
+
|
191
|
+
img = ImageTk.PhotoImage(Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)))
|
192
|
+
camera.create_image(w / 2, h / 2, image=img)
|
193
|
+
root.after(1, up)
|
194
|
+
|
195
|
+
|
196
|
+
root.after(1, up)
|
197
|
+
|
198
|
+
|
199
|
+
capture()
|
200
|
+
up()
|
201
|
+
|
202
|
+
root.mainloop()
|
203
|
+
|
204
|
+
```
|
116
205
|
ご回答よろしくお願いいたします。
|