Commit 973ccf67 authored by Joel Collins's avatar Joel Collins
Browse files

Created API V1

parent d04943c9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
from . import utilities
+9 −0
Original line number Diff line number Diff line
<html>
  <head>
    <title>Video Streaming Demonstration</title>
  </head>
  <body>
    <h1>Video Streaming Demonstration</h1>
    <img src="{{ url_for('stream') }}">
  </body>
</html>
+15 −0
Original line number Diff line number Diff line
def parse_payload(request):
    """Convert request to JSON. Will eventually handle error-checking."""
    # TODO: Handle invalid JSON payloads
    state = request.get_json()
    return state


def gen(camera):
    """Video streaming generator function."""
    while True:
        # the obtained frame is a jpeg
        frame = camera.get_frame()

        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
+2 −17
Original line number Diff line number Diff line
@@ -11,34 +11,19 @@ from flask import (

import numpy as np

from openflexure_microscope.api.utilities import parse_payload, gen
from openflexure_microscope.camera.pi import StreamingCamera

app = Flask(__name__)
cam = StreamingCamera()


def parse_payload(request):
    """Convert request to JSON. Will eventually handle error-checking."""
    # TODO: Handle invalid JSON payloads
    state = request.get_json()
    return state


def gen(camera):
    """Video streaming generator function."""
    while True:
        # the obtained frame is a jpeg
        frame = camera.get_frame()

        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')


@app.route('/')
def index():
    """Video streaming home page."""
    cam.start_worker()  # Start the stream
    return render_template('index.html')
    return render_template('index_v0.html')


@app.route('/stream')
Loading