[英]How do I display a newly saved image using opencv from Flask in the static folder?
我正在嘗試在網頁上顯示輸出之前對圖像輸入進行處理並對其進行處理。 但是,當我嘗試不同的圖像時,會顯示較舊的圖像而不是新的圖像。
以下是代碼段:
from flask import Flask, render_template, request
import pro
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html")
@app.route('/process', methods=['GET', 'POST'])
def process():
n = '/home/vivek/Desktop/CL3/d/booth/trial/uploads/up.jpg'
a = pro.pro(n)
return render_template("out.html")
if __name__ == '__main__':
app.run(debug=True)
流程代碼:
import cv2
def pro(p):
img = cv2.imread(p, 1)
# some process here
path = '/home/vivek/Desktop/CL3/d/booth/trial/static/'
cv2.imwrite(str(path) + 'out.jpg',img)
cv2.waitKey(0)
np = '/home/vivek/Desktop/CL3/d/booth/trial/static/out.jpg'
return np
最后是HTML文件:
<!DOCTYPE html>
<html>
<body>
<h2>OUTPUT</h2>
<img src="{{url_for('static', filename='out.jpg')}}" alt="OUTPUT" style="width:128px;height:128px;">
</body>
</html>
您需要禁用緩存
def process():
....
resp = make_response(render_template('out.html'))
resp.cache_control.no_cache = True
return resp
更新
class MyFlask(Flask):
def get_send_file_max_age(self, name):
if name == 'out.jpg':
return 0
return Flask.get_send_file_max_age(self, name)
app = MyFlask(__name__)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.