Spaces:
Running
Running
File size: 1,743 Bytes
0f2d9f6 9acc552 0f2d9f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import os
import sys
import warnings
import os.path as osp
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
root_path = osp.abspath(osp.join(__file__, osp.pardir, osp.pardir))
sys.path.append(root_path)
from feature_extraction.extractor_mediapipe import ExtractorMediaPipe
warnings.filterwarnings("ignore")
class FeaturesExtractor:
def __init__(self, extraction_library="mediapipe", blink_detection=False, upscale=1):
self.upscale = upscale
self.blink_detection = blink_detection
self.extraction_library = extraction_library
self.feature_extractor = ExtractorMediaPipe(self.upscale)
def __call__(self, image):
results = {}
face = self.feature_extractor.extract_face(image)
if face is None:
# print("No face found. Skipped feature extraction!")
return None
else:
results["img"] = image
results["face"] = face
eyes_data = self.feature_extractor.extract_eyes(image, self.blink_detection)
if eyes_data is None:
# print("No eyes found. Skipped feature extraction!")
return results
else:
results["eyes"] = eyes_data
if eyes_data["blinked"]:
# print("Found blinked eyes!")
return results
else:
iris_data = self.feature_extractor.extract_iris(image)
if iris_data is None:
# print("No iris found. Skipped feature extraction!")
return results
else:
results["iris"] = iris_data
return results
|