-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
36 lines (29 loc) · 939 Bytes
/
server.py
File metadata and controls
36 lines (29 loc) · 939 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
29
30
31
32
33
34
35
36
from flask import Flask, Response, request
from hardware import Car, getPCA
import cv2 as cv
from numpy import concatenate
car = Car(getPCA(), 15, 0, 0)
app = Flask('Car')
indexhtml = open('client.html').read()
middle = 80
turnangle = 30
car.servo.turn(middle)
@app.route('/')
def index():
return indexhtml
@app.route('/img')
def img():
car.updateCamera()
dsize = (car.camera.img.shape[1], car.camera.img.shape[0])
img = car.camera.img if car.camera.matrix is None else concatenate([car.camera.img, cv.resize(car.camera.thresholdedImage, dsize)], axis=1)
r = Response(cv.imencode('.png', img)[1].tobytes())
r.headers['Content-Type'] = 'image/png'
return r
@app.route('/setSpeed', methods=['POST'])
def setSpeed():
car.speed = int(request.args['speed'])
return 'ok'
@app.route('/turn', methods=['POST'])
def turn():
car.servo.turn(80+(turnangle*int(request.args['steer'])))
app.run(port=8000)