INNER CODE UNIT · Python
__init__
minivision-ai/Silent-Face-Anti-Spoofing · src/anti_spoof_predict.py:29
def __init__(self):
caffemodel = "./resources/detection_model/Widerface-RetinaFace.caffemodel"
deploy = "./resources/detection_model/deploy.prototxt"
self.detector = cv2.dnn.readNetFromCaffe(deploy, caffemodel)
self.detector_confidence = 0.6
def get_bbox(self, img):
height, width = img.shape[0], img.shape[1]
aspect_ratio = width / height
if img.shape[1] * img.shape[0] >= 192 * 192:
img = cv2.resize(img,
(int(192 * math.sqrt(aspect_ratio)),
int(192 / math.sqrt(aspect_ratio))), interpolation=cv2.INTER_LINEAR)
blob = cv2.dnn.blobFromImage(img, 1, mean=(104, 117, 123))
self.detector.setInput(blob, 'data')
out = self.detector.forward('detection_out').squeeze()
max_conf_index = np.argmax(out[:, 2])