CDN加速

文档中心 API文档 AI服务 画质检测-分类

画质检测-分类

更新时间:2019-12-12 17:33:02
适用产品:定制化接口

接口描述

对图片的质量进行检测,输出该图的六种分类的概率值。类别顺序如下:(0-original,1-blur,2-motion,3-jpeg,4-gauss noise, 5-interlace)

请求参数

参数名称类型必填描述
filestring用户传上来的图片。采用base64加密

返回参数

参数名称类型描述
codestring返回调用结果的状态
messagestring调用接口,返回状态码的说明
datalist输出该图的六种分类的概率值;([9.4408315e-01 6.7628813e-03 4.2719811e-02 6.4078663e-03 3.2604017e-19 2.6257783e-05]) 类别顺序如下: (0-original,1-blur,2-motion,3-jpeg,4-gauss noise, 5-interlace)

错误码

错误代码(code)描述(message)HTTP状态码语义
30052002post字段没有图片内容200

示例

示例说明
请求示例
复制
#!/usr/bin/env python
# -- coding: utf-8 --


import requests
import sys
import os
import json
import base64
import time
from hashlib import sha256
url = 'http://open.chinanetcenter.com/ipq/v1/type/tag'
username = 'your name'
apikey = 'your apikey'
__curPath__ = os.path.split(os.path.realpath(__file__))[0]


def getDate():
    import datetime
    GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
    date_gmt = datetime.datetime.utcnow().strftime(GMT_FORMAT)
    print("getDate: " + date_gmt)
    return date_gmt


def sha(date):
    import hmac
    print("sha: " + date)
    signed_apikey = hmac.new(apikey.encode(
        'utf-8'), date.encode('utf-8'), sha256).digest()
    signed_apikey = base64.b64encode(signed_apikey)
    print("sha: " + signed_apikey.decode())
    return signed_apikey


def encode(time):
    print("encode: " + time.decode())
    msg = username + ":" + time.decode()
    result = base64.b64encode(msg.encode('utf-8'))
    print("encode: " + result.decode())
    return result


def getAuth():
    return encode(sha(getDate()))

def getABase64StrFromFile(fname):
    with open(fname, 'rb') as f:
        c = f.read()
        c = base64.b64encode(c)
        return str(c, encoding='utf-8') 

def connect(fname):
    auth = getAuth()
    auth = 'Basic ' + auth.decode()
    d = {'file': getABase64StrFromFile(fname)}
    headers = {'Content-Type': 'application/json', 'Accept': "application/json",
               "Date": getDate(), 'Authorization': auth}
    r = requests.post(url, headers=headers, data=json.dumps(d))
    ret = r.text
    print(ret)

if __name__ == '__main__':
    connect('./type.jpg')
返回示例
复制
{"code": "0", "message": "Success", "data": [[0.944083034992218, 0.0067628733813762665, 0.04271981492638588, 0.006407870911061764, 3.26046344080606e-19, 2.6257634090143256e-05]]}