當前位置: 首頁>>代碼示例>>Python>>正文


Python dlib.cnn_face_detection_model_v1方法代碼示例

本文整理匯總了Python中dlib.cnn_face_detection_model_v1方法的典型用法代碼示例。如果您正苦於以下問題:Python dlib.cnn_face_detection_model_v1方法的具體用法?Python dlib.cnn_face_detection_model_v1怎麽用?Python dlib.cnn_face_detection_model_v1使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dlib的用法示例。


在下文中一共展示了dlib.cnn_face_detection_model_v1方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def __init__(self, device, path_to_detector=None, verbose=False):
        super().__init__(device, verbose)

        base_path = os.path.join(appdata_dir('face_alignment'), "data")

        # Initialise the face detector
        if 'cuda' in device:
            if path_to_detector is None:
                path_to_detector = os.path.join(
                    base_path, "mmod_human_face_detector.dat")

                if not os.path.isfile(path_to_detector):
                    print("Downloading the face detection CNN. Please wait...")

                    path_to_temp_detector = os.path.join(
                        base_path, "mmod_human_face_detector.dat.download")

                    if os.path.isfile(path_to_temp_detector):
                        os.remove(os.path.join(path_to_temp_detector))

                    request_file.urlretrieve(
                        "https://www.adrianbulat.com/downloads/dlib/mmod_human_face_detector.dat",
                        os.path.join(path_to_temp_detector))

                    os.rename(os.path.join(path_to_temp_detector), os.path.join(path_to_detector))

            self.face_detector = dlib.cnn_face_detection_model_v1(path_to_detector)
        else:
            self.face_detector = dlib.get_frontal_face_detector() 
開發者ID:kwea123,項目名稱:VTuber_Unity,代碼行數:31,代碼來源:dlib_detector.py

示例2: __init__

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def __init__(self, is_dlib=False):

    # resolution of input and output image size.
    self.resolution_inp = 256
    self.resolution_op = 256

    # ---- load detectors
    if is_dlib:
      import dlib
      detector_path = _util.getRelWeightsPath('dlib', 'mmod_human_face_detector.dat')
      self.face_detector = dlib.cnn_face_detection_model_v1(detector_path)

    # ---- load PRN
    self.pos_predictor = PosPrediction(self.resolution_inp, self.resolution_op)
    prn_path = _util.getRelWeightsPath('prnet', 'net/256_256_resfcn256_weight')
    assert os.path.isfile(prn_path + '.data-00000-of-00001'), "please download PRN trained model first."
    self.pos_predictor.restore(prn_path)

    # uv file: 2 x 68
    self.uv_kpt_ind = np.loadtxt(_util.getRelWeightsPath('prnet', 'uv', 'uv_kpt_ind.txt')).astype(np.int32)
    #  get kpt: get valid vertices in the pos map
    self.face_ind = np.loadtxt(_util.getRelWeightsPath('prnet', 'uv', 'face_ind.txt')).astype(np.int32)
    # ntri x 3.
    self.triangles = np.loadtxt(_util.getRelWeightsPath('prnet', 'uv', 'triangles.txt')).astype(np.int32)

    self.uv_coords = self.generate_uv_coords()

    # Cache Position map.
    self.pos = None 
開發者ID:joseph-zhong,項目名稱:LipReading,代碼行數:31,代碼來源:prnet.py

示例3: __init__

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def __init__(self, is_dlib = False, prefix = '.'):

        # resolution of input and output image size.
        self.resolution_inp = 256
        self.resolution_op = 256

        #---- load detectors
        if is_dlib:
            import dlib
            detector_path = os.path.join(prefix, 'Data/net-data/mmod_human_face_detector.dat')
            self.face_detector = dlib.cnn_face_detection_model_v1(
                    detector_path)

        #---- load PRN 
        self.pos_predictor = PosPrediction(self.resolution_inp, self.resolution_op)
        prn_path = os.path.join(prefix, 'Data/net-data/256_256_resfcn256_weight')
        if not os.path.isfile(prn_path + '.data-00000-of-00001'):
            print(prn_path)
            print("please download PRN trained model first.")
            exit()
        self.pos_predictor.restore(prn_path)

        # uv file
        self.uv_kpt_ind = np.loadtxt(prefix + '/Data/uv/uv_kpt_ind.txt').astype(np.int32) # 2 x 68 get kpt
        self.face_ind = np.loadtxt(prefix + '/Data/uv/face_ind.txt').astype(np.int32) # get valid vertices in the pos map
        self.triangles = np.loadtxt(prefix + '/Data/uv/triangles.txt').astype(np.int32) # ntri x 3
        
        self.uv_coords = self.generate_uv_coords() 
開發者ID:joseph-zhong,項目名稱:LipReading,代碼行數:30,代碼來源:api.py

