当前位置:网站首页>处理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)
边栏推荐
- Related programming problems of string
- 一片葉子兩三萬?植物消費爆火背後的“陽謀”
- Modify the system time of Px4 flight control
- Analyze "C language" [advanced] paid knowledge [II]
- New job insights ~ leave the old and welcome the new~
- Add PDF Title floating window
- Treadpoolconfig thread pool configuration in real projects
- Shell script quickly counts the number of lines of project code
- JS ES5也可以创建常量?
- 红外相机:巨哥红外MAG32产品介绍
猜你喜欢
2022/0524/bookstrap
Recognition of C language array
FLIR blackfly s industrial camera: configure multiple cameras for synchronous shooting
2022/0524/bookstrap
盒子拉伸拉扯(左右模式)
Introduction to microservice architecture
The cradle of eternity
张平安:加快云上数字创新,共建产业智慧生态
Reptile practice (VI): novel of climbing pen interesting Pavilion
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
随机推荐
猫猫回收站
Cisp-pte practice explanation (II)
IDEA常用的快捷键
Curl command
JS how to quickly create an array with length n
初识MySQL
新工作感悟~辞旧迎新~
[unique] what is the [chain storage structure]?
MySQL最基本的SELECT(查询)语句
JVM memory model
454 Baidu Mianjing 1
2022 system integration project management engineer examination knowledge point: Mobile Internet
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
Long press the button to execute the function
Can't you understand the code of linked list in C language? An article allows you to grasp the secondary pointer and deeply understand the various forms of parameter passing in the function parameter
JS Es5 can also create constants?
Mongodb checks whether the table is imported successfully
刨析《C语言》【进阶】付费知识【一】
Analyze "C language" [advanced] paid knowledge [End]
Ds-5/rvds4.0 variable initialization error