Exemplo n.º 1
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
Exemplo n.º 2
0
    def compare(self,
                file1,
                file2,
                ext_fields="",
                image_liveness="",
                types="",
                save_file=""):
        if isNull(file1) or isNull(file2):
            return
        http_url = HTTP_URL + "match?access_token=" + ACCESS_TOKEN

        # 二进制方式打开图片文件
        f1 = open(file1, 'rb')
        img1 = base64.b64encode(f1.read())
        f2 = open(file2, 'rb')
        img2 = base64.b64encode(f2.read())

        data = {"images": img1 + b',' + img2}
        if ext_fields != "":
            data["ext_fields"] = ext_fields
        if image_liveness != "":
            data["image_liveness"] = image_liveness
        if types != "":
            data["types"] = types

        return myRequest(http_url, data, save_file)
Exemplo n.º 3
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
Exemplo n.º 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
Exemplo n.º 5
0
    def verify(self, faceId1, faceId2, save_file=""):
        if isNull(faceId1) or isNull(faceId2):
            return
        http_url = HTTP_URL + "verify"

        data = {"faceId1": faceId1, "faceId2": faceId2}
        return myRequest(http_url, data, save_file)
Exemplo n.º 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
Exemplo n.º 7
0
    def search(self, filepath, group_id, save_file=""):
        if isNull(filepath) or isNull(group_id):
            return
        http_url = HTTP_URL + "identify"

        data = {"group_id": group_id}

        return myRequest(http_url, data, filepath, save_file)
Exemplo n.º 8
0
    def identify(self,crowd_id, face_id, save_file=""):
        if isNull(crowd_id) or isNull(face_id):
            return
        http_url = HTTP_URL+"face/Match/match_identify"

        data = {"crowd_id": crowd_id,
                "face_id": face_id}
        return myRequest(http_url, data, save_file)
Exemplo n.º 9
0
    def compare(self,file1, file2, save_file=""):
        if isNull(file1) or isNull(file2):
            return
        http_url = HTTP_URL+"face/Match/match_compare"

        params = {"face_id1": file1,
                "face_id2": file2}
        return myRequest_get(http_url, params, save_file)
Exemplo n.º 10
0
    def verify(self, face_id, people_id, save_file=""):
        if isNull(face_id) or isNull(people_id):
            return
        http_url = HTTP_URL+"face/Match/match_verify"

        data = {"face_id": face_id,
                "people_id": people_id}
        return myRequest(http_url, data, save_file)
Exemplo n.º 11
0
    def confirm(self,dynamicode, people_id, save_file=""):
        if isNull(dynamicode) or isNull(people_id):
            return
        http_url = HTTP_URL+"face/Match/match_confirm"

        data = {"dynamicode": dynamicode,
                "people_id": people_id}
        return myRequest(http_url, data, save_file)
Exemplo n.º 12
0
    def verify(self, filepath, person_id, save_file=""):
        if isNull(person_id) or isNull(filepath):
            return
        http_url = HTTP_URL + "verify"

        data = {"person_id": person_id}

        return myRequest(http_url, data, filepath, save_file)
Exemplo n.º 13
0
    def compare(self,file1, file2, type="life", save_file=""):
        if isNull(file1) or isNull(file2):
            return
        http_url = HTTP_URL+"recognition/compare_face"

        data = {"type": type}
        data["face_id1"] = file1
        data["face_id2"] = file2
        return myRequest( http_url, data, save_file)
Exemplo n.º 14
0
    def search(self,face_id, facegather_id, count=3, save_file=""):
        if isNull(face_id) or isNull(facegather_id):
            return
        http_url = HTTP_URL+"face/Match/match_search"

        data = {"face_id": face_id,
                "facegather_id": facegather_id,
                "count": count}

        return myRequest(http_url, data, save_file)
Exemplo n.º 15
0
    def search(self,face_token, faceset_token, return_result_count=1, save_file=""):
        if isNull(face_token) or isNull(faceset_token):
            return
        http_url = HTTP_URL+"search"


        data = {"face_token": face_token,
                "faceset_token": faceset_token,
                "return_result_count": return_result_count}

        return myRequest( http_url, data, save_file)
Exemplo n.º 16
0
    def search(self,face_id, faceset_id, limit=5, save_file=""):
        if isNull(face_id) or isNull(faceset_id):
            return
        http_url = HTTP_URL+"recognition/compare_face_faceset"


        data = {"face_id": face_id,
                "faceset_id": faceset_id,
                "limit": limit}

        return myRequest( http_url, data, save_file)
