A really simple python flask server for Moon-Trek client. The purpose of this server is to act as a backup plan for image registration. So we can have all the registration algorithm available even if client-side registration failed. And this server also unlocked algorithms thats not available in WebAssembly (SURF).
Note: We shouldn't rely on this server, we should slowly get rid of it.
you need to create a config.py file to run to server.
Use ./config/config.py.template as your template, and fill-in the blank.
If you want to deploy this server via Docker, you should use ./config/config.py.docker instead.
Here is a template config.py file
CONFIG = {
"log_filepath": "/app/data/moon-trek-python-server.log",
"logging_level": "INFO",
"default_rate_limits": ["20 per day"]
}log_filepath: path to log filelogging_level: logging level. We use python logging library, check out this article for detaildefault_rate_limits: setup rate limiting, input a list of str describing rate limits. We use Flask-Limiter for a basic rate limiting, checkout this article for detail of this field.
To deploy this server with Docker:
- In directory
python-server, build docker image with:
docker build -t moontrek-python-server .You can enable/disable OpenCV non-free registration algorithm (SURF) by setting docker build flag:
--build-arg "MR_ENABLE_OPENCV_NONFREE"to"ON"or"OFF". Learn more about the flag in this doc
- Run docker container with:
docker run -d --name moontrek-python-server \
-p 5000:5000 \
-v "$(pwd)/config:/app/config" \
-v "$(pwd):/app/data" \
moontrek-python-serverNote:
- we use
-pparameter to specify the port we want to expose from container to host system. Expose container port 5000 to host system port 5000. By default, docker will launch this server on container port 5000.- we use
-vto mount a volume of config file into docker container. So the server can find itsconfig.pyfile.- we use the second
-vto mount current directory into docker container's/app/datafolder, so it can save its log file to current directory.
To deploy this server manually:
- Install MoonRegistration-python package in your python environment
- Be sure to install the requirements.txt for MoonRegistration-python first
- install other requirements, they are the requirements.txt in current directory.
pip install -r requirements.txt- Finally, you can run the server with gunicorn:
gunicorn --bind 0.0.0.0:5000 app:appModify argument
--bind 0.0.0.0:5000to set the host & port you want to deploy this app
All the endpoints in this server starts with /pyapi/registrar/
Run a specified registration algorithm with input images.
- Parameter:
<algorithm>: str path parameter, can be one of following:- SIFT
- ORB
- AKAZE
- BRISK
- SURF
user-file: form-data of user image filemodel-file: form-data of model image file
- Return
- Sample Success return json
{
"ok": true,
"payload": {
"homography_matrix": [
[1, 2, 3],
[1, 2, 3],
[1, 2, 3]
]
},
"status": 200
}-
- Sample Failure return json
{
"ok": false,
"status": 400,
"error": "No enough keypoints for finding homography matrix"
}