python - 来自 request.get(url) 的 Python 树莓派 Image.open 图像
问题描述
我正在尝试从 URL 打开图像然后处理图像。
我正在获取的图像来自通过此端点的一个覆盆子凸轮
@app.route('/image')
def getImage():
frame = video_camera.get_frame()
return Response((b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n'),
mimetype='multipart/x-mixed-replace; boundary=frame')
然后在另一个覆盆子上,我试图以这种方式获取图像:
r = requests.get('http://'+ip+'/image')
curr_img = Image.open(BytesIO(r.content))
如果我在浏览器中打开链接,我可以看到图像,所以那部分似乎没问题。但是在使用 Image.open 时仍然出现此错误:
OSError: cannot identify image file <_io.BytesIO object at 0xffff8836dba0>
任何想法?
解决方案
就我而言,我需要改变我的
@app.route('/image')
def getImage():
frame = video_camera.get_frame()
return Response((b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n'),
mimetype='multipart/x-mixed-replace; boundary=frame')
至
@app.route('/image')
def getImage():
frame = video_camera.get_frame()
return frame
我的 video_camera.get_frame() 已经给了我图像的字节,所以我不需要添加任何内容。
推荐阅读
- html - 为网页添加动画
- python-multiprocessing - 如何获取python的多处理数组'指针并将其传递给Cpp程序?
- java - 由于 web.xml 或 servlet.java,本地主机上的服务器 Tomcat v8.5 服务器无法启动 Eclipse
- java - 用于文本分析的 Elasticsearch 分析器
- sql-server - 来自同一个表的多个插入,但第二个插入需要来自第一个插入的标识
- javascript - 从 Nodejs express 应用程序发布到 MySQL 数据库返回 404
- laravel - 在 Dusk 测试中,日期字段始终采用美国格式
- c++ - 什么时候可以在 C++ 中意外更改变量的值?
- reactjs - 与 Gatsby 和 Bulma 反应 - 列不水平
- xamarin.forms - 将 TextField 绑定到 Xamarin.Forms 中的 Int 属性