chauhuynh90 commited on
Commit
8a666b1
·
1 Parent(s): e087067

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -3,6 +3,15 @@ import gradio as gr
3
  from PIL import Image
4
  import cv2
5
  import numpy as np
 
 
 
 
 
 
 
 
 
6
  title = "DEEP FACE DEMO"
7
  distance_metric = ["cosine", "euclidean", "euclidean_l2",]
8
  detection_model = ["opencv", "retinaface", "mtcnn", "ssd", "dlib",]
@@ -39,6 +48,10 @@ def facial_recognition(img1, img2, metric, detection, recognition):
39
 
40
 
41
  def facial_analysis(img, detection):
 
 
 
 
42
  try:
43
  objs = DeepFace.analyze(img_path = img, actions = ['age', 'gender', 'race', 'emotion'], detector_backend = detection)
44
  except:
@@ -57,9 +70,9 @@ def facial_analysis(img, detection):
57
  text,
58
  (int(x), int(y) - 10),
59
  fontFace = cv2.FONT_HERSHEY_SIMPLEX,
60
- fontScale = 0.6,
61
  color = (0, 0, 255),
62
- thickness=2
63
  )
64
 
65
  return Image.fromarray(img)
 
3
  from PIL import Image
4
  import cv2
5
  import numpy as np
6
+ import math
7
+
8
+ FONT_SCALE = 8e-4 # Adjust for larger font size in all images
9
+ THICKNESS_SCALE = 4e-4 # Adjust for larger thickness in all images
10
+
11
+ import torch
12
+ # from utils.facial_makeup import *
13
+ import torchvision.transforms as transforms
14
+
15
  title = "DEEP FACE DEMO"
16
  distance_metric = ["cosine", "euclidean", "euclidean_l2",]
17
  detection_model = ["opencv", "retinaface", "mtcnn", "ssd", "dlib",]
 
48
 
49
 
50
  def facial_analysis(img, detection):
51
+
52
+ height, width, _ = img.shape
53
+ font_scale = min(width, height) * FONT_SCALE
54
+ thickness = math.ceil(min(width, height) * THICKNESS_SCALE)
55
  try:
56
  objs = DeepFace.analyze(img_path = img, actions = ['age', 'gender', 'race', 'emotion'], detector_backend = detection)
57
  except:
 
70
  text,
71
  (int(x), int(y) - 10),
72
  fontFace = cv2.FONT_HERSHEY_SIMPLEX,
73
+ fontScale = font_scale,
74
  color = (0, 0, 255),
75
+ thickness=thickness
76
  )
77
 
78
  return Image.fromarray(img)