我的 Flask 应用程序中有此代码,它在网页中实时显示来自相机源的图像(图像不断变化)
<img src="{{ url_for('video_feed') }}">
video_feed 是一个 API,它读取相机输入并将其转换为 jpg 以便它可以在网络浏览器中显示
@app.route("/video_feed")
def video_feed():
# return the response generated along with the specific media
# type (mime type)
return Response(generate(),
mimetype = "multipart/x-mixed-replace; boundary=frame")
def generate():
# grab global references
global outputFrame
# loop over frames from the output stream
while True:
# check if the output frame is available, otherwise skip
# the iteration of the loop
if outputFrame is None:
continue
# encode the frame in JPEG format
(flag, encodedImage) = cv2.imencode(".jpg", outputFrame)
# ensure the frame was successfully encoded
if not flag:
continue
# yield the output frame in the byte format
yield(b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' +
bytearray(encodedImage) + b'\r\n')
我正在将我的前端移至 Vue,我希望在我的应用程序中显示此实时图像源,但 vue 无法识别 {{ url_for('video_feed') }}。这样做的最佳方法是什么?