-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrasp_client.py
53 lines (40 loc) · 1.2 KB
/
rasp_client.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
import requests
import cv2
from imutils.video.pivideostream import PiVideoStream
import imutils
import time
import numpy as np
base_url = '35.236.20.13'
class VideoCamera(object):
def __init__(self, flip = False):
self.vs = PiVideoStream().start()
self.flip = flip
def __del__(self):
self.vs.stop()
def flip_if_needed(self, frame):
if self.flip:
return np.flip(frame, 0)
return frame
def get_frame(self):
frame = self.flip_if_needed(self.vs.read())
ret, jpeg = cv2.imencode('.jpg', frame)
return jpeg.tobytes()
def post_image(self):
img = self.get_frame()
url = 'http://' + base_url + '/prediction'
files = {'file': img}
response = requests.post(url, files=files)
return response
def main():
pi_camera = VideoCamera(flip=False)
# base_url = input('Server URL: ') + ':5000'
while True:
print('Requesting prediction to http://' + base_url + '/prediction')
res = pi_camera.post_image()
print(res)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
time.sleep(5)
print('END')
if __name__ == '__main__':
main()