示例4: _dlib_face_detection

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def _dlib_face_detection(image):
    """
    Face detection using the CNN implementation from Dlib.

    References:
    Davis E. King. Dlib-ml: A Machine Learning Toolkit. Journal of Machine Learning Research 10, pp. 1755-1758, 2009

    :param image: (ndarray) Raw image
    :return: (ndarray) The coordinates of the detected face
    """
    global _FACE_DETECTOR_DLIB

    face_coordinates = []

    # Verifies if dlib is initialized
    if _FACE_DETECTOR_DLIB is None:
        _FACE_DETECTOR_DLIB = dlib.cnn_face_detection_model_v1('./model/utils/templates/dlib/cnn_face_detector.dat')

    # Calls dlib's face detection method
    faces = _FACE_DETECTOR_DLIB(image)

    # Gets coordinates
    if not (faces is None):
        for face_id, net_output in enumerate(faces):
            xi, xf, yi, yf = (net_output.rect.left(), net_output.rect.right(), net_output.rect.top(), net_output.rect.bottom())
            face_coordinates.append([[xi, yi], [xf, yf]])

    return np.array(face_coordinates) 
開發者ID:siqueira-hc,項目名稱:Efficient-Facial-Feature-Learning-with-Wide-Ensemble-based-Convolutional-Neural-Networks,代碼行數:30,代碼來源:cvision.py

示例5: _preload_dlib_detector_fitter

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def _preload_dlib_detector_fitter(self):
        r"""
        Returns the dlib face detector and the landmark fitters (5 and 68 landmarks)
        -------

        """

        if self._gpu is True:
            self._detect = dlib.cnn_face_detection_model_v1(self._detector_path)
        else:
            self._detect = dlib.get_frontal_face_detector()

        self._fitter5 = dlib.shape_predictor(self._predictor5_path)
        self._fitter68 = dlib.shape_predictor(self._predictor68_path) 
開發者ID:georgesterpu,項目名稱:pyVSR,代碼行數:16,代碼來源:roi.py

示例6: __init__

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def __init__(self, device, path_to_detector=None, verbose=False):
        super().__init__(device, verbose)

        print('Warning: this detector is deprecated. Please use a different one, i.e.: S3FD.')
        base_path = os.path.join(appdata_dir('face_alignment'), "data")

        # Initialise the face detector
        if 'cuda' in device:
            if path_to_detector is None:
                path_to_detector = os.path.join(
                    base_path, "mmod_human_face_detector.dat")

                if not os.path.isfile(path_to_detector):
                    print("Downloading the face detection CNN. Please wait...")

                    path_to_temp_detector = os.path.join(
                        base_path, "mmod_human_face_detector.dat.download")

                    if os.path.isfile(path_to_temp_detector):
                        os.remove(os.path.join(path_to_temp_detector))

                    request_file.urlretrieve(
                        "https://www.adrianbulat.com/downloads/dlib/mmod_human_face_detector.dat",
                        os.path.join(path_to_temp_detector))

                    os.rename(os.path.join(path_to_temp_detector), os.path.join(path_to_detector))

            self.face_detector = dlib.cnn_face_detection_model_v1(path_to_detector)
        else:
            self.face_detector = dlib.get_frontal_face_detector() 
開發者ID:1adrianb,項目名稱:face-alignment,代碼行數:32,代碼來源:dlib_detector.py

示例7: __init__

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def __init__(self, is_dlib = False, prefix = '.'):

        # resolution of input and output image size.
        self.resolution_inp = 256
        self.resolution_op = 256

        #---- load detectors
        if is_dlib:
            import dlib
            detector_path = os.path.join(prefix, 'Data/net-data/mmod_human_face_detector.dat')
            self.face_detector = dlib.cnn_face_detection_model_v1(
                    detector_path)

        #---- load PRN 
        self.pos_predictor = PosPrediction(self.resolution_inp, self.resolution_op)
        prn_path = os.path.join(prefix, 'Data/net-data/256_256_resfcn256_weight')
        if not os.path.isfile(prn_path + '.data-00000-of-00001'):
            print("please download PRN trained model first.")
            exit()
        self.pos_predictor.restore(prn_path)

        # uv file
        self.uv_kpt_ind = np.loadtxt(prefix + '/Data/uv-data/uv_kpt_ind.txt').astype(np.int32) # 2 x 68 get kpt
        self.face_ind = np.loadtxt(prefix + '/Data/uv-data/face_ind.txt').astype(np.int32) # get valid vertices in the pos map
        self.triangles = np.loadtxt(prefix + '/Data/uv-data/triangles.txt').astype(np.int32) # ntri x 3
        
        self.uv_coords = self.generate_uv_coords() 
開發者ID:YadiraF,項目名稱:PRNet,代碼行數:29,代碼來源:api.py

