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


Python face_recognition.face_locations方法代碼示例

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


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

示例1: detect_biggest_face

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def detect_biggest_face(img):
    '''
    Detect biggest face in image
    :param img: cv::mat HxWx3 RGB
    :return: 4 <x,y,w,h>
    '''
    # detect faces
    bbs = face_recognition.face_locations(img)

    max_area = float('-inf')
    max_area_i = 0
    for i, (y, right, bottom, x) in enumerate(bbs):
        area = (right - x) * (bottom - y)
        if max_area < area:
            max_area = area
            max_area_i = i

    if max_area != float('-inf'):
        y, right, bottom, x = bbs[max_area_i]
        return x, y, (right - x), (bottom - y)

    return None 
開發者ID:albertpumarola,項目名稱:GANimation,代碼行數:24,代碼來源:face_utils.py

示例2: dlib_face_det

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def dlib_face_det(image):
    # Detect and localize faces using dlib (via face_recognition).
    # Assumes only one face is in image passed.

    # Convert image from BGR (OpenCV ordering) to dlib ordering (RGB).
    rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    # Detect the (x, y)-coordinates of the bounding boxes
    # corresponding to each face in the input image.
    # NB: model='cnn' causes OOM.
    boxes = face_recognition.face_locations(rgb,
        number_of_times_to_upsample=2, model='hog')

    if len(boxes) == 0:
        print('*** no face found! ***')
        return None

    # Return bounding box coords in dlib format.
    return boxes 
開發者ID:goruck,項目名稱:edge-tpu-servers,代碼行數:21,代碼來源:encode_faces.py

示例3: find_and_save_face

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def find_and_save_face(web_file,face_file):
    # Load the jpg file into a numpy array
    image = face_recognition.load_image_file(web_file)
    print(image.dtype)
    # Find all the faces in the image
    face_locations = face_recognition.face_locations(image)

    print("I found {} face(s) in this photograph.".format(len(face_locations)))

    for face_location in face_locations:

        # Print the location of each face in this image
        top, right, bottom, left = face_location
        print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))

        # You can access the actual face itself like this:
        face_image = image[top:bottom, left:right]
        pil_image = Image.fromarray(face_image)
        pil_image.save(face_file) 
開發者ID:fendouai,項目名稱:FaceRank,代碼行數:21,代碼來源:find_faces_in_picture.py

示例4: upload

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def upload():
    print('tracker start')
    image_path = request.args.get('path').split(os.sep)[1:]
    print(image_path)
    image_path = os.sep.join(image_path)
    image_dir = os.path.dirname(image_path)
    image_name = os.path.basename(image_path)
    print(image_path)
    image = cv2.imread(image_path)
    faces = fr.face_locations(image,
                              number_of_times_to_upsample=0, model="cnn")
    index = 0

    for (top, right, bottom, left) in faces:
        imgFace = image[top:bottom, left:right]
        img_output = cv2.resize(imgFace, (299, 299),
                                interpolation=cv2.INTER_AREA)
        face_path = os.path.join(image_dir, str(index) + image_name)
        index += 1
        cv2.imwrite(face_path, img_output)
    os.remove(image_path)
    print('tracker end')
    return 'true' 
開發者ID:seongahjo,項目名稱:Mosaicer,代碼行數:25,代碼來源:web.py

示例5: face_process

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def face_process():
    myprint("face process start",time.time())
    # Find all the faces and face encodings in the current frame of video
    # face_locations = face_recognition.face_locations(rgb_small_frame, model="cnn")
    myprint('face_locations start', time.time())
    face_locations = face_recognition.face_locations(rgb_small_frame, model="hog")
    myprint('face_locations end', time.time())
    myprint('face_encodings start', time.time())
    face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
    myprint('face_encodings end', time.time())
    face_names = []
    for face_encoding in face_encodings:
        # optimize start 采用KNN 排名*權重, 在類別上進行疊加,然後排序取出top1
        name, dis = vote_class(face_encoding)
        # optimize end 采用 排名*權重, 在類別上進行疊加,然後排序取出top1
        face_names.append(name)  # 將人臉數據

    # Display the results
    for (top, right, bottom, left), name in zip(face_locations, face_names):
        # Scale back up face locations since the frame we detected in was scaled to 1/4 size
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4
        myprint('putText start', time.time())
        # Draw a box around the face
        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
        # Draw a label with a name below the face
        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
        font = cv2.FONT_HERSHEY_DUPLEX
        cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
        myprint("putText end " + name, time.time())
        # say hello and save record to file
        myprint('process_face_records start', time.time())
        process_face_records(name)
        myprint('process_face_records end', time.time())

    # Display the resulting image
    cv2.imshow('Video', frame)
    myprint("face process end", time.time()) 
