CDN加速

信号灯检测

更新时间:2019-12-12 17:31:43

适用产品:定制化接口

接口描述

识别图片中的交通标志位置和状态

请求参数

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

返回参数

-
参数名称类型描述
codestring返回调用结果的状态
messagestring调用接口,返回状态码的说明
datalist返回识别到的红绿灯坐标和状态。返回内容为【左上y坐标, 左上x坐标, 右下y坐标, 右下x坐标],表示预测为物体的得分范围0-1,物体类别(红灯或绿灯)】

错误码

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

示例

PYTHON调用示例
示例说明
在采用python请求时,在编解码时,需添加 'Accept-Encoding': "deflate", 或增加gzip的编解码方法,或者其他编码的编解码方法。
请求示例
复制
#!/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/image/v1/traffic-light/recognition'

username = 'your username'
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",
                'Accept-Encoding': "deflate",
               "Date": getDate(), 'Authorization': auth}
    r = requests.post(url, headers=headers, data=json.dumps(d))
    print(dir(r))
    print(r)
    print(r.raw)
    ret = r.text
    print(ret)


if __name__ == '__main__':
    connect('./img/1.png')
返回示例