当前位置:网站首页>处理streamlit库上传的图片文件
处理streamlit库上传的图片文件
2022-07-06 18:28:00 【huijigo】
steamlit是一个可以快速建立网站的界面。在学校安排的实训项目中,我们要实现基于内容的图像检索系统设计和实现。其中的分支任务就是检索上传的图像。
我们使用了steamlit的uploadfile组件,该组件能将我们需要的图片以字节的方式上传到后端程序中。现在面临的问题就是如何解析这个16进制文件。
解决方案是PIL库的Image.open();他不仅可以直接读取文件路径下的文件,还可以通过字节流读取文件。
from io import BytesIO
import numpy as np
from PIL import Image
import streamlit as st
import cv2
#创建file_uploader组件
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# To read file as bytes:
bytes_data = uploaded_file.getvalue()
#将字节数据转化成字节流
bytes_data = BytesIO(bytes_data)
#Image.open()可以读字节流
capture_img = Image.open(bytes_data)
capture_img = cv2.cvtColor(np.asarray(capture_img), cv2.COLOR_RGB2BGR)
边栏推荐
- BigDecimal 的正确使用方式
- MySQL execution process and sequence
- Errors made in the development of merging the quantity of data in the set according to attributes
- ROS学习(十九)机器人SLAM功能包——cartographer
- HDU 4661 message passing (wood DP & amp; Combinatorics)
- Golang foundation - data type
- 微服务架构介绍
- ROS学习(24)plugin插件
- JS ES5也可以创建常量?
- LeetCode. Sword finger offer 62 The last remaining number in the circle
猜你喜欢
随机推荐
初识MySQL
3D激光SLAM:Livox激光雷达硬件时间同步
C语言【23道】经典面试题【下】
ROS学习(24)plugin插件
刨析《C语言》【进阶】付费知识【一】
Centros 8 installation MySQL Error: The gpg Keys listed for the "MySQL 8.0 Community Server" repository are already ins
HDU 4661 message passing (wood DP & amp; Combinatorics)
Yiwen takes you into [memory leak]
AcWing 345. Cattle station solution (nature and multiplication of Floyd)
Shortcut keys commonly used in idea
ROS learning (23) action communication mechanism
最近小程序开发记录
Vingt - trois mille feuilles? "Yang mou" derrière l'explosion de la consommation végétale
使用nodejs完成判断哪些项目打包+发版
Correct use of BigDecimal
JS es5 peut également créer des constantes?
AcWing 1141. LAN problem solving (kruskalkruskal finding the minimum spanning tree)
New job insights ~ leave the old and welcome the new~
js如何快速创建一个长度为 n 的数组
Mongodb checks whether the table is imported successfully







