python与html结合显示本地图片_显示图像通过flask / python从HTML连接到HTML

I'm tying to get an image attachment from couchdb using flask & python then pass the image to imgurl.html to be displayed.

The problem is that I'm only get this:

couchdb.http.ResponseBody object at 0x103b9c0b8> returned.

app.py

from flask import Flask, request, render_template, flash, request, url_for, redirect

import couchdb

import requests

app = Flask(__name__)

couch = couchdb.Server('http://127.0.0.1:5984/')

db = couch['test2']

doc = db.get_attachment('2', 'aboutme.jpg', default=None)

print("doc: ", doc)

@app.route('/')

def index():

return render_template('index.html')

@app.route('/imgurl/')

def imgurl():

return render_template('imgurl.html'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Python中实时写入图像并在HTML上实时显示,可以使用OpenCV和Flask。下面是一个简单的示例代码: ```python import cv2 from flask import Flask, render_template, Response app = Flask(__name__) camera = cv2.VideoCapture(0) # 打开摄像头 @app.route('/') def index(): return render_template('index.html') # 返回HTML模板 def gen(): while True: success, frame = camera.read() # 读取摄像头帧 if not success: break ret, buffer = cv2.imencode('.jpg', frame) # 将帧编码为JPEG格式 frame = buffer.tobytes() # 转换为字节串 yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # 返回MJPEG流 @app.route('/video_feed') def video_feed(): return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame') # 返回MJPEG流的响应 if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=True) # 运行Flask应用程序 ``` 在此示例中,我们使用Flask创建一个Web应用程序,并使用OpenCV从摄像头读取帧。然后,我们将每个帧编码为JPEG格式,并将其作为MJPEG流发送到HTML模板中的img标签。最后,我们使用Flask的Response对象将MJPEG流作为响应发送回客户端。 在HTML模板中,我们可以使用以下代码来显示视频流: ```html <!DOCTYPE html> <html> <head> <title>Video Streaming with Flask</title> </head> <body> <h1>Video Streaming with Flask</h1> <img src="{{ url_for('video_feed') }}" /> </body> </html> ``` 这将从Flask应用程序的/video_feed路由中获取MJPEG流,并将其作为img标签的src属性。当我们运行Python脚本并访问http://localhost:5000时,我们应该能够在HTML页面上实时看到摄像头的视频流。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值