facenet_task.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:face 作者: xpzouying 项目源码 文件源码
def detect_face_task(img):
    """Detect faces from image

    @input: image
    @output:
        - all faces information
    """

    # paramter for detect
    # image_size = 160
    # margin = 44
    minsize = 20 # minimum size of face
    threshold = [0.6, 0.7, 0.7]  # three steps's threshold
    factor = 0.709 # scale factor

    # caffe model
    pnet = caffe_model.get_pnet()
    rnet = caffe_model.get_rnet()
    onet = caffe_model.get_onet()

    bounding_boxes, _ = detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)
    print('detect bounding: ', bounding_boxes)
    print('Find faces: ', bounding_boxes.shape[0])

    # all_faces is faces information list, include face bytes, face position
    all_faces = []
    for face_position in bounding_boxes:
        face_position = face_position.astype(int)
        print('face position: ', face_position)

        # each face information, include position, face image
        head_rect = face_position[:4].tolist()  # numpy array to python list
        head_img = misc.toimage(img).crop(head_rect)
        head_img_io = StringIO.StringIO()
        head_img.save(head_img_io, format='JPEG')
        head_img_b64 = base64.b64encode(head_img_io.getvalue())

        # construct response
        face_info = {}
        face_info['rect'] = head_rect
        face_info['image'] = head_img_b64

        all_faces.append(face_info)

    return all_faces
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号