示例8: __init__

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def __init__(self, is_dlib = False):

        # resolution of input and output image size.
        self.resolution_inp = 256
        self.resolution_op = 256

        prefix = os.path.dirname(__file__)
        #---- load detectors
        if is_dlib:
            import dlib
            detector_path = os.path.join(prefix, 'Data/net-data/mmod_human_face_detector.dat')
            self.face_detector = dlib.cnn_face_detection_model_v1(
                    detector_path)

        #---- load PRN
        self.pos_predictor = PosPrediction(self.resolution_inp, self.resolution_op)
        prn_path = os.path.join(prefix, 'Data/net-data/256_256_resfcn256_weight')
        if not os.path.isfile(prn_path + '.data-00000-of-00001'):
            print("please download PRN trained model first.")
            exit()
        self.pos_predictor.restore(prn_path)

        # uv file
        self.uv_kpt_ind = np.loadtxt(prefix + '/Data/uv-data/uv_kpt_ind.txt').astype(np.int32) # 2 x 68 get kpt
        self.face_ind = np.loadtxt(prefix + '/Data/uv-data/face_ind.txt').astype(np.int32) # get valid vertices in the pos map
        self.triangles = np.loadtxt(prefix + '/Data/uv-data/triangles.txt').astype(np.int32) # ntri x 3
        self.canonical_vertices_fan = (np.load(prefix + '/Data/uv-data/canonical_vertices_68_fan.npy'))
        self.canonical_vertices_40 = np.load(prefix + '/Data/uv-data/canonical_vertices_40k.npy') # pos angle with 40k point, add by sai

        self.uv_coords = self.generate_uv_coords() 
開發者ID:bleakie,項目名稱:MaskInsightface,代碼行數:32,代碼來源:api.py

示例9: __init__

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def __init__(self, is_dlib = False, is_opencv = False, prefix = '.'):

        # resolution of input and output image size.
        self.resolution_inp = 256
        self.resolution_op = 256

        #---- load detectors
        if is_dlib:
            import dlib
            detector_path = os.path.join(prefix, 'Data/net-data/mmod_human_face_detector.dat')
            self.face_detector = dlib.cnn_face_detection_model_v1(
                    detector_path)

        if is_opencv:
            import cv2

        #---- load PRN 
        self.pos_predictor = PosPrediction(self.resolution_inp, self.resolution_op)
        prn_path = os.path.join(prefix, 'Data/net-data/256_256_resfcn256_weight')
        if not os.path.isfile(prn_path + '.data-00000-of-00001'):
            print("please download PRN trained model first.")
            exit()
        self.pos_predictor.restore(prn_path)

        # uv file
        self.uv_kpt_ind = np.loadtxt(prefix + '/Data/uv-data/uv_kpt_ind.txt').astype(np.int32) # 2 x 68 get kpt
        self.face_ind = np.loadtxt(prefix + '/Data/uv-data/face_ind.txt').astype(np.int32) # get valid vertices in the pos map
        self.triangles = np.loadtxt(prefix + '/Data/uv-data/triangles.txt').astype(np.int32) # ntri x 3 
開發者ID:clks-wzz,項目名稱:PRNet-Depth-Generation,代碼行數:30,代碼來源:api.py

示例10: get_face_detector

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def get_face_detector():
    """Get a singleton dlib face detector."""
    global _face_detector
    if not _face_detector:
        try:
            dat_path = _get_dlib_data_file('mmod_human_face_detector.dat')
            _face_detector = dlib.cnn_face_detection_model_v1(dat_path)
        except:
            xml_path = _get_opencv_xml('lbpcascade_frontalface_improved.xml')
            _face_detector = cv.CascadeClassifier(xml_path)
    return _face_detector 
開發者ID:swook,項目名稱:GazeML,代碼行數:13,代碼來源:frames.py

示例11: face_detection

# 需要導入模塊: import dlib [as 別名]
# 或者: from dlib import cnn_face_detection_model_v1 [as 別名]
def face_detection(
        img_path,
        verbose=False,
        model_file='utils/dlib_face_detector/mmod_human_face_detector.dat'):
    """
    Detects faces using dlib cnn face detection, and extend the bounding box
    to include the entire face.
    """
    def shrink(img, max_length=2048):
        ow, oh = img.size
        if max_length >= max(ow, oh):
            return img, 1.0

        if ow > oh:
            mult = max_length / ow
        else:
            mult = max_length / oh
        w = int(ow * mult)
        h = int(oh * mult)
        return img.resize((w, h), Image.BILINEAR), mult

    global cnn_face_detector
    if cnn_face_detector is None:
        cnn_face_detector = face_detect_model(model_file)

    img = Image.open(img_path).convert('RGB')
    w, h = img.size
    img_shrinked, mult = shrink(img)

    im = np.asarray(img_shrinked)
    if len(im.shape) != 3 or im.shape[2] != 3:
        return []

    crop_ims = []
    dets = cnn_face_detector(im, 0)
    for k, d in enumerate(dets):
        top = d.rect.top() / mult
        bottom = d.rect.bottom() / mult
        left = d.rect.left() / mult
        right = d.rect.right() / mult

        wid = right - left
        left = max(0, left - wid // 2.5)
        top = max(0, top - wid // 1.5)
        right = min(w - 1, right + wid // 2.5)
        bottom = min(h - 1, bottom + wid // 2.5)

        if d.confidence > 1:
            if verbose:
                print("%d-th face detected: (%d, %d, %d, %d)" %
                      (k, left, top, right, bottom))
            crop_im = img.crop((left, top, right, bottom))
            crop_ims.append((crop_im, (left, top, right, bottom)))

    return crop_ims 
開發者ID:PeterWang512,項目名稱:FALdetector,代碼行數:57,代碼來源:tools.py


注:本文中的dlib.cnn_face_detection_model_v1方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。