Ejemplo n.º 1
0
def huawei_image_tagging_by_str_stream(ret, str_stream):
    token = get_token(huawei_username, huawei_password, huawei_account_name)
    base64_encoded_str = base64.b64encode(str_stream)
    result = image_tagging(token, base64_encoded_str, '', 'en', 5, 60)
    huawei_res_processing(ret, result)
from ais_sdk.gettoken import get_token
from ais_sdk.utils import encode_to_base64
from ais_sdk.utils import decode_to_wave_file
from ais_sdk.distortion_correct import distortion_correct
import json

if __name__ == '__main__':
    #
    # access moderation distortion correct post data by token
    #
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use

    demo_data_url = 'https://ais-sample-data.obs.cn-north-1.myhwclouds.com/vat-invoice.jpg'
    token = get_token(user_name, password, account_name)

    #call interface use the url correction is true means do not correction
    result = distortion_correct(token, "", demo_data_url, True)
    result_obj = json.loads(result)
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'],
                            'data/modeation-distortion-token-1.png')
    else:
        print result

    # call interface use the file
    result = distortion_correct(
        token, encode_to_base64('data/modeation-distortion.jpg'), '', True)
    result_obj = json.loads(result)
    if result_obj['result']['data'] != '':
Ejemplo n.º 3
0
def huawei_image_tagging_by_url(ret, url):
    token = get_token(huawei_username, huawei_password, huawei_account_name)
    str_stream = requests.get(url).content
    base64_encoded_str=base64.b64encode(str_stream)
    result = image_tagging(token, base64_encoded_str, '', 'en', 5, 60)
    huawei_res_processing(ret, result)