def detect_face(data): from retinaface.detector import detector from utils import align_face src_path = data['src_path'] dst_path = data['dst_path'] boxB = np.array(data['boxB']) img = cv.imread(src_path) if img is not None: img, ratio = resize(img) boxB = boxB * ratio try: bboxes, landmarks = detector.detect_faces(img) if len(bboxes) > 0: i = select_face(bboxes, boxB) bbox, landms = bboxes[i], landmarks[i] img = align_face(img, [landms]) dirname = os.path.dirname(dst_path) os.makedirs(dirname, exist_ok=True) cv.imwrite(dst_path, img) except ValueError as err: print(err) except cv.error as err: print(err) return True
def detect_face(data): from retinaface.detector import detector from utils import align_face src_path = data['src_path'] dst_path = data['dst_path'] img_raw = cv.imread(src_path) if img_raw is not None: img = resize(img_raw) try: bboxes, landmarks = detector.detect_faces(img, confidence_threshold=0.9) if len(bboxes) > 0: bbox, landms = bboxes[0], landmarks[0] img = align_face(img, [landms]) dirname = os.path.dirname(dst_path) os.makedirs(dirname, exist_ok=True) cv.imwrite(dst_path, img) return True except ValueError as err: print(err) img = cv.resize(img, (im_size, im_size)) cv.imwrite(dst_path, img) return False return False
def get_face_attributes(full_path): try: img = Image.open(full_path).convert('RGB') bounding_boxes, landmarks = detector.detect_faces(img) if len(landmarks) > 0: landmarks = [int(round(x)) for x in landmarks[0]] return True, landmarks except KeyboardInterrupt: raise except: pass return False, None
def get_central_face_attributes(full_path): try: img = cv.imread(full_path) bounding_boxes, landmarks = detector.detect_faces(img) if len(landmarks) > 0: i = select_significant_face(bounding_boxes) return True, [bounding_boxes[i]], [landmarks[i]] except KeyboardInterrupt: raise except ValueError: pass except IOError: pass return False, None, None
def detect_face(data): src_path = data['src_path'] dst_path = data['dst_path'] # print(src_path) img_raw = cv.imread(src_path) if img_raw is not None: img, _ = resize(img_raw) try: bboxes, landmarks = detector.detect_faces(img) if len(bboxes) > 0: bbox, landms = bboxes[0], landmarks[0] img = align_face(img, [landms]) dirname = os.path.dirname(dst_path) os.makedirs(dirname, exist_ok=True) cv.imwrite(dst_path, img) return True except ValueError as err: print(err) return False
def get_all_face_attributes(full_path): img = Image.open(full_path).convert('RGB') bounding_boxes, landmarks = detector.detect_faces(img) return bounding_boxes, landmarks
def get_all_face_attributes(full_path): img = cv.imread(full_path) bounding_boxes, landmarks = detector.detect_faces(img) return bounding_boxes, landmarks