<filename>cpp/api.py
import os
import flask
from flask import Flask, send_file, send_from_directory
from flask_jwt_extended import (
    JWTManager, jwt_required, create_access_token,
    get_jwt_claims
)
import time  # sleep
import requests

app = flask.Flask(__name__)
app.config["DEBUG"] = True
jwt = JWTManager(app)

DOWNLOAD_DIRECTORY = "./"
@app.route('/get-files/<path:path>',methods = ['GET','POST'])
def get_files(path):
    # Download algorithm result
    # This should be called with input path="output.xml"
    try:
        return send_from_directory(DOWNLOAD_DIRECTORY, path, as_attachment=True)
    except FileNotFoundError:
        abort(404)


@app.route('/', methods=['GET'])
def run_alg():
    # Generate a new .conf file - path, start/end time
    # Use api data (video name)
    
    # Execute algorithm
    os.system("./a.out ./demo/video_example.conf")
    # Wait for algorithm to finish
    time.sleep(40)
    # read result from file
    cv_file = cv2.FileStorage("output.xml", cv2.FILE_STORAGE_WRITE)
    result = cv_file.getNode("FinalDisp").mat()
    cv_file.release()
    return(result)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port = 8000, threaded = True, debug = True)

<filename>cpp/api.py
import os
import flask
from flask import Flask, send_file, send_from_directory
from flask_jwt_extended import (
    JWTManager, jwt_required, create_access_token,
    get_jwt_claims
)
import time  # sleep
import requests

app = flask.Flask(__name__)
app.config["DEBUG"] = True
jwt = JWTManager(app)

DOWNLOAD_DIRECTORY = "./"
@app.route('/get-files/<path:path>',methods = ['GET','POST'])
def get_files(path):
    # Download algorithm result
    # This should be called with input path="output.xml"
    try:
        return send_from_directory(DOWNLOAD_DIRECTORY, path, as_attachment=True)
    except FileNotFoundError:
        abort(404)


@app.route('/', methods=['GET'])
def run_alg():
    # Generate a new .conf file - path, start/end time
    # Use api data (video name)
    
    # Execute algorithm
    os.system("./a.out ./demo/video_example.conf")
    # Wait for algorithm to finish
    time.sleep(40)
    # read result from file
    cv_file = cv2.FileStorage("output.xml", cv2.FILE_STORAGE_WRITE)
    result = cv_file.getNode("FinalDisp").mat()
    cv_file.release()
    return(result)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port = 8000, threaded = True, debug = True)

# sleep # Download algorithm result # This should be called with input path="output.xml" # Generate a new .conf file - path, start/end time # Use api data (video name) # Execute algorithm # Wait for algorithm to finish # read result from file