ParisNeo commited on
Commit
cda70dc
1 Parent(s): f223697

updated (removed realtime webcam

Browse files
Files changed (2) hide show
  1. .vscode/settings.json +3 -0
  2. app.py +0 -66
.vscode/settings.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "ros.distro": "noetic"
3
+ }
app.py CHANGED
@@ -72,17 +72,6 @@ class UI():
72
  self.distance_type = gr.State("cosine")
73
  gr.Markdown("## FaceAnalyzer face recognition test")
74
  with gr.Tabs():
75
- with gr.TabItem('Realtime Recognize'):
76
- with gr.Blocks():
77
- with gr.Row():
78
- with gr.Column():
79
- self.rt_webcam = gr.Image(label="Input Image", source="webcam", streaming=True)
80
- self.start_streaming = gr.Button("Start webcam")
81
- self.start_streaming.click(self.start_webcam, [], [self.start_streaming])
82
-
83
- with gr.Column():
84
- self.rt_rec_img = gr.Image(label="Output Image")
85
- self.rt_webcam.change(self.process_webcam, inputs=self.rt_webcam, outputs=self.rt_rec_img, show_progress=False)
86
  with gr.TabItem('Image Recognize'):
87
  with gr.Blocks():
88
  with gr.Row():
@@ -91,18 +80,6 @@ class UI():
91
  with gr.Column():
92
  self.rt_rec_img = gr.Image(label="Output Image")
93
  self.rt_inp_img.change(self.process_image, inputs=self.rt_inp_img, outputs=self.rt_rec_img, show_progress=True)
94
- with gr.TabItem('Add face from webcam'):
95
- with gr.Blocks():
96
- with gr.Row():
97
- with gr.Column():
98
- self.img = gr.Image(label="Input Image", source="webcam", streaming=True)
99
- self.txtFace_name = gr.Textbox(label="face_name")
100
- self.status = gr.Label(label="Status")
101
- self.txtFace_name.change(self.set_face_name, inputs=self.txtFace_name, outputs=self.status, show_progress=False)
102
- self.img.change(self.record_from_webcam, inputs=self.img, outputs=self.status, show_progress=False)
103
- with gr.Column():
104
- self.btn_start = gr.Button("Start Recording face")
105
- self.btn_start.click(self.start_stop)
106
  with gr.TabItem('Add face from files'):
107
  with gr.Blocks():
108
  with gr.Row():
@@ -280,49 +257,6 @@ class UI():
280
  pickle.dump({"mean":embeddings_cloud_mean, "inv_cov":embeddings_cloud_inv_cov},f)
281
  print(f"Saved {name}")
282
 
283
- def record_from_webcam(self, image):
284
- if self.face_name is None or self.face_name=="":
285
- self.embeddings_cloud=[]
286
- self.is_recording=False
287
- return "Please input a face name"
288
-
289
- if self.is_recording and image is not None:
290
- if self.i < self.nb_images:
291
- fa.image_size=(640, 480, 3)
292
-
293
- # Process the image to extract faces and draw the masks on the face in the image
294
- fa.process(image)
295
- if fa.nb_faces>0:
296
- try:
297
- face = fa.faces[0]
298
- vertices = face.get_face_outer_vertices()
299
- image = face.getFaceBox(image, vertices, margins=(40,40,40,40))
300
- embedding = DeepFace.represent(image, enforce_detection=False)[0]["embedding"]
301
- self.embeddings_cloud.append(embedding)
302
- self.i+=1
303
- except Exception as ex:
304
- print(ex)
305
- return f"Processing frame {self.i}/{self.nb_images}..."
306
- else:
307
- # Now let's find out where the face lives inside the latent space (128 dimensions space)
308
-
309
- embeddings_cloud = np.array(self.embeddings_cloud)
310
- embeddings_cloud_mean = embeddings_cloud.mean(axis=0)
311
- embeddings_cloud_inv_cov = embeddings_cloud.std(axis=0)
312
- # Now we save it.
313
- # create a dialog box to ask for the subject name
314
- name = self.face_name
315
- with open(str(self.faces_path/f"{name}.pkl"),"wb") as f:
316
- pickle.dump({"mean":embeddings_cloud_mean, "inv_cov":embeddings_cloud_inv_cov},f)
317
- print(f"Saved {name} embeddings")
318
- self.i=0
319
- self.embeddings_cloud=[]
320
- self.is_recording=False
321
- self.upgrade_faces()
322
-
323
- return f"Saved {name} embeddings"
324
- else:
325
- return "Waiting"
326
 
327
  def record_from_files(self, images, face_name):
328
  if face_name is None or face_name=="":
 
72
  self.distance_type = gr.State("cosine")
73
  gr.Markdown("## FaceAnalyzer face recognition test")
74
  with gr.Tabs():
 
 
 
 
 
 
 
 
 
 
 
75
  with gr.TabItem('Image Recognize'):
76
  with gr.Blocks():
77
  with gr.Row():
 
80
  with gr.Column():
81
  self.rt_rec_img = gr.Image(label="Output Image")
82
  self.rt_inp_img.change(self.process_image, inputs=self.rt_inp_img, outputs=self.rt_rec_img, show_progress=True)
 
 
 
 
 
 
 
 
 
 
 
 
83
  with gr.TabItem('Add face from files'):
84
  with gr.Blocks():
85
  with gr.Row():
 
257
  pickle.dump({"mean":embeddings_cloud_mean, "inv_cov":embeddings_cloud_inv_cov},f)
258
  print(f"Saved {name}")
259
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
 
261
  def record_from_files(self, images, face_name):
262
  if face_name is None or face_name=="":