Exemplo n.º 1
0
def face_grouping(uid, face_image_url):
    api = API(constant.FACEPP_API_KEY, constant.FACEPP_API_SECRET)
    rst = api.faceset.create()
    faceset_id = rst['faceset_id']
    for url in face_image_url:
        for face in face_image_url[url]['face']:
            res = api.faceset.add_face(faceset_id=faceset_id, face_id = face['face_id'])
    session_id = api.grouping.grouping(faceset_id = faceset_id)
    session_id = session_id['session_id']
    rst = api.wait_async(session_id)
    api.faceset.delete(faceset_id=faceset_id)
    if not rst.has_key('result'):
        raise Exception('API return error')
    return rst['result']
Exemplo n.º 2
0
class ImageDetector:
    ''' Image Detector class demo'''
    file_path = None
    api = None

    def __init__(self, file_path):
        self.file_path = file_path
        self.api = API(API_KEY, API_SECRET)

    def detect(self):
        file = File(self.file_path)
        middle_result = self.api.detection.detect(img=file)
        result = self.api.wait_async(middle_result["session_id"])
        return len(result['result']['face'])
Exemplo n.º 3
0
    print_result('create person {}'.format(name), rst)

# Step 3: create a new group and add those persons in it
# 步骤3:.创建Group,将之前创建的Person加入这个Group
rst = api.group.create(group_name='test')
print_result('create group', rst)
rst = api.group.add_person(group_name='test', person_name=FACES.iterkeys())
print_result('add these persons to group', rst)

# Step 4: train the model
# 步骤4:训练模型
rst = api.train.identify(group_name='test')
print_result('train', rst)
# wait for training to complete
# 等待训练完成
rst = api.wait_async(rst['session_id'])
print_result('wait async', rst)

# Step 5: recognize face in a new image
# 步骤5:识别新图中的Face
rst = api.recognition.identify(group_name='test', url=TARGET_IMAGE)
print_result('recognition result', rst)
print '=' * 60
print 'The person with highest confidence:', \
        rst['face'][0]['candidate'][0]['person_name']

# Finally, delete the persons and group because they are no longer needed
# 最终,删除无用的person和group
api.group.delete(group_name='test')
api.person.delete(person_name=FACES.iterkeys())
Exemplo n.º 4
0
            person_name = name, face_id = faces)

# Step 3: create a new group and add those persons in it
# 步骤3:.创建Group,将之前创建的Person加入这个Group
#rst = api.group.create(group_name = 'test')
#print_result('create group', rst)
rst = api.group.add_person(group_name = 'test', person_name = FACES.iterkeys())
print_result('add these persons to group', rst)

# Step 4: train the model
# 步骤4:训练模型
rst = api.train.identify(group_name = 'test')
print_result('train', rst)
# wait for training to complete
# 等待训练完成
rst = api.wait_async(rst['session_id'])
print_result('wait async', rst)

# Step 5: recognize face in a new image
# 步骤5:识别新图中的Face
rst = api.recognition.identify(group_name = 'test', img = File(TARGET_IMAGE))
print_result('recognition result', rst)
print '=' * 60
print 'The person with highest confidence:', \
        rst['face'][0]['candidate'][0]['person_name']

# Finally, delete the persons and group because they are no longer needed
# 最终,删除无用的person和group
#api.group.delete(group_name = 'test')
#api.person.delete(person_name = FACES.iterkeys())
Exemplo n.º 5
0
    print_result("create person {}".format(name), rst)

# Step 3: create a new group and add those persons in it
# 步骤3:.创建Group,将之前创建的Person加入这个Group
rst = api.group.create(group_name="test")
print_result("create group", rst)
rst = api.group.add_person(group_name="test", person_name=FACES.iterkeys())
print_result("add these persons to group", rst)

# Step 4: train the model
# 步骤4:训练模型
rst = api.train.identify(group_name="test")
print_result("train", rst)
# wait for training to complete
# 等待训练完成
rst = api.wait_async(rst["session_id"])
print_result("wait async", rst)

# Step 5: recognize face in a new image
# 步骤5:识别新图中的Face
rst = api.recognition.identify(group_name="test", url=TARGET_IMAGE)
print_result("recognition result", rst)
print "=" * 60
print "The person with highest confidence:", rst["face"][0]["candidate"][0]["person_name"]

# Finally, delete the persons and group because they are no longer needed
# 最终,删除无用的person和group
api.group.delete(group_name="test")
api.person.delete(person_name=FACES.iterkeys())

# Congratulations! You have finished this tutorial, and you can continue