我正在尝试使用Heroku上托管的OpenCV,Flask,Face Recognition制作Web应用程序。在localhost上,一切都按预期运行,但是在Heroku上,我无法打开客户端摄像头。我知道我需要javascript或WebSocket来实现这一目标。我可以用javascript找到的所有内容是如何从浏览器上的相机中流式传输,这对我来说并不好,因为我需要打开OpenCV框架进行面部检测和识别。另外,我还在寻找WebSocket和flask-socket,但它们只发送消息,而不发送视频。
这是我的代码:app.py
'''Face Detection Login App '''
import random, string
import face_recognition
import cv2
import glob
from flask import Flask, render_template, redirect, url_for
app = Flask(__name__)
@app.route('/')
def index():
render_template('home.html')
@app.route('/article')
def article():
return render_template('article.html')
@app.route('/registered')
def registered():
return render_template('registered.html')
@app.route('/reject')
def reject():
return render_template('reject.html')
@app.route('/login', methods=["GET", "POST"])
def login():
page_name = 'reject'
video_capture = cv2.VideoCapture(0)
# Load faces
faces = 'faces/*.jpg*'
face = glob.glob(faces)
for fn in face:
try_image = face_recognition.load_image_file(f'{fn}')
print(f'{fn}')
try_face_encoding = face_recognition.face_encodings(try_image)
if not try_face_encoding: …Run Code Online (Sandbox Code Playgroud)