我已将图像的URL存储在MySQL数据库中,这些图像位于F驱动器中。我的烧瓶应用程序位于c驱动器中。读取图像时有什么区别吗?我需要将文件夹与flask放在相同的工作目录中吗?另外,我试图通过part_no登录时将图像显示在浏览器上。 (通过执行添加加权方法,我的网络摄像头摘要和图像显示在同一窗口中)如何完成相同的操作。如果必须通过给出其路径一次按单个图像选择它,则可以执行此操作。我还需要修改代码,以使浏览器在输入特定的部件ID时显示相应的图像。有人可以指导我如何去做吗?
camera-opencv.py
@staticmethod
def frames():
camera = cv2.VideoCapture(Camera.video_source)
if not camera.isOpened():
raise RuntimeError('Could not start camera.')
while True:
# read current frame
_, img = camera.read()
new_img = [cv2.imread(file) for file in
glob.glob('F:/Parts/*.jpg')]]
img = cv2.resize(img, (640, 480))
dst = cv2.addWeighted(img,0.8,new_img,0.3,0)
# encode as a jpeg image and return it
yield cv2.imencode('.jpg', dst)[1].tobytes()
app.py
from flask_mysqldb import MySQL
from flask import Flask, flash, redirect, render_template, request,
session, abort, Response
from importlib import import_module
import os
from flask import Flask, render_template, Response
# import camera driver
if os.environ.get('CAMERA'):
Camera = import_module('camera_' + os.environ['CAMERA']).Camera
else:
from camera import Camera
mysql=MySQL()
app= Flask(__name__)
app.config['MYSQL_HOST']= '127.0.0.1'
app.config['MYSQL_USER']= 'root'
app.config['MYSQL_PASSWORD']= 'Divya@123'
app.config['MYSQL_DB']= 'TVSDB'
mysql.init_app(app)
@app.route('/')
def home():
if not session.get('logged_in'):
return render_template('login.html')
else:
return "Hello Boss! <a href=>"+ logout+ "Logout</a> "
@app.route('/login',methods=['GET','POST'] )
def Authenticate():
Part_No = request.form['Part_No']
cursor = mysql.connection.cursor()
cursor.execute("SELECT * FROM Pro1 WHERE Part_No=%s",[Part_No])
data = cursor.fetchone()
if data is None:
return render_template('login.html')
print("Incorrect Part_No")
else:
return render_template('index.html')
print("You are signed in")
def gen(camera):
"""Video streaming generator function."""
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
@app.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
return Response(gen(Camera()),mimetype='multipart/x-mixed-replace;
boundary=frame')
@app.route('/img/<int:img_id>')
def serve_img(img_id):
cursor = mysql.connection.cursor()
cursor.execute("SELECT File_Path FROM Pro1 WHERE Part_No=%s",[Part_No])
data = cursor.fetchone()
cursor.close()
return render_template('index.html')
@app.route("/logout")
def logout():
session['logged_in'] = False
return home()
if __name__ == '__main__':
app.run(debug= True, threaded=True)
我正在寻找的预期结果是显示摄像头+特定part_id的图像并执行添加加权方法。