This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# parent_serializer.py | |
class MetaObj(): | |
pass | |
class ParentSerializer(serializers.ModelSerializer): | |
def __init__(self, *args, **kwargs): | |
meta_obj = MetaObj() | |
meta_obj.model = ParentModel | |
meta_obj.fields = ["field_1", "field_2"] | |
meta_obj.read_only_fields = ["field 3", "field_4"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def drawEyeliner(img, interp_pts): | |
L_eye_interp, R_eye_interp = interp_pts | |
L_interp_x, L_interp_top_y, L_interp_bottom_y = L_eye_interp | |
R_interp_x, R_interp_top_y, R_interp_bottom_y = R_eye_interp | |
overlay = img.copy() | |
# overlay = np.empty(img.shape) | |
# overlay = np.zeros_like(img) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getEyelinerPoints(eye_landmark_points): | |
''' | |
Takes an array of eye coordinates and interpolates them: | |
''' | |
L_eye_top, L_eye_bottom, R_eye_top, R_eye_bottom = eye_landmark_points | |
L_interp_x = np.arange(L_eye_top[0][0], L_eye_top[-1][0], 1) | |
R_interp_x = np.arange(R_eye_top[0][0], R_eye_top[-1][0], 1) | |
L_interp_top_y = interpolateCoordinates(L_eye_top, L_interp_x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.interpolate import interp1d | |
def interpolateCoordinates(xy_coords, x_intrp): | |
x = xy_coords[:, 0] | |
y = xy_coords[:, 1] | |
intrp = interp1d(x, y, kind='quadratic') | |
y_intrp = intrp(x_intrp) | |
y_intrp = np.floor(y_intrp).astype(int) | |
return y_intrp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getEyeLandmarkPts(face_landmark_points): | |
''' | |
Input: Coordinates of Bounding Box single face | |
Returns: eye's landmark points | |
''' | |
face_landmark_points[36][0]-=5 | |
face_landmark_points[39][0]+=5 | |
face_landmark_points[42][0]-=5 | |
face_landmark_points[45][0]+=5 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
face_detector = dlib.get_frontal_face_detector() | |
lndMrkDetector = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") | |
def Eyeliner(frame): | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
bounding_boxes = face_detector(gray, 0)# The 2nd argument means that we upscale the image by 'x' number of times to detect more faces. | |
if bounding_boxes: | |
for i, bb in enumerate(bounding_boxes): | |
face_landmark_points = lndMrkDetector(gray, bb) | |
face_landmark_points = face_utils.shape_to_np(face_landmark_points) |