pip install -r requirements.txt
Start the server by
python main.py
The server will then be run at localhost:5000
- Raw images from uploaded from the Raspberry Pi are stored at the
uploads
folder. - After calling the
image/
endpoint, the annotated image (with bounding box and label) is stored in theruns
folder. - After calling the
stitch/
endpoint, the stitched image is located atruns/stitched.jpg
NORTH
: 0
EAST
: 2
SOUTH
: 4
WEST
: 6
+) Obstacles: the list of obstacles that need to navigate
+) big_turn: 0 -> turn 3-1; 1 -> turn 4-2
Sample json request body:
{
"obstacles":
[
{
"x": 4,
"y": 11,
"id": 1,
"d": 4
},
{
"x": 8,
"y": 18,
"id": 2,
"d": 4
},
{
"x": 9,
"y": 6,
"id": 3,
"d": 0
},
{
"x": 16,
"y": 11,
"id": 4,
"d": 6
},
{
"x": 16,
"y": 19,
"id": 5,
"d": 4
}
],
"big_turn" : 1
}
Sample json response:
"data": {
"commands": [
"FR30",
"BS30",
"FL30",
"SNAP1",
"FR30",
"BS20",
"FL30",
"FS10",
"SNAP2",
"BS50",
"FR30",
"FS10",
"SNAP4",
"BL30",
"FS30",
"SNAP3",
"BS20",
"BL30",
"BS10",
"BL30",
"FS10",
"SNAP5",
"FIN"
],
"distance": 46.0,
"path": [
{
"d": 0,
"s": -1,
"x": 1,
"y": 1
},
{
"d": 2,
"s": -1,
"x": 5,
"y": 3
},
{
"d": 2,
"s": -1,
"x": 2,
"y": 3
},
{
"d": 0,
"s": 1,
"x": 4,
"y": 7
},
{
"d": 2,
"s": -1,
"x": 8,
"y": 9
},
{
"d": 2,
"s": -1,
"x": 6,
"y": 9
},
{
"d": 0,
"s": -1,
"x": 8,
"y": 13
},
{
"d": 0,
"s": 2,
"x": 8,
"y": 14
},
{
"d": 0,
"s": -1,
"x": 8,
"y": 9
},
{
"d": 2,
"s": -1,
"x": 12,
"y": 11
},
{
"d": 2,
"s": 4,
"x": 13,
"y": 11
},
{
"d": 4,
"s": -1,
"x": 9,
"y": 13
},
{
"d": 4,
"s": 3,
"x": 9,
"y": 10
},
{
"d": 4,
"s": -1,
"x": 9,
"y": 12
},
{
"d": 6,
"s": -1,
"x": 11,
"y": 16
},
{
"d": 6,
"s": -1,
"x": 12,
"y": 16
},
{
"d": 0,
"s": -1,
"x": 16,
"y": 14
},
{
"d": 0,
"s": 5,
"x": 16,
"y": 15
}
]
},
"error": null
}
The image is sent to the API as a file, thus no base64
encoding required.
Sample Request in Python
response = requests.post(url, files={"file": (filename, image_data)})
image_data
: abytes
object
The API will then perform three operations:
- Store the received file into the
/uploads
directory. - Use the model to identify the image.
- Return the result as a
json
response.
Sample json response
{
"image_id": "D",
"obstacle_id": 1
}
This will provide commands to the rpi for the obstacles to navigate around an obstacle. The command process will be up to rpi side
Sample Request in Python
{
"robot" : {"x" : 1, "y" : 1, "d" : 0},
"obstacle" : {"x" : 6, "y" : 6}
}
The API then return something like this:
{
"commands": [
"FW01",
"FW01",
"FW01",
"FR00",
"SNAPE",
"BL00",
"FW01",
"BL00",
"BW01",
"BR00",
"FW01",
"SNAPS",
"BW01",
"FL00",
"FW01",
"FR00",
"BW01",
"FR00",
"SNAPW",
"BL00",
"BW01",
"BL00",
"BW01",
"BW01",
"BW01",
"BW01",
"BW01",
"FL00",
"SNAPN",
"FIN"
],
"path": [
{
"d": 0,
"s": -1,
"x": 1,
"y": 1
},
{
"d": 0,
"s": -1,
"x": 1,
"y": 2
},
{
"d": 0,
"s": -1,
"x": 1,
"y": 3
},
{
"d": 0,
"s": -1,
"x": 1,
"y": 4
},
{
"d": 2,
"s": 1,
"x": 3,
"y": 6
},
{
"d": 4,
"s": -1,
"x": 1,
"y": 8
},
{
"d": 4,
"s": -1,
"x": 1,
"y": 7
},
{
"d": 6,
"s": -1,
"x": 3,
"y": 9
},
{
"d": 6,
"s": -1,
"x": 4,
"y": 9
},
{
"d": 4,
"s": -1,
"x": 6,
"y": 11
},
{
"d": 4,
"s": 1,
"x": 6,
"y": 10
},
{
"d": 4,
"s": -1,
"x": 6,
"y": 11
},
{
"d": 2,
"s": -1,
"x": 8,
"y": 9
},
{
"d": 2,
"s": -1,
"x": 9,
"y": 9
},
{
"d": 4,
"s": -1,
"x": 11,
"y": 7
},
{
"d": 4,
"s": -1,
"x": 11,
"y": 8
},
{
"d": 6,
"s": 1,
"x": 9,
"y": 6
},
{
"d": 0,
"s": -1,
"x": 11,
"y": 4
},
{
"d": 0,
"s": -1,
"x": 11,
"y": 3
},
{
"d": 2,
"s": -1,
"x": 9,
"y": 1
},
{
"d": 2,
"s": -1,
"x": 8,
"y": 1
},
{
"d": 2,
"s": -1,
"x": 7,
"y": 1
},
{
"d": 2,
"s": -1,
"x": 6,
"y": 1
},
{
"d": 2,
"s": -1,
"x": 5,
"y": 1
},
{
"d": 2,
"s": -1,
"x": 4,
"y": 1
},
{
"d": 0,
"s": 1,
"x": 6,
"y": 3
}
]
}
This will trigger the stitch_image()
function.
- all images found in the
run/
directory will be stitched together and saved atrun/stitched.jpg