嫖百度的easyDL

百度的ezdl实验,进去玩玩,希望能学到点东西,用群里的数据,用百度的公有云,白嫖快乐。
接口调用的代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: UTF-8 -*-
import requests
import base64,json,cv2
file_path = 'test.jpg'#这里输入图片的地址即可
access_token = ''
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=szbFpD6Kkuv6Edgwsq4SpNn8&client_secret=Gqlr50aK8hgyZo6rGiL3nviyQrjBVV2M&'
response = requests.get(host)
if(response):
con = response.json()
access_token = con['access_token']

def get_file_content(file_path):
with open(file_path, 'rb') as fb:
return fb.read()
if access_token != '':
image = get_file_content(file_path)
image_base64 = base64.b64encode(image)
image_base64_utf8 = str(image_base64, encoding = 'utf-8')
request_url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/detection/galaxy_rubbish"

request_url += "?access_token=" + access_token
s = json.dumps({'image':image_base64_utf8})
response = requests.post(request_url, data = s, headers = {'Content-Type':'application/json'})
content = response.json()
results = content['results']
print(results)
image = cv2.imread(file_path)
cv2.namedWindow("capture",0)
cv2.resizeWindow("capture", 1200,1200)
font = cv2.FONT_HERSHEY_SIMPLEX
for con in results:
x1 = con['location']['left']
x2 = x1+con['location']['width']
y1 = con['location']['top']
y2 = y1+con['location']['height']
image = cv2.rectangle(image,(x1,y1),(x2,y2),(0,255,0),5)
image = cv2.putText(image,con['name']+str(con['score'])[:6],(x1,y2+20),font,1.2,(255,255,255),2)
cv2.imshow("capture", image)
cv2.waitKey(0)

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2015-2024 galaxy
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信