Exemplo n.º 17
0
    def copyUser(self, uid, src_group_id, save_file=""):
        if isNull(uid) or isNull(src_group_id):
            return
        http_url = HTTP_URL + "faceset/group/adduser?access_token=" + ACCESS_TOKEN

        data = {
            "group_id": self.group_id,
            "uid": uid,
            "src_group_id": src_group_id
        }

        return myRequest(http_url, data, save_file)
Exemplo n.º 18
0
    def copyPerson(self, person_id, src_group_id, save_file=""):
        if isNull(person_id) or isNull(src_group_id):
            return
        http_url = HTTP_URL + "faceset/group/addperson"

        data = {
            "group_id": self.group_id,
            "person_id": person_id,
            "src_group_id": src_group_id
        }

        return myRequest(http_url, data, save_file)
Exemplo n.º 19
0
    def search(self,
               filepath,
               group_id,
               ext_fields="",
               user_top_num=1,
               save_file=""):
        if isNull(filepath) or isNull(group_id):
            return
        http_url = HTTP_URL + "identify?access_token=" + ACCESS_TOKEN

        data = {"group_id": group_id, "user_top_num": user_top_num}
        if ext_fields != "":
            data["ext_fields"] = ext_fields

        return myRequest(http_url, data, filepath, save_file)
Exemplo n.º 20
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
Exemplo n.º 21
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
Exemplo n.º 22
0
    def search(self,
               name,
               selfie_file,
               image_auto_rotate="false",
               save_file=""):
        if isNull(name) or isNull(selfie_file):
            return
        http_url = HTTP_URL + "search/image/search"

        img = open(selfie_file, 'rb')
        data = {
            "name": name,
            "historical_selfie_file": img,
            "image_auto_rotate": image_auto_rotate
        }
        return myRequest(http_url, data, save_file)
Exemplo n.º 23
0
    def verify(self,
               filepath,
               uid,
               group_id,
               ext_fields="",
               top_num=1,
               save_file=""):
        if isNull(uid) or isNull(group_id) or isNull(filepath):
            return
        http_url = HTTP_URL + "verify?access_token=" + ACCESS_TOKEN

        data = {"uid": uid, "group_id": group_id, "top_num": top_num}
        if ext_fields != "":
            data["ext_fields"] = ext_fields

        return myRequest(http_url, data, filepath, save_file)
Exemplo n.º 24
0
    def deleteFace_Person(self, face_ids, save_file=""):
        if isNull(face_ids):
            return
        http_url = HTTP_URL + "delface"

        data = {"person_id": self.person_id, "face_ids": face_ids}

        return myRequest(http_url, data, save_file)
Exemplo n.º 25
0
    def removePerson_faceSet(self, person_uuid, save_file=""):
        if isNull(person_uuid):
            return
        http_url = HTTP_URL + "search/image/delete_person"

        data = {"name": self.name, "person_uuid": person_uuid}

        return myRequest(http_url, data, save_file)
Exemplo n.º 26
0
 def detect(self, filepath, max_face_num=1, face_fields="", save_file=""):
     if isNull(filepath):
         return
     http_url = HTTP_URL + "detect?access_token=" + ACCESS_TOKEN
     data = {"max_face_num": max_face_num}
     if face_fields != "":
         data["face_fields"] = face_fields
     return myRequest(http_url, data, filepath, save_file)
Exemplo n.º 27
0
    def deleteOneUser(self, uid, save_file=""):
        if isNull(uid):
            return
        http_url = HTTP_URL + "faceset/group/deleteuser?access_token=" + ACCESS_TOKEN

        data = {"uid": uid, "group_id": self.group_id}

        return myRequest(http_url, data, save_file)
Exemplo n.º 28
0
    def updateUser(self,
                   filepath,
                   user_info,
                   group_id,
                   action_type="",
                   save_file=""):
        if isNull(user_info) or isNull(group_id) or isNull(filepath):
            return
        http_url = HTTP_URL + "faceset/user/update?access_token=" + ACCESS_TOKEN

        data = {
            "uid": self.uid,
            "user_info": user_info,
            "group_id": group_id,
            "action_type": action_type
        }
        return myRequest(http_url, data, filepath, save_file)
Exemplo n.º 29
0
    def deleteOnePerson(self, person_id, save_file=""):
        if isNull(person_id):
            return
        http_url = HTTP_URL + "faceset/group/deleteperson"

        data = {"person_id": person_id, "group_id": self.group_id}

        return myRequest(http_url, data, save_file)
Exemplo n.º 30
0
    def addFace_Person(self, filepath, save_file=""):
        if isNull(filepath):
            return
        http_url = HTTP_URL + "addface"

        data = {"person_id": self.person_id}

        return myRequest(http_url, data, filepath, save_file)