""" @file: run.py @desc: expose the rest api using flask """ import sys import cv2 import numpy as np from feature_api import load_model, align, get_feature, match_feature feature_extractor, device = load_model('Res50', 512, '0') def match_image(src_numpy, dst_numpy): face_image = align(src_numpy, output_size=(112, 112)) src_feat = get_feature(face_image, feature_extractor, device) face_image = align(dst_numpy, output_size=(112, 112)) dst_feat = get_feature(face_image, feature_extractor, device) output = match_feature(src_feat, dst_feat) sim = 0 if output[0] < 0 else output[0] print("Matching Score: ", sim) if sim < 0.72: result = "Different Person" else: result = "Same Person" response = { "confidence": sim, "threshold": 0.72, "result": result } return response if __name__ == '__main__': src_file = '../images/11.jpg' dst_file = '../images/4.jpg' src_img = cv2.imread(src_file) dst_img = cv2.imread(dst_file) print(match_image(src_img, dst_img))