Ejemplo n.º 1
0
def call_api():
    data = {
        'api_key': API_KEY,
        'api_secret': API_SECRET,
        'merge_rate': merge_rate
    }
    if template_rectangle:
        data.update({'template_rectangle': template_rectangle})
    if merge_rectangle:
        data.update({'merge_rectangle': merge_rectangle})

    template_file = get_input_file_path(
        os.path.abspath(os.path.dirname(__file__)), 'input1')
    merge_file = get_input_file_path(
        os.path.abspath(os.path.dirname(__file__)), 'input2')
    if not all([template_file, merge_file]):
        print('请将input1.png/input1.jpg, input2.png/input2.jpg文件放在mergeface目录下')
        return
    files = {
        'template_file': open(template_file, 'rb').read(),
        'merge_file': open(merge_file, 'rb').read()
    }

    resp = requests.post(MERGEFACE_PATH, data=data, files=files).json()
    base64_file = resp.get('result')
    if base64_file:
        with open(output_file, 'wb') as f:
            f.write(base64.b64decode(base64_file))
    resp.pop('result', None)
    print(resp)
Ejemplo n.º 2
0
def call_api():
    data = {
        'api_key': API_KEY,
        'api_secret': API_SECRET,
        'return_grayscale': return_grayscale
    }
    input_file = get_input_file_path(
        os.path.abspath(os.path.dirname(__file__)), 'input')
    if not input_file:
        print('请将input.png/input.jpg文件放在segment目录下')
        return
    files = {'image_file': open(input_file, 'rb').read()}
    resp = requests.post(SEGMENT_PATH, data=data, files=files).json()
    result_file = resp.get('result')
    body_image_file = resp.get('body_image')
    if result_file:
        with open(
                os.path.abspath(os.path.dirname(__file__)) + '/mask.png',
                'wb') as f:
            f.write(base64.b64decode(result_file))
    resp.pop('result', None)

    if body_image_file:
        with open(
                os.path.abspath(os.path.dirname(__file__)) + '/output.png',
                'wb') as f:
            f.write(base64.b64decode(body_image_file))
    resp.pop('body_image', None)
    print(resp)
Ejemplo n.º 3
0
def call_api():
    data = {
        'api_key': API_KEY,
        'api_secret': API_SECRET,
        'return_landmark': return_landmark
    }
    input_file = get_input_file_path(
        os.path.abspath(os.path.dirname(__file__)), 'input')
    if not input_file:
        print('请将input.png/input.jpg文件放在thousandlandmark目录下')
        return
    files = {'image_file': open(input_file, 'rb').read()}
    resp = requests.post(THOUSANDLANDMARK_PATH, data=data, files=files).json()
    print(resp)
Ejemplo n.º 4
0
def call_api():
    data = {
        'api_key': API_KEY,
        'api_secret': API_SECRET
    }
    input_file = get_input_file_path(os.path.abspath(os.path.dirname(__file__)), 'input')
    if not input_file:
        print('请将input.png/input.jpg文件放在skeleton目录下')
        return
    files = {
        'image_file': open(input_file, 'rb').read()
    }
    resp = requests.post(SKELETON_PATH, data=data, files=files).json()
    print(resp)
Ejemplo n.º 5
0
def call_api():
    data = {
        'api_key': API_KEY,
        'api_secret': API_SECRET,
        'outer_id': outer_id,
        'return_result_count': return_result_count
    }
    if face_rectangle:
        data.update({'face_rectangle': face_rectangle})
    input_file = get_input_file_path(
        os.path.abspath(os.path.dirname(__file__)), 'input')
    if not input_file:
        print('请将input.png/input.jpg文件放在search目录下')
        return
    files = {'image_file': open(input_file, 'rb').read()}
    resp = requests.post(SEARCH_PATH, data=data, files=files).json()
    print(resp)
Ejemplo n.º 6
0
def call_api():
    data = {
        'api_key': API_KEY,
        'api_secret': API_SECRET,
        'whitening': whitening,
        'smoothing': smoothing
    }
    input_file = get_input_file_path(
        os.path.abspath(os.path.dirname(__file__)), 'input')
    if not input_file:
        print('请将input.png/input.jpg文件放在beautify目录下')
        return
    files = {'image_file': open(input_file, 'rb').read()}
    resp = requests.post(BEAUTIFY_PATH, data=data, files=files).json()
    base64_file = resp.get('result')
    if base64_file:
        with open(output_file, 'wb') as f:
            f.write(base64.b64decode(base64_file))
    resp.pop('result', None)
    print(resp)