def processImage(self, im, draw=True):
        # landmark Detection
        im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
        landmarks_2d, bbox = self.getLandmark(im_gray)

        # if no face deteced, return original image
        if landmarks_2d is None:
            return im, None

        # Headpose Detection
        t.tic()
        rvec, tvec, cm, dc = self.getHeadpose(im, landmarks_2d)
        if self.v: print(', hp: %.2f' % t.toc(), end='ms')

        t.tic()
        angles = self.getAngles(rvec, tvec)
        if self.v: print(', ga: %.2f' % t.toc(), end='ms')

        if draw:
            t.tic()
            draw = Draw(im, angles, bbox, landmarks_2d, rvec, tvec, cm, dc, b=10.0)
            im = draw.drawAll()
            if self.v: print(', draw: %.2f' % t.toc(), end='ms' + ' ' * 10)
         
        return im, angles
Exemple #2
0
    def processImage(self, im, draw=True):
        # landmark Detection
        im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
        landmarks_2d, bbox = self.getLandmark(im_gray)

        # if no face deteced, return original image
        if landmarks_2d is None:
            return im, None, None

        # Headpose Detection
        t.tic()
        rvec, tvec, cm, dc = self.getHeadpose(im, landmarks_2d)
##        print("\ntvec:\n {0}".format(tvec))
##        tx, ty, tz = tvec[:, 0]
##        print('getTvec tx: %s' % tx)
##        print('getTvec ty: %s' % ty)
##        print('getTvec tz: %s' % tz)
        if self.v: print(', hp: %.2f' % t.toc(), end='ms')

        t.tic()
        angles = self.getAngles(rvec, tvec)
        rx, ry, rz = angles


        if self.v: print(', ga: %.2f' % t.toc(), end='ms')

        if draw:
            t.tic()
            draw = Draw(im, angles, bbox, landmarks_2d, rvec, tvec, cm, dc, b=10.0)
            im = draw.drawAll()
            if self.v: print(', draw: %.2f' % t.toc(), end='ms' + ' ' * 10)

        return im, angles, tvec