開發者ID:matiji66,項目名稱:face-attendance-machine,代碼行數:42,代碼來源:facerec_from_webcam_faster.py

示例6: __init__

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def __init__(self, path, load_first_face = True):
        super().__init__(path)
        self.faces = {}
        self.coordinates = {}  # stores the face (locations center, rotation, length)
        self.last_frame = self.get(0)
        self.frame_shape = self.last_frame.shape[:2]
        self.last_location = (0, 200, 200, 0)
        if (load_first_face):
            face_positions = face_recognition.face_locations(self.last_frame, number_of_times_to_upsample=2)
            if len(face_positions) > 0:
                self.last_location = face_positions[0] 
開發者ID:DariusAf,項目名稱:MesoNet,代碼行數:13,代碼來源:pipeline.py

示例7: constructIndexes

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def constructIndexes(self, label):
        valid_links = []
        console.section('Analyzing')
        file_name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
        file_name += '.jpg'
        tmp_path = os.path.join(tempfile.gettempdir(), file_name)
        console.task("Storing Image in {0}".format(tmp_path))
        for num, i in enumerate(self.profile_img):
            console.task('Analyzing {0}...'.format(i.strip()[:90]))
            urlretrieve(i, tmp_path)
            frame = cv2.imread(tmp_path)
            big_frame = cv2.resize(frame, (0, 0), fx=2.0, fy=2.0)
            rgb_small_frame = big_frame[:, :, ::-1]
            face_locations = face_recognition.face_locations(rgb_small_frame)
            face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations, num_jitters=self.num_jitters)
            face_names = []
            for face_encoding in face_encodings:
                # See if the face is a match for the known face(s)
                matches = face_recognition.compare_faces(self.known_face_encodings, face_encoding)
                name = "Unknown"
                # If a match was found in known_face_encodings, just use the first one.
                if True in matches:
                    first_match_index = matches.index(True)
                    name = self.known_face_names[first_match_index]
                face_names.append(name)

            for _, name in zip(face_locations, face_names):
                if name == label:
                    valid_links.append(num)
        if os.path.isfile(tmp_path):
            console.task("Removing {0}".format(tmp_path))
            os.remove(tmp_path)
        return valid_links 
開發者ID:ThoughtfulDev,項目名稱:EagleEye,代碼行數:35,代碼來源:face_recog.py

示例8: detect_faces

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def detect_faces(frame):
    face_locations = face_recognition.face_locations(frame)
    landmarks = _raw_face_landmarks(frame, face_locations)   

    for ((y, right, bottom, x), landmarks) in zip(face_locations, landmarks):
        yield DetectedFace(frame[y: bottom, x: right], x, right - x, y, bottom - y, landmarks)

# extract all faces in image 
開發者ID:DerWaldi,項目名稱:youtube-video-face-swap,代碼行數:10,代碼來源:face_extractor.py

示例9: _raw_face_landmarks

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def _raw_face_landmarks(face_image, face_locations):
    face_locations = [_css_to_rect(face_location) for face_location in face_locations]
    return [pose_predictor(face_image, face_location) for face_location in face_locations] 
開發者ID:DerWaldi,項目名稱:youtube-video-face-swap,代碼行數:5,代碼來源:face_extractor.py

示例10: reset

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def reset(self):
        self.face_relative_locations = []
        self.face_locations = []
        self.faces = [] 
開發者ID:AIInAi,項目名稱:tf-insightface,代碼行數:6,代碼來源:face_track_server.py

