当前位置: 首页>>代码示例>>Python>>正文


Python dlib.shape_predictor方法代码示例

本文整理汇总了Python中dlib.shape_predictor方法的典型用法代码示例。如果您正苦于以下问题:Python dlib.shape_predictor方法的具体用法?Python dlib.shape_predictor怎么用?Python dlib.shape_predictor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dlib的用法示例。


在下文中一共展示了dlib.shape_predictor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def test(image_path, model_path):
    '''Test the given model by showing the detected landmarks.
        - image_path: the path of an image. Should contain a face.
        - model_path: the path of a shape predictor model.
    '''
    image = cv2.imread(image_path)
    face_detector = dlib.get_frontal_face_detector()
    dets = face_detector(image, 1)
    predictor = dlib.shape_predictor(model_path)

    for d in dets:
      cv2.rectangle(image, (d.left(), d.top()), (d.right(), d.bottom()), 255, 1)
      shape = predictor(image, d)
      for i in range(shape.num_parts):
        p = shape.part(i)
        cv2.circle(image, (p.x, p.y), 2, 255, 1)
        cv2.putText(image, str(i), (p.x + 4, p.y), cv2.FONT_HERSHEY_SIMPLEX, 0.25, (255, 255, 255))

    cv2.imshow("window", image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


# uncomment to test
# test("test_image.jpg", "shape_predictor.dat") 
开发者ID:Luca96,项目名称:dlib-minified-models,代码行数:27,代码来源:training_script.py

示例2: __init__

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def __init__(self, usage):
        self.usage = usage
        if self.usage == 'train':
            print('loading train samples')
            self.image_folder = image_folder
            if os.path.isfile('data/train_triplets.json'):
                with open('data/train_triplets.json', 'r') as file:
                    self.samples = json.load(file)
            else:
                self.samples = get_random_triplets('train')
        else:
            print('loading valid samples(LFW)')
            self.image_folder = lfw_folder
            with open('data/lfw_val_triplets.json', 'r') as file:
                self.samples = json.load(file)

        self.detector = dlib.get_frontal_face_detector()
        self.sp = dlib.shape_predictor(predictor_path) 
开发者ID:foamliu,项目名称:FaceNet,代码行数:20,代码来源:data_generator.py

示例3: predict

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def predict(image, model, shape_predictor=None):
    # get landmarks
    if NETWORK.use_landmarks or NETWORK.use_hog_and_landmarks or NETWORK.use_hog_sliding_window_and_landmarks:
        face_rects = [dlib.rectangle(left=0, top=0, right=NETWORK.input_size, bottom=NETWORK.input_size)]
        face_landmarks = np.array([get_landmarks(image, face_rects, shape_predictor)])
        features = face_landmarks
        if NETWORK.use_hog_sliding_window_and_landmarks: 
            hog_features = sliding_hog_windows(image)
            hog_features = np.asarray(hog_features)
            face_landmarks = face_landmarks.flatten()
            features = np.concatenate((face_landmarks, hog_features))
        else:
            hog_features, _ = hog(image, orientations=8, pixels_per_cell=(16, 16),
                                    cells_per_block=(1, 1), visualise=True)
            hog_features = np.asarray(hog_features)
            face_landmarks = face_landmarks.flatten()
            features = np.concatenate((face_landmarks, hog_features))
        tensor_image = image.reshape([-1, NETWORK.input_size, NETWORK.input_size, 1])
        predicted_label = model.predict([tensor_image, features.reshape((1, -1))])
        return get_emotion(predicted_label[0])
    else:
        tensor_image = image.reshape([-1, NETWORK.input_size, NETWORK.input_size, 1])
        predicted_label = model.predict(tensor_image)
        return get_emotion(predicted_label[0])
    return None 
开发者ID:amineHorseman,项目名称:facial-expression-recognition-using-cnn,代码行数:27,代码来源:predict.py

示例4: _setup_predictor

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def _setup_predictor(self, predictor_path):
        if not os.path.exists(predictor_path):
            # Download predictor file
            url = FaceDetector.predictor_url
            bz2_path = os.path.basename(url)

            logger.info('Download to "%s"', bz2_path)
            urllib.request.urlretrieve(url, bz2_path)

            logger.info('Expand to "%s"', predictor_path)
            data = bz2.BZ2File(bz2_path).read()
            open(predictor_path, 'wb').write(data)

            logger.info('Remove temporary file ("%s")', bz2_path)
            os.remove(bz2_path)

        # Deserialize
        predictor = dlib.shape_predictor(predictor_path)

        return predictor 
开发者ID:takiyu,项目名称:portrait_matting,代码行数:22,代码来源:face_detector.py

示例5: detect_fiducial_points

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def detect_fiducial_points(img, predictor_path):
    """
    Detect face landmarks and return the mean points of left and right eyes.
    If there are multiple faces in one image, only select the first one.
    """
    detector = dlib.get_frontal_face_detector()
    predictor = dlib.shape_predictor(predictor_path)
    dets = detector(img, 1)
    if len(dets) < 1:
        return [] 
    for k, d in enumerate(dets):
        shape = predictor(img, d)
        break
    landmarks = []
    for i in range(68):
        landmarks.append([shape.part(i).x, shape.part(i).y])
    landmarks = np.array(landmarks)
    left_eye = landmarks[36:42]
    right_eye = landmarks[42:48]
    mouth = landmarks[48:68]
    return np.array([np.mean(left_eye, 0), np.mean(right_eye, 0)]).astype('int') 
开发者ID:chaofengc,项目名称:Face-Sketch-Wild,代码行数:23,代码来源:face_rectify.py

示例6: startCapture

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def startCapture(self):
        self.setText("请稍候,正在初始化数据和摄像头。。。")
        try:
            # 检测相关
            self.detector = dlib.get_frontal_face_detector()
            self.predictor = dlib.shape_predictor(
                "Data/shape_predictor_68_face_landmarks.dat")
            cascade_fn = "Data/lbpcascades/lbpcascade_frontalface.xml"
            self.cascade = cv2.CascadeClassifier(cascade_fn)
            if not self.cascade:
                return QMessageBox.critical(self, "错误", cascade_fn + " 无法找到")
            self.cap = cv2.VideoCapture(0)
            if not self.cap or not self.cap.isOpened():
                return QMessageBox.critical(self, "错误", "打开摄像头失败")
            # 开启定时器定时捕获
            self.timer = QTimer(self, timeout=self.onCapture)
            self.timer.start(1000 / self.fps)
        except Exception as e:
            QMessageBox.critical(self, "错误", str(e)) 
开发者ID:PyQt5,项目名称:PyQt,代码行数:21,代码来源:FacePoints.py

示例7: __init__

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def __init__(self, specific_model):
        super(FaceDetectorSSD, self).__init__()
        self.specific_model = specific_model
        graph_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            DeepFaceConfs.get()['detector'][self.specific_model]['frozen_graph']
        )
        self.detector = self._load_graph(graph_path)

        self.tensor_image = self.detector.get_tensor_by_name('prefix/image_tensor:0')
        self.tensor_boxes = self.detector.get_tensor_by_name('prefix/detection_boxes:0')
        self.tensor_score = self.detector.get_tensor_by_name('prefix/detection_scores:0')
        self.tensor_class = self.detector.get_tensor_by_name('prefix/detection_classes:0')

        predictor_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            DeepFaceConfs.get()['detector']['dlib']['landmark_detector']
        )
        self.predictor = dlib.shape_predictor(predictor_path)

        config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True))
        self.session = tf.Session(graph=self.detector, config=config) 
