-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
28 lines (22 loc) · 788 Bytes
/
client.py
File metadata and controls
28 lines (22 loc) · 788 Bytes
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
from __future__ import print_function
import requests
import json
import cv2
def post_image(img_file, URL):
""" post image and return the response """
img = open(img_file, 'rb').read()
response = requests.post(URL, data=img, headers=headers)
return response
addr = 'http://localhost:5000'
test_url = addr + '/stopzone'
# prepare headers for http request
content_type = 'image/jpeg'
headers = {'content-type': content_type}
img = cv2.imread('lena.jpg')
# encode image as jpeg
_, img_encoded = cv2.imencode('.jpg', img)
# send http request with image and receive response
response = requests.post(test_url, data=img_encoded.tostring(), headers=headers)
# decode response
print(json.loads(response.text))
# expected output: {u'message': u'image received. size=124x124'}