示例11: process

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def process(self, frame):
        self.reset()
        self.cam_h, self.cam_w, _ = frame.shape
        # Resize frame of video to 1/4 size for faster face recognition processing
        small_frame = cv2.resize(frame, (0, 0), fx=self.down_scale_factor, fy=self.down_scale_factor)

        # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
        rgb_small_frame = small_frame[:, :, ::-1]
        self.face_locations = face_recognition.face_locations(rgb_small_frame)
        # Display the results
        for y1_sm, x2_sm, y2_sm, x1_sm in self.face_locations:
            # Scale back up face locations since the frame we detected in was scaled to 1/4 size
            x1 = int(x1_sm / self.down_scale_factor)
            x2 = int(x2_sm / self.down_scale_factor)
            y1 = int(y1_sm / self.down_scale_factor)
            y2 = int(y2_sm / self.down_scale_factor)

            x1_rltv = x1 / self.cam_w
            x2_rltv = x2 / self.cam_w
            y1_rltv = y1 / self.cam_h
            y2_rltv = y2 / self.cam_h

            _face_area = frame[x1:x2, y1:y2, :]
            if _face_area.size == 0:
                continue
            self.faces.append(_face_area)
            self.face_relative_locations.append([x1_rltv, y1_rltv, x2_rltv, y2_rltv])
            # cv2.imshow('faces', frame[y1:y2, x1:x2, :])
            # cv2.waitKey(0)
        print('[FaceTracker Server] Found {} faces!'.format(len(self.faces)))
        return self.faces 
開發者ID:AIInAi,項目名稱:tf-insightface,代碼行數:33,代碼來源:face_track_server.py

示例12: get_face_and_save

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def get_face_and_save(path):
    image_path = f'{IMAGES_PATH}/{path}'
    image = face_recognition.load_image_file(image_path)
    locations = face_recognition.face_locations(image)
    if len(locations) == 1:  # save the face of mm
        top, right, bottom, left = locations[0]
        face_image = image[top:bottom, left:right]
        pil_image = Image.fromarray(face_image)
        with open(f'{IMAGES_PATH}/faces/face-{path}', "wb") as f:
            pil_image.save(f)
    return len(locations) 
開發者ID:nladuo,項目名稱:MMFinder,代碼行數:13,代碼來源:filter_images.py

示例13: get_face_and_save

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def get_face_and_save(filename):
    img_path = f"{UPLOAD_DIR}/{filename}"
    image = face_recognition.load_image_file(img_path)
    locations = face_recognition.face_locations(image)
    if len(locations) == 1:  # save the face of mm
        top, right, bottom, left = locations[0]
        face_image = image[top:bottom, left:right]
        pil_image = Image.fromarray(face_image)
        with open(f"{UPLOAD_DIR}/face-{filename}", "wb") as f:
            pil_image.save(f)
    return len(locations) 
開發者ID:nladuo,項目名稱:MMFinder,代碼行數:13,代碼來源:web_service.py

示例14: detect_faces

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def detect_faces(img):
    '''
    Detect faces in image
    :param img: cv::mat HxWx3 RGB
    :return: yield 4 <x,y,w,h>
    '''
    # detect faces
    bbs = face_recognition.face_locations(img)

    for y, right, bottom, x in bbs:
        # Scale back up face bb
        yield x, y, (right - x), (bottom - y) 
開發者ID:albertpumarola,項目名稱:GANimation,代碼行數:14,代碼來源:face_utils.py

示例15: _img_morph

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_locations [as 別名]
def _img_morph(self, img, expresion):
        bbs = face_recognition.face_locations(img)
        if len(bbs) > 0:
            y, right, bottom, x = bbs[0]
            bb = x, y, (right - x), (bottom - y)
            face = face_utils.crop_face_with_bb(img, bb)
            face = face_utils.resize_face(face)
        else:
            face = face_utils.resize_face(img)

        morphed_face = self._morph_face(face, expresion)

        return morphed_face 
開發者ID:albertpumarola,項目名稱:GANimation,代碼行數:15,代碼來源:test.py


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