Spaces:
Build error
Build error
Commit ·
572ea36
1
Parent(s): f5b590a
added square_padding for crops to maintain aspect ratio
Browse files- app/demo/routes.py +1 -1
- app/face_detection/helper.py +3 -0
- app/face_detection/inference.py +5 -3
app/demo/routes.py
CHANGED
|
@@ -150,7 +150,7 @@ def face_recognition():
|
|
| 150 |
for i in range(len(names)):
|
| 151 |
print(names[i],":",db_faces_features[i].shape)
|
| 152 |
|
| 153 |
-
# face_recognizer.set_face_db_and_mode(faces=
|
| 154 |
face_recognizer.set_face_db_and_mode(faces=names,db_faces_features=db_faces_features,distance_mode="best",recognition_mode="repeat")
|
| 155 |
|
| 156 |
face_detector.image_size=get_image_size(session["demo"]['settings']['fr_mode'])
|
|
|
|
| 150 |
for i in range(len(names)):
|
| 151 |
print(names[i],":",db_faces_features[i].shape)
|
| 152 |
|
| 153 |
+
# face_recognizer.set_face_db_and_mode(faces=names,db_faces_features=db_faces_features,distance_mode="avg",recognition_mode="repeat")
|
| 154 |
face_recognizer.set_face_db_and_mode(faces=names,db_faces_features=db_faces_features,distance_mode="best",recognition_mode="repeat")
|
| 155 |
|
| 156 |
face_detector.image_size=get_image_size(session["demo"]['settings']['fr_mode'])
|
app/face_detection/helper.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import cv2
|
| 2 |
import numpy as np
|
|
|
|
| 3 |
|
| 4 |
|
|
|
|
| 5 |
def get_crops(img,objs_found,aligner=None,resize:tuple=None):
|
| 6 |
img_h,img_w,_=img.shape
|
| 7 |
all_crops=[]
|
|
@@ -17,6 +19,7 @@ def get_crops(img,objs_found,aligner=None,resize:tuple=None):
|
|
| 17 |
crop=aligner.align_image(crop)
|
| 18 |
if crop is None: continue
|
| 19 |
if resize is not None:
|
|
|
|
| 20 |
crop=cv2.resize(crop,resize)
|
| 21 |
all_crops.append(crop)
|
| 22 |
|
|
|
|
| 1 |
import cv2
|
| 2 |
import numpy as np
|
| 3 |
+
from app.face_detection.inference import square_pad
|
| 4 |
|
| 5 |
|
| 6 |
+
square_maker=square_pad(color=(255,255,255))
|
| 7 |
def get_crops(img,objs_found,aligner=None,resize:tuple=None):
|
| 8 |
img_h,img_w,_=img.shape
|
| 9 |
all_crops=[]
|
|
|
|
| 19 |
crop=aligner.align_image(crop)
|
| 20 |
if crop is None: continue
|
| 21 |
if resize is not None:
|
| 22 |
+
crop=square_maker(crop)
|
| 23 |
crop=cv2.resize(crop,resize)
|
| 24 |
all_crops.append(crop)
|
| 25 |
|
app/face_detection/inference.py
CHANGED
|
@@ -53,16 +53,18 @@ class square_crop:
|
|
| 53 |
raise NotImplementedError
|
| 54 |
|
| 55 |
class square_pad:
|
| 56 |
-
def
|
|
|
|
|
|
|
| 57 |
h,w=img.shape[:2]
|
| 58 |
self.w_added,self.h_added=0,0
|
| 59 |
if h>w:
|
| 60 |
self.w_added=int((h-w)/2)
|
| 61 |
-
padding=(np.ones([h,self.w_added,3])*np.array(color)[None,None,:]).astype("uint8")
|
| 62 |
img=np.concatenate([padding,img,padding],axis=1)
|
| 63 |
elif w>h:
|
| 64 |
self.h_added=int((w-h)/2)
|
| 65 |
-
padding=(np.ones([self.h_added,w,3])*np.array(color)[None,None,:]).astype("uint8")
|
| 66 |
img=np.concatenate([padding,img,padding],axis=0)
|
| 67 |
h,w=img.shape[:2]
|
| 68 |
|
|
|
|
| 53 |
raise NotImplementedError
|
| 54 |
|
| 55 |
class square_pad:
|
| 56 |
+
def __init__(self,color=(0,0,0)):
|
| 57 |
+
self.color=color
|
| 58 |
+
def __call__(self,img):
|
| 59 |
h,w=img.shape[:2]
|
| 60 |
self.w_added,self.h_added=0,0
|
| 61 |
if h>w:
|
| 62 |
self.w_added=int((h-w)/2)
|
| 63 |
+
padding=(np.ones([h,self.w_added,3])*np.array(self.color)[None,None,:]).astype("uint8")
|
| 64 |
img=np.concatenate([padding,img,padding],axis=1)
|
| 65 |
elif w>h:
|
| 66 |
self.h_added=int((w-h)/2)
|
| 67 |
+
padding=(np.ones([self.h_added,w,3])*np.array(self.color)[None,None,:]).astype("uint8")
|
| 68 |
img=np.concatenate([padding,img,padding],axis=0)
|
| 69 |
h,w=img.shape[:2]
|
| 70 |
|