[Nanonets] How to post Memo [Python]

Object detection

import requests
import cv2
import json
import time

url =Given URL

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

path = './testdir/test1.jpg'#Free path

#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('Given', ''), files=file)
response = requests.post(url, auth=requests.auth.HTTPBasicAuth('Given', ''), data=data)
end = time.time()
print("Post time", end-start, "Seconds")
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()

Image classification

import requests
import time

url = 'Given'

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': 'Given'}

    start = time.time()

    response = requests.request('POST', url, headers=headers, auth=requests.auth.HTTPBasicAuth('Given', ''), data=data, files=file)

    end = time.time()
    print("Post time", end - start, "Seconds")

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

Recommended Posts

[Nanonets] How to post Memo [Python]
How to install Python
[First post] Question ・ How to sweep out python
Post from Python to Slack
How to install Python [Windows]
Post to vim → Python → Slack
python3: How to use bottle (2)
How to update Python Tkinter to 8.6
Post to slack with Python 3
How to use Python argparse
[Python] How to use checkio
How to run Notepad ++ Python
How to change Python version
[python] How to judge scalar
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
Post to Slack in Python
How to use Python bytes
[Python] How to run Jupyter-notebook + pandas + multiprocessing (Pool) [pandas] Memo
How to install python using anaconda
How to write a Python class
[Python] How to do PCA in Python
Python memo
[Python] How to derive nCk (ABC156-D)
[Python] How to use Pandas Series
How to collect images in Python
python memo
Post from python to facebook timeline
How to use Requests (Python Library)
How to use SQLite in Python
[Introduction to Python] How to parse JSON
[Lambda] [Python] Post to Twitter from Lambda!
Python memo
How to get the Python version
How to get started with Python
How to develop in a virtual environment of Python [Memo]
[Python] How to import the library
python memo
[Memo] How to use Google MµG
Get, post communication memo in Python
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
[Python] How to swap array values
How to wrap C in Python
How to use ChemSpider in Python
Python memo
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
How to speed up Python calculations
How to calculate date with python
How to access wikipedia from python
How to use python zip function
Easily post to twitter with Python 3
How to handle Japanese in Python
[Python] How to use Typetalk API
Python memo