Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

opencv - Flask app working on local server but not globally

These are my routes and some functions:

from flask import Flask, render_template, Response
import cv2
import time
from sys import stdout
from flask_socketio import SocketIO
import math
import numpy as np
import logging
import os
from camera import VideoCamera

app = Flask(__name__)
app.logger.addHandler(logging.StreamHandler(stdout))

app.config['SECRET_KEY'] = 'b13ce0c6768bb0b280bab13ceb13ce0cde280ba0c676dfde280ba245676dfde280ba0c676dfde280ba245'
app.config['DEBUG'] = True
socketio = SocketIO(app)

@socketio.on('connect', namespace='/test')
def test_connect():
    app.logger.info("client connected")


@app.route('/', methods = ['GET','POST'])
def index():
    """Video streaming home page."""
    return render_template('index.html')

def gen(camera):
    while True:
        data= camera.get_frame()

        frame=data[0]
        yield (b'--frame
'
               b'Content-Type: image/jpeg

' + frame + b'

')

@app.route('/video_feed')
def video_feed():
    return Response(gen(VideoCamera()), mimetype='multipart/x-mixed-replace; boundary=frame')

@app.route('/golden_ratio_calculating', methods = ['GET','POST'])
def calculate():
    ratio = main()
    return render_template('golden_calc_page.html' , ratio123 = ratio)


if __name__ == '__main__':
    port = int(os.environ.get('PORT', 5000))
    socketio.run(app, port = port)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have you had a look at the Heroku docs regarding camera interfaces? There is an add-on CameraTag

Heroku Cameratag

Also you might find self-hosting your flask app on an apache2 server a more successful solution. There are many tutorials and the process is not difficult.

Heroku is great, but with my experience with face_recognition specifically, if you don't pay for upgrades you will run into issues exceeding memory <550mb.

This link here is a great tutorial for self-hosting flask app.

Deploy Flask to Apache Server

Furthermore, it may be that Heroku cannot access the local camera peripheral or the device is no longer [0]

 # Using OpenCV to capture from device 0.
        

        self.stream = WebcamVideoStream(src = 0).start()

Have you tried modifying the src?

This may also be useful for your application.

Stream webcam to html OpenCV


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...