开发者ID:ildoonet,项目名称:deepface,代码行数:24,代码来源:detector_ssd.py

示例8: get_landmarks

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def get_landmarks(img, resource_dir, verbose=False):
    # if not automatically downloaded, get it from:
    # http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2
    predictor_path = resource_dir + "/dlib_models/shape_predictor_68_face_landmarks.dat"
    detector = dlib.get_frontal_face_detector()
    predictor = dlib.shape_predictor(predictor_path)

    lmarks = []
    dets = detector(img, 1)
    if verbose:
        print("Number of faces detected: {}".format(len(dets)))
    shapes = []
    for k, det in enumerate(dets):
        shape = predictor(img, det)
        shapes.append(shape)
        xy = _shape_to_np(shape)
        lmarks.append(xy)

    lmarks = np.asarray(lmarks, dtype='float32')
    # display_landmarks(img, dets, shapes)
    return lmarks 
开发者ID:XiuweiHe,项目名称:EmotionClassifier,代码行数:23,代码来源:facial_feature_detector.py

示例9: __init__

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def __init__(self, facePredictor):
        """
        Instantiate an 'AlignDlib' object.

        :param facePredictor: The path to dlib's
        :type facePredictor: str
        """
        assert facePredictor is not None

        #pylint: disable=no-member
        self.detector = dlib.get_frontal_face_detector()
        self.predictor = dlib.shape_predictor(facePredictor) 
