Example #1
0
def compare_file(filepath1, filepath2, return_landmark=0):
    if isNull(filepath1) or isNull(filepath2):
        return
    http_url = "https://api-cn.faceplusplus.com/facepp/v3/compare"

    key = get_key()

    secret = get_secret()

    data = {
        "api_key": key,
        "api_secret": secret,
        "return_landmark": return_landmark
    }

    files = {
        "image_file1": open(filepath1, "rb"),
        "image_file2": open(filepath2, "rb")
    }

    response = requests.post(http_url, data=data, files=files)

    req_con = response.content.decode('utf-8')

    req_dict = JSONDecoder().decode(req_con)

    print(req_dict)

    with open('result_json/compare_file.json', 'w') as json_file:
        json_file.write(json.dumps(req_dict, indent=2))
    return req_dict
Example #2
0
def analyze_face(face_token, return_landmark=0, return_attributes="none"):
    if isNull(face_token):
        return
    http_url = "https://api-cn.faceplusplus.com/facepp/v3/face/analyze"

    key = get_key()

    secret = get_secret()

    data = {
        "api_key": key,
        "api_secret": secret,
        "face_token": face_token,
        "return_landmark": return_landmark,
        "return_attributes": return_attributes
    }

    response = requests.post(http_url, data=data)

    req_con = response.content.decode('utf-8')

    req_dict = JSONDecoder().decode(req_con)

    print(req_dict)

    with open('result_json/analyze_face.json', 'w') as json_file:
        json_file.write(json.dumps(req_dict, indent=2))
    return req_dict
Example #3
0
def compare_facetokens(face_token1, face_token2, return_landmark=0):
    if isNull(face_token1) or isNull(face_token2):
        return
    http_url = "https://api-cn.faceplusplus.com/facepp/v3/compare"

    key = get_key()

    secret = get_secret()

    data = {
        "api_key": key,
        "api_secret": secret,
        "return_landmark": return_landmark,
        "face_token1": face_token1,
        "face_token2": face_token2
    }

    response = requests.post(http_url, data=data)

    req_con = response.content.decode('utf-8')

    req_dict = JSONDecoder().decode(req_con)

    print(req_dict)

    with open('result_json/compare_facetokens.json', 'w') as json_file:
        json_file.write(json.dumps(req_dict, indent=2))
    return req_dict
Example #4
0
def setUserID_face(face_token, user_id):
    if isNull(face_token) or isNull(user_id):
        return
    http_url = "https://api-cn.faceplusplus.com/facepp/v3/face/setuserid"

    key = get_key()

    secret = get_secret()

    data = {
        "api_key": key,
        "api_secret": secret,
        "face_token": face_token,
        "user_id": user_id
    }

    response = requests.post(http_url, data=data)

    req_con = response.content.decode('utf-8')

    req_dict = JSONDecoder().decode(req_con)

    print(req_dict)

    with open('result_json/setUserID_face.json', 'w') as json_file:
        json_file.write(json.dumps(req_dict, indent=2))
    return req_dict
Example #5
0
def detect(filepath, return_landmark=0, return_attributes="none"):
    if isNull(filepath):
        return
    http_url = "https://api-cn.faceplusplus.com/facepp/v3/detect"

    key = get_key()

    secret = get_secret()

    data = {
        "api_key": key,
        "api_secret": secret,
        "return_landmark": return_landmark,
        "return_attributes": return_attributes
    }

    files = {"image_file": open(filepath, "rb")}

    response = requests.post(http_url, data=data, files=files)

    req_con = response.content.decode('utf-8')

    req_dict = JSONDecoder().decode(req_con)

    print(req_dict)

    with open('result_json/detect_test_image.json', 'w') as json_file:
        json_file.write(json.dumps(req_dict, indent=2))
    return req_dict
Example #6
0
def removeFace_faceSet(faceset_token, face_tokens):
    if isNull(faceset_token) or isNull(face_tokens):
        return
    http_url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/removeface"

    key = get_key()

    secret = get_secret()

    data = {
        "api_key": key,
        "api_secret": secret,
        "faceset_token": faceset_token,
        "face_tokens": face_tokens
    }

    response = requests.post(http_url, data=data)

    req_con = response.content.decode('utf-8')

    req_dict = JSONDecoder().decode(req_con)

    print(req_dict)

    with open('result_json/removeFace_faceSet.json', 'w') as json_file:
        json_file.write(json.dumps(req_dict, indent=2))
    return req_dict
Example #7
0
def create_faceSet(display_name="",
                   outer_id="",
                   tags="",
                   face_tokens="",
                   user_data="",
                   force_merge=0):
    http_url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/create"

    key = get_key()

    secret = get_secret()

    data = {
        "api_key": key,
        "api_secret": secret,
        "display_name": display_name,
        "outer_id": outer_id,
        "tags": tags,
        "face_tokens": face_tokens,
        "user_data": user_data,
        "force_merge": force_merge
    }
    if display_name == "":
        del data["display_name"]
    if outer_id == "":
        del data["outer_id"]
    if tags == "":
        del data["tags"]
    if face_tokens == "":
        del data["face_tokens"]
    if user_data == "":
        del data["user_data"]

    response = requests.post(http_url, data=data)

    req_con = response.content.decode('utf-8')

    req_dict = JSONDecoder().decode(req_con)

    print(req_dict)

    with open('result_json/create_faceSet.json', 'w') as json_file:
        json_file.write(json.dumps(req_dict, indent=2))
    return req_dict
Example #8
0
def get_faceSet(tags="", start=1):
    http_url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets"

    key = get_key()

    secret = get_secret()

    data = {"api_key": key, "api_secret": secret, "tags": tags, "start": start}
    if tags == "":
        del data["tags"]
    response = requests.post(http_url, data=data)

    req_con = response.content.decode('utf-8')

    req_dict = JSONDecoder().decode(req_con)

    print(req_dict)

    with open('result_json/get_faceSet.json', 'w') as json_file:
        json_file.write(json.dumps(req_dict, indent=2))
    return req_dict