Перенаправление URL при потоковой передаче видео с использованием Javascript и Flask - PullRequest
0 голосов
/ 23 января 2020

Я создал файл распознавания объектов, который успешно распознает такие объекты, как Apple и Man go. Я реализовал потоковое видео в реальном времени на Flask, следуя инструкции из Блог о потоковом видео

Вот мой Flask Файл.

from flask import Flask, render_template, Response, redirect, url_for
from camera import VideoCamera
app = Flask(__name__)
@app.route('/')
def index():
    return render_template('index.html')
def gen(camera1):
    while True:
        label, frame = camera1.get_frame()
        yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n'
        yield frame
        yield b'\r\n\r\n'
def genlabel(camera1):
    while True:
        label, frame = camera1.get_frame()
        return label
@app.route('/form')
def form():
    return Response(genlabel(VideoCamera()),
                    mimetype='text')
@app.route('/video_feed')
def video_feed():
    label = gen(VideoCamera())
    return Response((label),
                    mimetype='multipar/x-mixed-replace; boundary=frame')
@app.route('/apple')
def add():
    return render_template('apple.html')

И вот мой обработанный индекс. html file.

<html>
  <head>
    <title>Video Streaming Demonstration</title>
  </head>
  <body>
      <p id="label">Here will be date|time</p>
<script>
    var label = document.getElementById("label");
    if (label == "apple"){
        label.addEventListener('change', doThing);
    }

    setInterval(() => {
        fetch("{{ url_for('form') }}")
        .then(response => {
                response.text().then(t => {label.innerHTML = t})
            });
        }, 100);  
    /* function */
    function doThing(){
        location.href = "{{ url_for('apple') }}";
    }
</script>
  </body>
</html>

Он не перенаправляется даже при обнаружении яблока в видеопотоке. Почему?

...