开发者ID:deepinsight,项目名称:insightface,代码行数:14,代码来源:align_dlib.py

示例10: __init__

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def __init__(self, facePredictor):
        """
        Instantiate an 'AlignDlib' object.
        :param facePredictor: The path to dlib's
        :type facePredictor: str
        """
        assert facePredictor is not None

        self.detector = dlib.get_frontal_face_detector()
        self.predictor = dlib.shape_predictor(facePredictor) 
开发者ID:yeziyang1992,项目名称:Python-Tensorflow-Face-v2.0,代码行数:12,代码来源:align_dlib.py

示例11: __init__

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def __init__(self, MDE: MainData):
		self.md = MDE

		self.detector = dlib.get_frontal_face_detector()
		self.sp = dlib.shape_predictor("shape_predictor_5_face_landmarks.dat") 
开发者ID:aangfanboy,项目名称:TripletLossFace,代码行数:7,代码来源:align_dataset.py

示例12: predictor

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def predictor(self):
        """
        预测我们的面部方向
        :return:
        """
        return shape_predictor('shape_predictor_68_face_landmarks.dat') 
开发者ID:tomoncle,项目名称:face-detection-induction-course,代码行数:8,代码来源:input_static_pic_to_gif2_for_class.py

示例13: __init__

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def __init__(self, saved=False):
        self.saved = saved  # 是否保存图片
        self.listener = True  # 启动参数
        self.video_capture = cv2.VideoCapture(0)  # 调用本地摄像头
        self.doing = False  # 是否进行面部面具
        self.speed = 0.1  # 面具移动速度
        self.detector = get_frontal_face_detector()  # 面部识别器
        self.predictor = shape_predictor("shape_predictor_68_face_landmarks.dat")  # 面部分析器
        self.fps = 4  # 面具存在时间基础时间
        self.animation_time = 0  # 动画周期初始值
        self.duration = self.fps * 4  # 动画周期最大值
        self.fixed_time = 4  # 画图之后,停留时间
        self.max_width = 500  # 图像大小
        self.deal, self.text, self.cigarette = None, None, None  # 面具对象 
开发者ID:tomoncle,项目名称:face-detection-induction-course,代码行数:16,代码来源:input_video_stream_paste_mask.py

示例14: _getSharedLandmarker

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def _getSharedLandmarker():
  global _landmarker
  if _landmarker is None:
    _landmarker = dlib.shape_predictor(_face_landmarks_path)
  return _landmarker 
开发者ID:joseph-zhong,项目名称:LipReading,代码行数:7,代码来源:face.py

示例15: __init__

# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import shape_predictor [as 别名]
def __init__(self, facePredictor):
        """
        Instantiate an 'AlignDlib' object.

        :param facePredictor: The path to dlib's
        :type facePredictor: str
        """
        assert facePredictor is not None

        self.detector = dlib.get_frontal_face_detector()
        self.predictor = dlib.shape_predictor(facePredictor) 
开发者ID:tornadomeet,项目名称:mxnet-face,代码行数:13,代码来源:align_face.py


注:本文中的dlib.shape_predictor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。