1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Nanonets】ポストの仕方メモ【Python】

Last updated at Posted at 2020-01-06

物体検知

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()

画像分類

import requests
import time

url = '与えられる'

headers = {
  'accept': 'application/x-www-form-urlencoded'
}

nls = ["test1.jpg", "test2.jpg", "test3.jpg", "test4.jpg", "test5.jpg", "test6.jpg"]

for n in nls:
    path = n

    file = {'file': open(path, 'rb')}

    data = {'modelId': '与えられる'}

    start = time.time()

    response = requests.request('POST', url, headers=headers, auth=requests.auth.HTTPBasicAuth('与えられる', ''), data=data, files=file)

    end = time.time()
    print("ポスト時間", end - start, "")

    print(response.text)
    jsondata = response.json()
    result = jsondata["result"]
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?