diff options
Diffstat (limited to 'megapixels/app/processors/face_landmarks.py')
| -rw-r--r-- | megapixels/app/processors/face_landmarks.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/megapixels/app/processors/face_landmarks.py b/megapixels/app/processors/face_landmarks.py index 8086ba1e..171fc666 100644 --- a/megapixels/app/processors/face_landmarks.py +++ b/megapixels/app/processors/face_landmarks.py @@ -83,8 +83,11 @@ class Dlib2D(Landmarks2D): self.log.info(f'loaded predictor model: {model}') def landmarks(self, im, bbox): - # Draw high-confidence faces - dim_wh = im.shape[:2][::-1] + '''Generates 68-pt landmarks using dlib predictor + :param im: (numpy.ndarray) BGR image + :param bbox: (app.models.BBox) dimensioned + :returns (list) of (int, int) for x,y values + ''' bbox = bbox.to_dlib() im_gray = cv.cvtColor(im, cv.COLOR_BGR2GRAY) points = [[p.x, p.y] for p in self.predictor(im_gray, bbox).parts()] @@ -168,8 +171,8 @@ class Landmarks3D: points_formatted[f'{d}{idx}'] = pt[j] return points_formatted - def normalize(self, points, dim): - return [np.array(p)/dim for p in points] # divides each point by w,h dim + # def normalize(self, points): + # '''TODO''' class FaceAlignment3D_68(Landmarks3D): @@ -182,13 +185,14 @@ class FaceAlignment3D_68(Landmarks3D): device = f'cuda:{gpu}' if gpu > -1 else 'cpu' self.fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._3D, device=device, flip_input=flip_input) - def landmarks(self, im, as_type=str): + def landmarks(self, im, rect): '''Calculates the 3D facial landmarks :param im: (numpy.ndarray) BGR image + :param rect: (list) of face (x1, y1, x2, y2) :returns (list) of 68 (int) (tuples) as (x,y, z) ''' # predict landmarks - points = self.fa.get_landmarks(im) # returns array of arrays of 68 3D pts/face + points = self.fa.get_landmarks(im, [rect]) # returns array of arrays of 68 3D pts/face # convert to data type points = [list(map(int, p)) for p in points[0]] return points
\ No newline at end of file |
