import requests
import cv2
import json
import time
url = 与えられたURL
headers = {
'accept': 'application/x-www-form-urlencoded'
}
path = './testdir/test1.jpg'#自由なパス
# file = {'file': open(path, 'rb')}
data = {'urls' : ['https://goo.gl/ICoiHc', 'https://goo.gl/ICoiHc']}
start = time.time()
# response = requests.post(url, auth=requests.auth.HTTPBasicAuth('与えられる', ''), files=file)
response = requests.post(url, auth=requests.auth.HTTPBasicAuth('与えられる', ''), data=data)
end = time.time()
print("ポスト時間", end-start, "秒")
print(response.text)
jsondata = response.json()
result = jsondata["result"]
image = cv2.imread(path)
sep_score = 0.3
for r in result:
labells = []
score_ls = []
print(r)
for p in r["prediction"]:
print(p)
label, left, top, right, bottom, score = p["label"], p["xmin"], p["ymin"], p["xmax"], p["ymax"], p["score"]
if score >= sep_score and not label in labells:
labells.append(label)
score_ls.append(score_ls)
cv2.rectangle(image, (left, top), (right, bottom), (255, 0, 0), thickness=3)
color = (255, 0, 0)
fontScale = 1.0
fontFace = cv2.FONT_HERSHEY_COMPLEX
text = label + " " + str(round(score, 2))
org = (left, top)
cv2.putText(image, text, org, fontFace, fontScale, color, thickness=4, lineType=cv2.LINE_8)
cv2.imshow("pic", image)
cv2.waitKey(0)
cv2.destroyAllWindows()