识别 示例图片
1 太平洋AI集装箱箱号识别接口(文档下方有详细操作指南)
1.1 接口一:提交base64格式的图片
地址:http://218.1.125.60:88/container_num_detect/container_num_detect_base64/
提交方式:post
接口参数:
{'img':img_base64}
返回值:
{
"msg":"ok", 状态信息
"code":"200", 状态码
"data":{
"container_number":"ONEU0345800" 箱号识别结果
}
}
python示例代码(可直接复制运行)
import requests
import base64
from urllib.request import urlretrieve # url定义端口
url="http://218.1.125.60:88/container_num_detect/container_num_detect_base64/" # 定义图片下载地址
IMAGE_URL = "http://po10jrblw.bkt.clouddn.com/7dd0eb85fec8b062697d2d7298eec04.jpg" # 发送图片请求并保存图片到当前目录
urlretrieve(IMAGE_URL, './imgs.jpg') # 定义取出刚刚保存的图片
img = "imgs.jpg" # 打开图片并编译为 BASE64格式
with open(img,'rb') as f:
rows = f.read()
imgBase64 = base64.b64encode(rows) # 准备post请求数据
data={'img':imgBase64}
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36'} # 发送post请求并获取结果 使用utf-8格式解码
res = requests.post(url,data=data,headers=headers) # 使用utf-8格式解码
res.encoding = 'utf-8'
# 拿到识别结果
html = res.text
print(html) # 返回数据
# {
# "msg":"ok", 状态信息
# "code":"200", 状态码
# "data":{
# "container_number":"ONEU0345800" 箱号识别结果
# }
# }
1.2 接口二:通过URL地址提交图片(例如七牛云图片链接)
地址:http://218.1.125.60:88/container_num_detect/container_num_detect_url/
提交方式:post
接口参数:
{'img':img_url}
返回值:
{
"msg":"ok", 状态信息
"code":"200", 状态码
"data":{
"container_number":"ONEU0345800" 箱号识别结果
}
}
python示例代码(可直接复制运行)
import requests
import json # 定义端口url
url="http://218.1.125.60:88/container_num_detect/container_num_detect_url/"
# 定义图片url
img = 'http://po10jrblw.bkt.clouddn.com/7dd0eb85fec8b062697d2d7298eec04.jpg' # 准备post请求数据
data={'img':img}
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36'} # 发送post请求
res = requests.post(url,data=data,headers=headers) # 使用 utf-8 解码
res.encoding = 'utf-8'
# 获取识别结果
detect_res = res.text
print(detect_res) # 返回数据
# {
# "msg":"ok", 状态信息
# "code":"200", 状态码
# "data":{
# "container_number":"ONEU0345800" 箱号识别结果
# }
# }
参考链接:http://www.fp-ai.com/article_details.html?id=33e75ff09dd601bbe69f351039152189